Monday, 31 December 2012
Wednesday, 3 October 2012
Error Handling In Selenium RC
With help of error handling you can able to get details of failure.
public void test() throws Exception {
try {
selenium.open("http://seleniumhq.org/");
selenium.click("xpath=(//button[text()='Login'])[2]");
}catch (SeleniumException e){ //If any error occurs
try{
//Code to write error in file
FileWriter fstream = new FileWriter("e:/filename1.txt",true); //Will
write error details here, if file doesn't exists it will create new
BufferedWriter bw = new BufferedWriter(fstream);
bw.write("Test Project " + e.getMessage());
bw.newLine();
bw.close();
}catch(Exception a){ //For File handling Error
System.out.println("Error In File Handling");
}
}
}
Output
Test Project ERROR: Element xpath=(//button[text()='Login'])[2] not found
If any of the steps in your tests fails then selenium will throw an
exception and tests would stop. If you handle the exceptions using 'try catch', then you should be able to achieve what you are looking for.
As an
example, see the code below. This would handle the Element Not Found Error.And you can write that exception to file
try {
selenium.open("http://seleniumhq.org/");
selenium.click("xpath=(//button[text()='Login'])[2]");
}catch (SeleniumException e){ //If any error occurs
try{
//Code to write error in file
FileWriter fstream = new FileWriter("e:/filename1.txt",true); //Will
write error details here, if file doesn't exists it will create new
BufferedWriter bw = new BufferedWriter(fstream);
bw.write("Test Project " + e.getMessage());
bw.newLine();
bw.close();
}catch(Exception a){ //For File handling Error
System.out.println("Error In File Handling");
}
}
}
Output
Test Project ERROR: Element xpath=(//button[text()='Login'])[2] not found
Tuesday, 4 September 2012
Verify the height and width of image in Selenium
You can verify image height and width with help of selenium.
I have shared sample script. In this script i'm storing width and height of image and then comparing it with expected width and height.
CODE -
int wid = (Integer) selenium.getElementWidth("css=p > img.medialeft");
int hght = (Integer) selenium.getElementHeight("css=p > img.medialeft");
System.out.println(wid);
System.out.println(hght);
if ((hght == 234) && (wid == 140))
{
System.out.println("image size" +wid + " X " + hght + "pixels");
}
Else
{
System.out.println("Image width and height is not matching with expected");
}
Here expected width and height is 140 and 234 respectively.
In if condition it is checking whether width and height is same as required, if it is same it will print, else will move to other part or any error message.
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.Configure Selenium RC With JUnit Using Eclipse
Before configuring Selenium RC with Junit Using Eclipse below components are required -
1.Install JRE : http://www.java.com/en/download/
3. Download Latest version of JUnit: https://github.com/KentBeck/junit/downloads
4.Download and Install Selenium IDE firefox plugin : http://seleniumhq.org/download/
5.Download Selenium RC server and Selenium Client Drivers for Java:http://seleniumhq.org/download/
Once done with above steps launch Eclipse.
After launching eclipse, you need to Create New Project for selenium scripts
Go to File > New > Project then In Select a Wizard Click Java Project. Then provide all details like project name.
Once new project is created, right click on project go to Build Path > Configure Build Path.
Click on Libraries menu when pop-up appears, then click to "Add External Jar's ". Select Selenium RC server and Selenium Client Drivers for Java which is downloaded from http://seleniumhq.org/download/.
Once it is done, now build path is configured and project is ready to use.
Now create a package for project.
Once package is created then next step will be to create class.Right click on Package and add new class, it will ask for name. Click on Finish once class name is provided.
Once done with all above steps, your package explorer looks like below -
Once class is created you are ready to write script for selenium scenario. As well you can execute created script on eclipse IDE.
Thank you...
After launching eclipse, you need to Create New Project for selenium scripts
Go to File > New > Project then In Select a Wizard Click Java Project. Then provide all details like project name.
Once new project is created, right click on project go to Build Path > Configure Build Path.
Click on Libraries menu when pop-up appears, then click to "Add External Jar's ". Select Selenium RC server and Selenium Client Drivers for Java which is downloaded from http://seleniumhq.org/download/.
Once it is done, now build path is configured and project is ready to use.
Now create a package for project.
Once package is created then next step will be to create class.Right click on Package and add new class, it will ask for name. Click on Finish once class name is provided.
Once done with all above steps, your package explorer looks like below -
Once class is created you are ready to write script for selenium scenario. As well you can execute created script on eclipse IDE.
Thank you...
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
Selenium supported browsers
*firefox
*mock
*firefoxproxy
*pifirefox
*chrome
*iexploreproxy
*iexplore
*firefox3
*safariproxy
*googlechrome
*konqueror
*firefox2
*safari
*piiexplore
*firefoxchrome
*opera
*iehta
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
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 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 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.
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}store | 1 | delimiter
store | javascript{storedVars['string'].split('is :')[storedVars['delimiter']]} | 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.
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.
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 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
Performance
Tools for identifying the performance of web application
1.YSlow
2.Page Speed
These are browsers add-on very useful for performance measure, you can download them from below links -
There are some best practices for Speeding Up Your Web Site
You can see those practices here .
Tuesday, 7 February 2012
Software Testing
What is Software Testing?
It is an activity to evaluate and ensure the correctness and reliability of the software or program with respect to its requirements or expectation.
Importance of Software Testing:
For a while, just think that you are still in 1950 and you want to talk to a person who is at huge distance from you even without paying much money then it is just a dream. But not now .
Even the average person was never ready to buy a computer in his home due to it’s high costing but now its a common thing for us. Most of us can’t go a day without checking our emails or chat with friends/family now. We are depending on internet, gadgets, phone services and competitive medical services.
Software is everywhere and as it is created by people, it is not perfect. There are few examples as below.
Due to such countless events create importance of software testing automatically and now, it is becoming career for a life.
It is an activity to evaluate and ensure the correctness and reliability of the software or program with respect to its requirements or expectation.
Importance of Software Testing:
For a while, just think that you are still in 1950 and you want to talk to a person who is at huge distance from you even without paying much money then it is just a dream. But not now .
Even the average person was never ready to buy a computer in his home due to it’s high costing but now its a common thing for us. Most of us can’t go a day without checking our emails or chat with friends/family now. We are depending on internet, gadgets, phone services and competitive medical services.
Software is everywhere and as it is created by people, it is not perfect. There are few examples as below.
- Disney’s lion king : Program was not worked on all operating system and it became news for TV and Newspapers.
- US patriot missile defense system: This system was used during gulf war as a defense system for Iraqi scud missiles. But during war, it was failed to do so. And approx 28 US soldiers were killed.During investigation, they have found that it was because of software bug. System timing was not much accurate after 14 hrs and during war, the system had been operated for more that 1000 hrs.
- The Y2K [2000 year] bug: A programmer programmed a software such that it considered YY instead of YYYY just for saving memory. It was failed on end of 1999. It considered 00 and 01 instead of 2000 and 2001.It is estimated that several hundred millions of dollor were spent to update or replace the software which was worked like that.
Due to such countless events create importance of software testing automatically and now, it is becoming career for a life.
Subscribe to:
Posts (Atom)