Monday 30 December 2013

Automation Testing Utilities!!

Selenium Object Bank - SOB

Google’s Selenium Web Driver has took a pace where automating a web application has made easier than ever. With very few methods exposed by the API, almost all the actions can be achieved that are necessary for working with a web application.

In automation script where all the application Objects are given within, maintaining these Objects can be tiresome. Readability of the Script is not as easy as it looks. Understanding the code at later point of time can be real painful. Addressing these issues users including myself had followed various approaches for minimizing the complexity, one such is implementing the Page Object Pattern, or may be storing all the Objects in an external property file, Providing detailed comments for the Objects, or any other user defined approach.

Keeping these in mind, I wondered how we could deal with all these cumbersome tasks using one single solution. There took the birth of Selenium Object Bank (SOB) that can address the following questions. 
·                     Storing all the Objects in a central location
·                     Changing Object properties without any modification on the Script
·                     Readability and clear understanding of the automation steps performed by just looking into the Script
·                     Minimizing the Script code by Object notation
·                     Creating Robust Scripts
·                     Re usability of the Objects
·                     Identifying the Objects with different locators other than those provided by Web Driver (id, name, xpath, css, class, tagName) 

Sample Code

A Sample code for automating WordPress website using regular approach

driver.findElement(By.id("user_login")).sendKeys("admin");
driver.findElement(By.id("user_pass")).sendKeys("demo123"); 
driver.findElement(By.id("wp-submit")).click();
driver.findElement(By.linkText("Posts")).click();
driver.findElement(By.linkText("Add New")).click();
driver.findElement(By.id("title")).sendKeys("Sample");
driver.findElement(By.id("publish")).click();
driver.findElement(By.linkText("All Posts")).click();
driver.findElement(By.id("post-search-input")).sendKeys("Sample");
driver.findElement(By.id("search-submit")).click();
driver.findElement(By.xpath("/html/body/div/div[3]/div[2]/div/div[4]/form/table/thead/tr/th/input")).click();
WebElement selectBulkOption = driver.findElement(By.name("action"));
Select select = new Select(selectBulkOption);
select.selectByVisibleText("Move to Trash");
driver.findElement(By.id("doaction")).click();


Same code when used with SOB

setWebDriverObject(driver); 
uname().sendKeys("admin");
pass().sendKeys("demo123");
login().click();
posts().click();
addNew().click();
postTitle().sendKeys("Demo Post");
publish().click();
allPosts().click();
searchBox().sendKeys("Demo Post");
searchPostsButton().click();
tickAllCheckbox().click();  
postActions().selectByVisibleText("Move to Trash");
applyButton().click(); 

using SOB, it makes easier for a person to read the program. It hides the Object details keeping them separately.

Installing the Plug-In


Selenium Object Bank is available as a Plugin for Eclipse IDE. Follow the below steps for downloading and installing the plugin

Step 1:
Download the plugin
  • Open the link [ Plugin Link ]
  • Click on “File” menu and select “Download” option as shown in figure.
  • Save the zip file to your local drive and extract the folder now this directory contains the SOB plugin files.





Step 2:
Open eclipse application. Go to “help” and select “Install New Software…”
 

Step 3:
A window gets opened, now click on Add button, this time a small window appears as shown in figure




Step 4:
Click on local button and browse for the plugin directory as shown in figure and then click on OK button





Step 5:
Once the plugin directory is selected, the path is shown in the small window. Click on Ok button, you can also give the name it’s optional.

Once after clicking the Ok button you will see “Selenium Object Bank” category. Tick the checkbox and click on Next button as shown in figure. 




  • After clicking “Next” button, here it takes some time for calculating requirements and dependencies.
  • After the process is done click on “Next” button
  • Next accept the license agreement by selecting the “Accept” radio and then Click on “Finish” button.
  • During the installation it might give a Warning message. Click on OK button.



  • After the installation restart the eclipse application.
  • Done here you go … SOB is now ready to use 












1 comment: