Showing posts with label Selenium IDE. Show all posts
Showing posts with label Selenium IDE. Show all posts

Tuesday, 4 September 2012

Compare a variable with blank value in selenium



To compare variable with blank value, you can try solution like suggested      below - 
Here 'test' and 'j' are two variable. j having blank value.
It will compare 'test' and 'j' variable and accordingly it will display message  whether test variable is blank or not.


storeValue  |  element  |  test
store          |           |  j  (blank value)
gotoIf        |  storedVars['test']==storedVars['j']  |  true
getEval      |  alert("test Variable Value is not blank")
gotolabel   |  finish
label         |  true
getEval      |  alert("test Variable Value is blank")
label         |  finish


Xpath to determine checkbox “checked” attribute

If there is multiple check-boxes with same ids and you have to select the next check-box which is not selected/checked. 
For such scenario you can refer below script - 




Here 'stnewrecord' is class of check-box. Script will store number of check-box, and according to that loop will follow. It will check whether check-box is checked or not if not it will check else move to next step.
xpath=(//input[@class='stnewrecord'])[${i}]  
This is xpath of check-box. 'i' is position, it will increase on each iteration.

Thursday, 3 May 2012

CKeditor with Selenium IDE


There are two ways to deal with Ckeditor

1)
focus  |  class=cke_show_borders
typeKeys |  class=cke_show_borders  | testing content

'cke_show_borders' is a class of body area

2)

runScript | CKEDITOR.instances["editor1"].setData('
testContent
');

'editor1' is instance of Ckeditor






































With help of these option you can able to tackle with CKeditor.

Friday, 30 March 2012

Selenium IDE and CAPTCHA


Selenium can only be used to test a web app protected by CAPTCHA if a human involved for the test. So, if you are automating registration form of any site that includes a CAPTCHA, you will require human interaction during the specific section that requires a CAPTCHA response.

There are two ways in which you can automate CAPCHA
1.By break command
2.By input-box

Suppose after command 3, there is CAPTCHA

1.By break command

Command 1
Command 2
Command 3
4th command will be
Break
Enter CAPTCHA manually and resume execution of test
continue with your next commands

2.By input-box
Command 1
Command 2
Command 3
4th command will be
storeEval | prompt(“Enter value for captcha”); |variable
type | locator of CAPTCHA field | ${variable}
continue with your next commands



Saturday, 3 March 2012

Debugging Tests in Selenium IDE


Below are the methods or ways of Debugging your selenium IDE scripts..

Selenium IDE reports failures in the log console, and failed test cases within the suite are shown in red.
The failing test cases and commands are highlighted in red, so it’s easy to see what failed, but quite often it can be difficult to understand why it failed. This information is all in the log, but if you’ve run more than just a couple of tests then it will be difficult to match up the failing commands to the errors in the log.

There are a few ways to debug these failures and work out if your application under test has bugs, or perhaps your tests require some changes

Execute Individual Command:


When you double-click a command in Selenium IDE it will be executed – this is very handy when first writing your tests. You could use this to step through each command in each test case until you find a failure, and investigate from there.

Custom Log Messages:

There’s a command in Selenium IDE named echo and this will basically repeat whatever you type into the log when the test is executed. You could use this to output a message associated with an expected failure, and then find this in the log. You do still have to scroll through the log to look for your messages though.

Slow Down:
You can use the speed slider to slow down how fast your test commands are executed. This can be helpful as you can watch the application under test while your tests are running and see any obvious issues that your tests are failing on. You can also use this in combination with executing commands manually by pausing your tests.

Pause, Break and Step:

You can pause your test at any time, either by clicking the Pause icon in the toolbar or by setting breakpoints. Set a breakpoint by right-clicking on a command you want Selenium IDE to pause before executing, and selecting ‘Toggle Breakpoint’ from the context-menu. You will see a small pause icon appear to the left of your command.
When Selenium IDE is paused, the Step icon becomes available. You can use this to execute one command at a time, which can be very useful when approaching a failure or working through a number of verification failures. If you have set multiple breakpoints then you can click the Resume icon to continue executing your tests and stop at the next breakpoint.

Set Start Point:

If you have a really long test and it’s failing towards the end, then you can set a custom start point so that you don’t have to run the entire test when you’re investigating the failure. For example, your test might register a new user, log in, and then fail on the welcome page. You could simply navigate to the welcome page yourself and set your test to start from there. To set a start point simply right click on the first command you want Selenium IDE to execute and click ‘Set / Clear Start Point’. You will see a small play icon appear to the left of your command.

There are many ways that Selenium IDE can assist you in investigating failures and debugging your tests.

Selenium IDE -Get Current Time, Date, Month and Year


Current Time - javascript{(new Date().getHours()+" : " + new Date().getMinutes() + " : " + new Date().getSeconds())}

Current year - javascript{(new Date()).getFullYear()}

Current Month - javascript{(new Date().getMonth()) + 1}

Current date - javascript{(new Date().getDate().toString())}

Selenium IDE - Locating Elements in Page.

For most of the Selenium commands target is required. This target identifies an element in the content of the web application. The various locator types are:
1. Identifying elements by ID
2. Identifying elements by Name
3. Identifying elements by Link
4. Identifying elements by XPath
5. Identifying elements by CSS
6. Identifying elements by DOM

For identifying elements, we need some applications.

FireBug: Firebug integrates with Firefox to put a wealth of web development tools at your fingertips while you browse. You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page.

We can download this from this website: http://getfirebug.com/.
Just Drag and Drop firebug.xpi to Firefox it will install.

With the help of FireBug you can
1. Identifying elements by ID
2. Identifying elements by Name



Identifying elements by DOM


Few examples for DOM
getElementById()
getElementsByName()
getElementsByTagName()
getElementsByClassName()



identifier=id
Select the element with the specified @id attribute. If no match is found, select the first element whose @name attribute is id.
(This is normally the default; see below.)
id=id
Select the element with the specified @id attribute.
name=name
Select the first element with the specified @name attribute.
  • username
  • name=username

The name may optionally be followed by one or more element-filters, separated from the name by whitespace. If the filterType is not specified, value is assumed.
  • name=flavour value=chocolate


dom=javascriptExpression


Find an element using Javascript traversal of the HTML Document Object
Model. DOM locators must begin with "document.".
  • dom=document.forms['myForm'].myDropdown
  • dom=document.images[56]


xpath=xpathExpression
Locate an element using an XPath expression.
  • xpath=//img[@alt='The image alt text']
  • xpath=//table[@id='table1']//tr[4]/td[2]


link=textPattern
Select the link (anchor) element which contains text matching the
specified pattern.
  • link=The link text


css=cssSelectorSyntax
Select the element using css selectors. Please refer to CSS2 selectors, CSS3 selectors
for more information. You can also check the TestCssLocators test in
the selenium test suite for an example of usage, which is included in
the downloaded selenium core package.
  • css=a[href="#id3"]
  • css=span#firstChild + span

Selenium IDE - Add two number stored in variable



store          | 10 |  a
store          | 5   |  b
storeEval   | ${a}+${b} | total
echo         |${total}

Friday, 17 February 2012

Selenium IDE split text - Get require string from sentence

Split text from sentence

Suppose you have sentence as 'my name is : radical' and you want only radical text from whole sentence, use below code

store   | my name is : radical | string
  store | 1 | delimiter
  store | javascript{storedVars['string'].split('is :')[storedVars['delimiter']]} | name
 echo  | ${name}

Selenium IDE: Random Number Generator Using Selenium IDE

Generate random number in selenium IDE

type  |  field  | javascript{Math.floor(Math.random()*11)}  

You can increase number of 1 to increase number of digits

similarly you can use for email 

type | field | javascript{"joe+" + Math.floor(Math.random()*11111) + "@gmail.com";}


Saturday, 11 February 2012

Get XPATH in IE

Here is a way to find the XPATH on IE...


STEPS TO INSTAL BOOKMARKLETS
1)Open IE
2)Type 
about:blank in the address bar and hit enter
3)From Favorites main menu select--->Add favorites
4) In the Add a favorite popup window enter name 
GetXPATH1.
5)Click add button in the add a favorite popup window.
6)Open the Favorites menu and right click the newly added favorite and select properties option.
7)GetXPATH1 Properties will open up. Select the web Document Tab.
8)Enter the following in the URL field.
javascript:function getNode(node){var nodeExpr=node.tagName;if(!nodeExpr)return null;if(node.id!=''){nodeExpr+="[@id='"+node.id+"']";return "/"+nodeExpr;}var rank=1;var ps=node.previousSibling;while(ps){if(ps.tagName==node.tagName){rank++;}ps=ps.previousSibling;}if(rank>1){nodeExpr+='['+rank+']';}else{var ns=node.nextSibling;while(ns){if(ns.tagName==node.tagName){nodeExpr+='[1]';break;}ns=ns.nextSibling;}}return nodeExpr;}

9)Click Ok. Click YES on the popup alert.
10)Add another favorite by following steps 3 to 5, Name this favorite GetXPATH2 (step4)
11)Repeat steps 6 and 7 for GetXPATH2 that you just created.
12)Enter the following in the URL field for GetXPATH2

javascript:function o__o(){var currentNode=document.selection.createRange().parentElement();var path=[];while(currentNode){var pe=getNode(currentNode);if(pe){path.push(pe);if(pe.indexOf('@id')!=-1)break;}currentNode=currentNode.parentNode;}var xpath="/"+path.reverse().join('/');clipboardData.setData("Text", xpath);}o__o();

13)Repeat Step 9.

You are all done!!

Now to get the XPATH of elements just select the element with your mouse.Select the element(link, button, image, checkbox, text etc) then select the favorite GetXPATH1 from the favorites menu and then select the second favorite GetXPATH2. At his point if you get any confirmation, hit allow access button. Now open up a notepad file, right click and select paste option. This will give you the XPATH of the element you seek.


Friday, 10 February 2012

Selenium IDE - parameterization

For parameterization you need to create js file
For eg. Js file contains
  var username=new Array("parameterization1@mailinator.com","parameterization2@mailinator.com");
  var password=new Array("parameterization1","parameterization2");

Sample script for parameterization



Selenium IDE Flow Control - Goto and While Loop


For looping statement you need to add selenium extension goto_sel_ide.js. You can get this from here .

Upload that file to selenium IDE

Options > options > selenium core extension




Below is sample script for  Flow Control


 

 

Send email functionality using Gmail




open               | http://www.gmail.com
type                | id=Email                     |tester
type                | id=Passwd                  | tester@123
clickAndWait    | id=signIn
clickAt             | //div[@id=':oy']/div/div
type               | name=to                      |  testing@gmail.com
 type              | name=subject              | testSubject
type               | css=body[class='editable  LW-avf'] | testing
keyPress         | //div/b[text()='Send']    | 13