Tuesday 31 December 2013

Selenium Object Bank Services



Following are the services provided by SOB

  • Adding an Object
  • Removing an Object
  • Updating an Object
  • View Available Objects 



How to Use

Let’s start with an example by Testing WordPress Website for adding and deleting a post. 

Step 1: 
Download the sample Eclipse project for WordPress [SOB Sample Demo Download Link
Import the Project into Eclipse 
After importing you can see three Java Files 

  • atu.selenium.scripts.WithoutObjectBank
  • com.test.Testing
  • objects.mapper.com.test.HasTestingObjects

Download the latest Selenium Server Standalone jar file and add it to your Build Path

[Selenium Server Standalone Jar Link]

Download the SOB jar file and add it to your Build Path [SOB Jar File Download Link]
  • The first class atu.selenium.scripts.WithoutObjectBank is a sample Selenium WebDriver script without using SOB
  • The Second class com.test.Testing is the same Selenium WebDriver script with SOB features
  • The Third class objects.mapper.com.test.HasTestingObjects is generated automatically by SOB


Step 2: 
Right click on the com.test.Testing java and Select Selenium Object Bank Manager as shown in below figure  




Once you select, SOB window appears as shown below




  • From the SOB window you can see the available Objects in the left Pane
  • When you click on any Object from the left pane, you can see the Object details and the Element Tag type from the Properties table and the Select Box
  • To Add an Object, Enter a Unique Object Name in the field, Select the element tag type, enter the attribute and its value (you can add more than one locator)and click on Add button





  • To Remove an Object from the Available Objects, Select one of them and click on Remove button
  • To Update an Object Attribute or Value, Select any object from the left pane and edit values from the Properties table
  • The Clear Fields button is used when you want to clear the Properties and Object Name field. (While Adding an Object)



How does SOB work?
  • Create a WebDriver Script
  • Right Click on the Script and select Selenium Object Bank Manager, since it is a newly created script it pops up a message box like below as it does not have an Object Bank associated with it.
  • Click on Yes to Create an Object Bank for the Script





  • After clicking on Yes button, a Directory Named ObjectBank is created in the project folder. Under this ObjectBank directory, an XML file is generated that stores the Object details for the corresponding script
  •  The XML file name is same as the Script name and its directory structure is same as the Script package structure
  •  Along with this XML file, for each Script, a corresponding java file named Has[Script Name]Objects is generated under the objects.mapperpackage. The script’s directory structure is same as its package structure.
           NOTE:  Please refresh the Eclipse Project folder to see the newly created files 
  •  For example: if the script name is com.test.Registration.java then
  •  An XML file is generated in ObjectBank\com\test\Registration.xml
  •  A Java file is generated in objects\mapper\com\test\HasRegistrationObjects.java under src package






Future Scope for SOB


Well, we are using this approach for our Projects and will be continued in future :) 

A whole lot of new features will be introduced into SOB to the benefit of various Clients, Organizations, and Users including myself. Stay tuned :) 

We love WebDriver, as an Open Source tool, we love to keep its utilities Open Source. 
                                                                                              

Model Based Testing

A new paradigm for manual and automated functional testing.

 

Testing is an essential, but time and resource consuming activity 
in the software development process.Generating a short, 
but effective test suite usually needs a lot of manual work 
and expert knowledge.In a model-based process, among other sub-tasks
test construction and test execution can be automated.

What is Model Based Testing?

Model based testing is a black box testing technique where run time behavior 
of a software under test is checked against predictions made by a formal 
specification or model. In other means, it describes how system behaves 
in response to an action ( determined by a model). Supply action ,and see,
if the system responds as per the expectation.

Testers construct mental models anyway during their testing.
Those mental models can be transformed to models on paper. 
This helps testers to achieve readability and re-usability.

What are the advantages of Model based Testing?

  • Easy test case/suite maintenance
  • Reduction in Cost
  • Improved Test Coverage
  • Can run different tests on n number  of machines
  • Early defect detection
  • Increase in defect count
  • Time savings
  • Improved tester job satisfaction

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