Saturday, 16 July 2016

Selenium 2 tutorial

This tutorial series is all about selenium 2, also known as WebDriver. Selinium2 is a test automation tool for web applications.

What you need to learn Selenium 2?
Basic Java knowledge is required to learn selenium 2. Following link has step-by-step installation instructions for Java.


I am going to use Eclipse IDE, to demonstrate all my example applications.

Download and install Mozilla Firefox.
Ofcourse, examples in this tutorial will work on other browsers also, I am using Firefox.

Add Firebug and FirePath plugins to Firefox browser
You can get firebug plugin from https://getfirebug.com/


I am going to use following maven dependencies.

<dependency>
         <groupId>org.seleniumhq.selenium</groupId>
         <artifactId>selenium-firefox-driver</artifactId>
         <version>2.53.0</version>
</dependency>

Since all my examples are going to deal with firefox-driver, I am using selenium-firefox-driver,

Starting with 2.53.0 you need to explicitly include HtmlUnitDriver as a dependency to include it.

<dependency>
         <groupId>org.seleniumhq.selenium</groupId>
         <artifactId>selenium-htmlunit-driver</artifactId>
         <version>2.52.0</version>
</dependency>

If you are going to use chrome browser, use following dependency.

<dependency>
         <groupId>org.seleniumhq.selenium</groupId>
         <artifactId>selenium-chrome-driver</artifactId>
         <version>2.53.0</version>
</dependency>

Following is the dependencies for safari browser.

<dependency>
         <groupId>org.seleniumhq.selenium</groupId>
         <artifactId>selenium-safari-driver</artifactId>
         <version>2.53.0</version>
</dependency>

Following is the dependency for Internet explorer browser.

<dependency>
         <groupId>org.seleniumhq.selenium</groupId>
         <artifactId>selenium-ie-driver</artifactId>
         <version>2.53.0</version>
</dependency>

Following is the dependency for edge browser.

<dependency>
         <groupId>org.seleniumhq.selenium</groupId>
         <artifactId>selenium-edge-driver</artifactId>
         <version>2.53.0</version>
</dependency>

Introductio To Selenium 2
Hello World application
Locating web elements using WebDriver
Locate elements using class name
Locate elements using CSS selectors
Locate element by id
Locate element by By Link Text Or Partial Link Text
Locate element by By name
Locate elements by By tag name
Locate element by By XPath
Find XPath Using Firebug
findElements: Get all elements that match given criteria
implicit wait
Actions on Web Elements
getAttribute: Get the value associated with an attribute
sendKeys: Write text to textbox, textarea
clear() : erase the text at textbox (or) textarea
submit: Submit the form
getCssValue: Get value of given css property
getLocation: Get location of the element
getSize: Get size of the element
getRect: get location and size of the rendered element
getText: Get visible text
getTagName: Get tag name of the element
isDisplayed: Check whether element is displayed or not
isEnabled: Check whether element is enabled or not
isDisplayed Vs isEnabled
isSelected: Check whether element is selected or not
click: Clicks this element
Taking screen shots
Switching among windows
Switching among frames
alerts handling
Navigation API
Waiting for webpage to load
Explicit timeouts
Cookies handling




Previous                                                 Next                                                 Home

No comments:

Post a Comment