div.menu4 { /*width:500px;margin:0 auto;*//*Uncomment this line to make the menu center-aligned.*/ text-align:center; font-size:0; height: 25px; *position:relative;*top:1px;/*Hacks for IE6 & IE7 */ } div.menu4 a { display: inline-block; margin-right:6px; /* It specifies the distance between each tab */ background:#FFF url(bg.gif) repeat-x 0 0; padding-left:4px; vertical-align:top;/*ChangeSet#1*/ text-decoration:none; } div.menu4 a span { display: inline-block; background:#FFF url(bg.gif) repeat-x 100% 0; padding: 0 20px; text-decoration:none; font: normal 12px Arial; line-height: 25px; color:#7087A9; vertical-align:top; } div.menu4 a:hover, div.menu4 a.current { background:#FFF url(bg.gif) repeat-x 0 -25px; line-height: 26px; } div.menu4 a:hover span, div.menu4 a.current span { background:#FFF url(bg.gif) repeat-x 100% -25px; line-height: 26px; color:#244D8A; } div.menu4sub { height:8px; border:1px solid #C2D5EF; background:#eee url(bg.gif) repeat-x 0 -50px; }

Wednesday, 24 February 2016

Selenium Automation

Selenium WebDriver - Arhitecture

I Try And Simplify as much as really possible to understand the way the architecture of Selenium formed.
Selenium WebDriver Divided into 3 major sections

1. Level Bindings that are language
2. Selenium WebDriver API
3. Drivers

Language Degree Bindings:

We've got a common API which has a common set of instructions and we've different bindings for the languages that are different. So we could see there's Java, Python, Ruby, etc..There Is also some other bindings and new bindings can be added quite easily.

Selenium WebDriver API:

Now these bindings communicate with Selenium WebDriver API and this API deliver the commands taken from language level bindings inter-Pret it and sent it to Specific driver. In short-term API contains set of common library which allow sending command to respective drivers.


Internet Browser Special Drivers such as IE, FF, Chrome etc..It functions in headless mode which makes, text execution quicker. Additionally, it contains mobile Drivers that are specific.

 The basic notion is each one among these drivers understands the way to drive the browser that it corresponds to.

For E.g. Chrome Driver understands how to handle the low-level details of chrome driver and drive it to do things like clicking the target element, browsing the target page etc...

How it's operating:

You might be writing your test in Java utilizing typical that instructions are being sent by Java binding across this API that is typical and selenium API. Now on another end is listening a driver, it interpret those commands and executing them on the actual browser and return result copy using the API.

Selenium Webdriver - Page Object Model:

  • Developing an automation code that is maintainable is just one of the keys to some successful test automation Task. Test-automation code has to be treated as creation code and standards that are similar And patterns should to be applied while developing this code.

  • While building Selenium Web Driver evaluations, we can use the Page Object model pattern. This Pattern assists in improving the tests, making them exceptionally maintainable, cutting back the code duplication, concealing the internal execution from tests, and creating a layer of abstraction.Utilizing the Webpage Object Model

  • By applying object oriented advancement principles, we can develop a category that serves as an Interface to some web site in the program, modeling its qualities and conduct. This helps In making a layer of separation involving the test code and code specific to the page, by hiding the technical execution including locators used to recognize components on the page, layout, etc. 

  • The Page Object design pattern provides tests for an interface in which an evaluation can work on that page in a way much like the consumer accessing the page, but by concealing its internals. 

  • As an example, if we build a Page Object evaluation for a log-in page, then it'll provide A method to login, that will accept the user name and password and simply take the user to the Welcome page of the program. 

  • The evaluation need not worry about input controls are employed for the login page, their locator details, etc.Evaluations should use objects of a page in a high degree, where any change in lay out or characteristics used for the fields in the inherent page must not break the evaluation.

  • This chapter covers recipes to create tests using relevant design and Page Item model. For exposing, using the PageFactory type elements from a page

  • For executing the Page Object model in tests, we must chart and produce a Page Item Type for every page being analyzed. For example, to test a BMI, the BMI Calculator program. Calculator page category is going to be defined. 

  • That will show the internals of the BMI Calculator Page to the evaluation, as shown in following diagram. This can be performed through the use of the PageFactory class of Selenium WebDriver API. Sample Codes will soon be posted soon......

WebDriver - Catching Screen shot:

This may help when test run and exceptional malfunctions during execution, by Utilizing the web page will be Captured by the TakeScreenhot Interface WebDriver.
Sample Code:


public void testScreenshot()
try {
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\Screeshots\\Loginpage.png"));
} catch (Exception e) {

How It Works....

The TakesScreenshot interface supplies the getScreenshotAs() method to catch
a screen capture of the page shown in the driver example. In the below code , we
Defined OutputType.FILE as an argument to the getScreenshotAs() approach.

So that it will return the captured screen shot in a file:
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

We can save the file object returned by the getScreenshotAs() approach using the
copyFile() procedure of the FileUtils class

WebDriver - Automating Dropdowns Using Select Class:

WebDriver supports Automating Drop Down and List controls using a unique "Select" category in the place of the WebElement category.

Let's produce a test for a Drop-Down management. This test will perform some basic tests and after that call various methods to choose alternatives in dropdown.

Sample Code:


public void testDropdown() {
//Get the Dropdown as a Select using its name attribute
Select make = new Select(driver.findElement(By.name("make")));
//Verify Dropdown does not support multiple selection
//Verify Dropdown has four options for selection
assertEquals(4, make.getOptions().size());
//With Select class we can select an option in Dropdown using visible Text
assertEquals("Admin", make.getFirstSelectedOption().getText());
//or we can select an option in Dropdown using value attribute
assertEquals("Manager", make.getFirstSelectedOption().getText());
//or we can select an option in Dropdown using index
assertEquals("Contributor", make.getFirstSelectedOption().getText());

Selenium Automation Framework Layout:

To design a framework we need to focus on the following factors.
1. We must create UI Map
2. Libraries for UI objects.
3. Layout groups depending on use under test.
4. Plan for evaluation execution approach to minimize the time.
5. Design report generation.
6. Prepare step suite and a Step table.
7. Prepare a Data established whereever needed
8. Design Key Word Driven activity fixtures
9. Design and develop the code that is psudo.

Frame function has several varieties and most well-known are the below
a.Keyword driven frame work
b.Data driven driven frame work
c.Hybrid framework

Key word Driven Frame work:

Keyword driven framework is an action based test approach used in planing and implementation of automation.

Data Driven Framework:

Data driven is the layout of possible inputs what may distributed by by the end-user. This may cover maximum probabilities of an input information. It may be Spread sql or sheet. We need to link and move the values to component or the specific field.

The experienced person on the project should designs the data. It could be even or a client non specialized person but should be more familiar with consumer would-be.
We need to chart the file path properly.

Hybrid Frame Work:

Hybrid Framework is only the mixture or the group of some frame work according to the frame work programmer it can be called by us as framework.

  1. Sample Template - Frame work Psudo Code
  2. Sample Template - Step Table
  3. Sample Template - Data Set
  4. Sample Template - UI Map

Simple Startup in Web Driver:

Web driver is a java interface which is having bunch of executing types and capabilities which we can send from javadocs in selenium official site.

Download newest java consumer variation from http://seleniumhq.org/download/. Its a zip pack, Unzip and go to eclipse Generate new java project and right-click on java project and select Build Path ---">> Configure assemble path Click "Add External Jars" and pick all the jar under the unzipped folder. Click OK.

Now Create New class and try the following sample code:

import org.openqa.selenium.firefox. FirefoxDriver;

Public class test {

Public static void main (String[] args) {
Webdriver v1 = new firefoxDriver();

// This will initiate firefox brower

It will open a firefox browser window and launch facebook site. Type
v1.quit - to quit the browser.

Check it out!!!

Selenium IDE - parametrization:

Parametrization is one of the key area in Test automation. Create and we have to design the most mix of test info to give as input signal. This is among the main reason we're going to RC. But it might be possible in Selenium IDE also.

Steps to invoke the data file in to Selenium IDE

1.Create (Copy and Paste) Following data in a notepad.
Keyword = "Selenium Automation Framework Design"

2. Save the file in Java Script format (datapool.js)

3. Open Selenium IDE and Choose --">>Options--">>Alternatives.

4. Under Selenium IDE Extensions See The Saved .js file

5. Click OK and Restart Selenium IDE.

No comments:

Post a Comment