Professional Documents
Culture Documents
Software Required
JDK 1.6 , selenium-Webdriver-2.x(this can be
downloaded from http://seleniumhq.org/download/)
Installation Procedure
Selenium Webdriver is simply a jar file and to run it
we need java installed. (JDK 1.6 is preferred)
Once the Java is installed just unzip the selenium-
Webdriver-2.x.zip which was downloaded from the
selenium site to a directory.
Selenium-
RC
Selenium-
Webdriver
Selenium Web Driver works in the same way users interacts with the web pages. In
contrast to Selenium RC, it doesn't need a server to run. It directly starts a browser
instance and controls it.
Command :
java -jar selenium-server.jar -multiwindow -
htmlSuite "*iexplore"
"https://localhost/bookstore/"
"D:\testa.html" "C:\results.html“
Required Software:
selenium-java.2.32.0.zip , Selenium Java Client Driver jar , JDK 1.6 +, Eclipse
(or any other IDE), Junit jar and testing jar
For building the frame work we require continuous build integration tools
like Ant, Maven or cruise control.
Assert Verify
When an "assert" fails, the test is aborted. When a "verify"(Soft Assertions) fails, the
test will continue execution, logging the
failure.
Assert pass/fail is logged in the result logs With Verify failures user has to check the
automatically. logs or the console to get details or to
modify the code for all individual
verification check points.
• waitFor commands will fail and halt the test if the condition
does not become true within the current timeout setting
(setTimeout).
Locating by ID
This is the most common way of locating elements since ID’s are
supposed to be unique for each element.
Target Format: id=id of the element
• Locating by Name
o Locating elements by name are very similar to locating by ID, except that
we use the “name=” prefix instead.
o Target Format: name=name of the element
Syntax Description
•tag = the HTML tag of the element being accessed
•# = the hash sign. This should always be present when using a CSS
css=tag#id
Selector with ID
•id = the ID of the element being accessed
Syntax Description
•tag = the HTML tag of the element being accessed
css=tag.clas •. = the dot sign. This should always be present when using a CSS Selector
s with class
•class = the class of the element being accessed
Syntax Description
•tag = the HTML tag of the element being accessed
•[ and ] = square brackets within which a specific attribute and its
css=tag[attri corresponding value will be placed
bute=value] •attribute = the attribute to be used. It is advisable to use an attribute that is
unique to the element such as a name or ID.
•value = the corresponding value of the chosen attribute.
Syntax Description
•tag = the HTML tag of the element being accessed
•. = the dot sign. This should always be present when using a CSS Selector
with class
css=tag.cl •class = the class of the element being accessed
ass[attribut •[ and ] = square brackets within which a specific attribute and its
e=value] corresponding value will be placed
•attribute = the attribute to be used. It is advisable to use an attribute that is
unique to the element such as a name or ID.
•value = the corresponding value of the chosen attribute.
Syntax Description
•tag = the HTML tag of the element being accessed
css=tag:contains(“inner text”)
•inner text = the inner text of the element
Contd.
Syntax Description
Locating by Xpath
XPath is the language used when locating XML (Extensible Markup Language) nodes. Since
HTML can be thought of as an implementation of XML, we can also use XPath in locating HTML
elements.
Advantage: It can access almost any element, even those without class, name, or id
attributes.
Disadvantage: It is the most complicated method of identifying elements because of too
many different rules and considerations.
Locating by Xpath
3
© COPYRIGHT 2011 SAPIENT CORPORATION | CONFIDENTIAL 29
Process of Developing Selenium
Java Scripts.
console
• Open the folder contain the selenium project that you have just
created. Inside that folder create another folder with name
“lib”
• Inside the lib folder place the following jar files.
junit-4.8.1.jar
selenium-java-client-driver.jar
selenium-server.jar
testng-5.12.jars
After placing the jar file in lib come back to the eclipse and
click on the project explorer strip and press F5. You should see
the all the jar files under the lib folder in the project explorer as
shown in the Image in next slide.
success
failure
setUp method
This method prepares the selenium server to run the test. This
method basically hooks to the selenium server and opens up
the base URL of the application
test*** method
The methods with the name test will actually run the tests on
the application. There can be any number of test methods in
the app
tearDown method
This method will run after the end of the test. This test will
disconnect with the server and makes room for the next tests
to run the tests.
© COPYRIGHT 2011 SAPIENT CORPORATION | CONFIDENTIAL 47
Script View
The generated selenium command can be enhanced by writing java commands. Using java
methods we can do parameterization and data base validation.
More over java methods can be used for to perform some complex validations and testing
activities.
The best way to use java methods is used to is have a Java IDE like eclipse.
Implementation Steps
1) First get the values from the list box
2) To get the values from the list box or any other HTML element we need to know its Xpath.
(use Xpath checker)
3) The values taken from the list box are stored in a variable.
4) Use the indexOf method to find if “HTML” is present in the extracted variable.
Xpath Locator
• This allows for running tests in parallel, with the entire test suite
theoretically taking only as long to run as the longest individual test.
Based on your target file you can run either in sequence or in parallel