Archive

Archive for the ‘Selenium’ Category

Get current page URL webdriver 2.0

Get the URL of the current page

@driver.current_url

Categories: Selenium Tags: , ,

Elements Locators in Selenium Ruby webdriver

September 24, 2012 2 comments
        :class             => ‘class name’,
        :class_name        => ‘class name’,
        :css               => ‘css selector’,
        :id                => ‘id’,
        :link              => ‘link text’,
        :link_text         => ‘link text’,
        :name              => ‘name’,
        :partial_link_text => ‘partial link text’,
        :tag_name          => ‘tag name’,
        :xpath             => ‘xpath’
Categories: Selenium Tags: , ,

get number of links in a page using Selenium IDE

get number of links in a page using Selenium IDE
<tr>
<td>open</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>window.document.getElementsByTagName(&quot;a&quot;).length</td>
<td>totallinks</td>
</tr>
<tr>
<td>echo</td>
<td>${totallinks}</td>
<td></td>
</tr>
Categories: Selenium Tags:

round off the decimal value to decimal places using Selenium IDE

round off the decimal value to decimal places using Selenium IDE

Input:-

<tr>
<td>roundUp</td>
<td>23.33345555,4</td>
<td>aa</td>
</tr>
script:-
Selenium.prototype.doRoundUp = function(elementOne, elementTwo)
{
 var val = elementOne.split(‘,’);
 var value = val[0];
 var digits = val[1];
 var numberRounded = (Math.round((value*Math.pow(10,digits)).toFixed(digits-1))/Math.pow(10,digits)).toFixed(digits);
 storedVars[ elementTwo ] = numberRounded;
};
Output:-
23.3335

 

Categories: Selenium Tags: ,

Generate random email id in Ruby

Guys,

We can return random email using following method

def email
      emailid = (0..8).map{(‘a’..’z’).to_a[rand(26)]}.join+”@yopmail.com”
      return emailid
end
while need random email id, just call the method “email()”.
Categories: Selenium Tags:

get tomorrow’s Date using javascript for selenium IDE

Selenium.prototype.doGenerateTomorrowDate = function( varName1, varName2 ) 
{
    var currentDate = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
    var day = currentDate.getDate()
    var month = currentDate.getMonth() + 1
    var year = currentDate.getFullYear()
    var monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
    var month = monthNames[month];
    storedVars[ varName1 ] =  day;
    storedVars[ varName2 ] =  month;
};

<tr>
    <td>generateTomorrowDate</td>
    <td>x</td>
    <td>y</td>
</tr>
<tr>
    <td>echo</td>
    <td>${x}</td>
    <td></td>
</tr>
<tr>
    <td>echo</td>
    <td>${y}</td>
    <td></td>
</tr>
Categories: Selenium Tags: ,

if statement in Selenium IDE

open  | URL of site
storeTextPresent  | any unique text of page a  | title
gotoIf  | storedVars.title  | true
getEval | alert(“page B”);
gotolabel | finish
label  | true
getEval | alert(“Page A”);
label | finish

This will check whether title is present or not, and if present control will redirect to label true, else will execute next statement after gotoif.

Categories: Selenium Tags: ,

Get id of div from its class name using JavaScript for Selenium IDE

Get id of div from its class name using JavaScript for Selenium IDE
<tr>
<td>storeEval</td>
<td>window.document.getElementsByClassName(‘classname’)[0].id</td>
<td>idname</td>
</tr>
<tr>
<td>echo</td>
<td>${idname}</td>
<td></td>
</tr>
Categories: Selenium Tags:

How to solve the link has target ‘_blank’, which is not supported in Selenium

For the example,

<a target=”_blank” id=”verify_email” href=”https://thiyagarajan.wordpress.com/users/verify/1341484215″>Verify your email</a>

So We can use following,

<tr>
<td>storeAttribute</td>
<td>//a[@id=’verify_email’]/@href</td>
<td>href</td>
</tr>
<tr>
<td>echo</td> ‘ this is only optional to see the link
<td>${href}</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>${href}</td>
<td></td>
</tr>

 

Categories: Selenium Tags: ,

Generates a random word using JavaScript in Selenium IDE

Selenium.prototype.doRandomWord = function( length, varName ) {
    var consonants = ‘bcdfghjklmnpqrstvwxyz’,
        vowels = ‘aeiou’,
        rand = function(limit) {
            return Math.floor(Math.random()*limit);
        },
        i, word=”, length = parseInt(length,10),
        consonants = consonants.split(”),
        vowels = vowels.split(”);
    for (i=0;i<length/2;i++) {
        var randConsonant = consonants[rand(consonants.length)],
            randVowel = vowels[rand(vowels.length)];
        word += (i===0) ? randConsonant.toUpperCase() : randConsonant;
        word += i*2<length-1 ? randVowel : ”;
    }
storedVars[ varName ] =  word;
};
Categories: Selenium Tags: ,

Generates a random alphanumeric string using JavaScript Selenium IDE

Selenium.prototype.doRandomAlphaNumeric = function( length, varName ) {
var valida = “abcdefghijklmnopqrstuvwxyz”;
var validn = “0123456789”;
var npwd = “”;
var pick = 0;
for ( var i = 0 ; i < length ; i++)
{
/* this is to pick alpha or number 0=a 1=n*/
if(Math.floor(2*Math.random()))
{
/* this is to pick a random character */
pick = Math.floor(26*Math.random());
if(Math.floor(2*Math.random()))
npwd = npwd + valida.substring(pick,pick+1).toUpperCase();
else
npwd = npwd + valida.substring(pick,pick+1);
}
else
{
/* this is to pick a random number */
pick = Math.floor(10*Math.random());
npwd = npwd + validn.substring(pick,pick+1);
}
}
storedVars[ varName ] =  npwd;
};
Categories: Selenium

Locating Elements in Selenium IDE

Locating by Id

Locating by Name

Locating by XPath

Locating Hyperlinks by Link Text

Locating by DOM

Locating by CSS

Categories: Selenium Tags:

write the selenium IDE test case for CAPTCHA images

Try prompt a text box for user to key in the captcha, and store in variable

example:

storeEval | prompt(“Enter Captcha:”) | varName

Then type the varName text in to your captcha text box example

type | id=CaptchaText | ${varName}

Categories: Selenium Tags: ,

Object Identification In Selenium

The following Identifiers used for object identification,

  1. id
  2. name
  3. dom
  4. xpath
  5. link
  6. css

Run phpUnit + selenium RC remote test cases to local browser

We can run the test cases from remote server and case will get execute into local machine. We have to follow the below steps,

  1. Install phpunit and necessary packages in server
  2. edit the test case and change host as local ip address ( use static ip address )
  3. run the selenium RC in local server
  4. run the test case in server

Test case will get execute into local machine.

Categories: Selenium

handle autocomplete in selenium IDE

The type command may not be enough to trigger the autocomplete.  My only addition would be that you might need the typeKeys command, which causes slightly different JavaScript events to be fired, which may be more likely to trigger the autocomplete widget.

So we can use the following steps to handle the situation,

  • typeKeys
  • waitForTextPresent
  • mouseOver
  • clickAt
Categories: Selenium Tags: , ,

Selenium Features

1 Multi Platform support
– Windows,Linux,Mac
2 Multi browser support
– Chrome, IE, Firefox, Safari, Netscape
3 Multiple programming Language support
– C#, Java, Ruby, PHP, Perl, Python
4 Xpath, Htmlid, DOM, Css selector
5 Support Ajax
6 ProxyInjection Mode
7 Experimental Browsers provided to test secured sites
8 Easy to use, small learning curve
9 Free-Open source
10 Matured Community

Categories: Selenium