Tuesday, 31 December 2013

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 












Wednesday, 27 November 2013

Calling multipe QTP scripts using VB file:

Well, Sometimes there comes a situation where we have to call multiple test files at a glance.
It would be cumbersome to call/open test one by one and run. Yet there are many alternative methods to achieve the same, but i love the way using array collection.
To make fully automated code/script you could even write a function to call all the tests from your test folder into the array collection dynamically and then executing the following code.Here, although, i have manually inserted every test into the array.

Function LoadNrun()
arrColl = Array(“C:\filename1″, “C:\filename2″,”C:\filename3″)
For each arrTest in arrColl
qtApp.Open arrTest
set qtTest = qtApp.Test
set objResultsOptions = CreateObject(“QuickTest.RunResultsOptions”) objResultsOptions.ResultsLocation = arrTest & “\Res1″ qtTest.Run objResultsOptions qtTest.Close
Next
End Function




*************************************************
How to close QTP Application through Code/Script/Descriptive Programming?
*************************************************

Close QTP Application:
Well,Question is simple but answer is little bit  complex. Here you need to search the desired application process on Win32_Process list.Microsoft MSDN has a good source of information on this topic. I am going to show the code without giving much explanation; Hope the code itself serves as a source of explanation
Please have a quick look on the above topic:
The Win32_Process:Win32 classes, such as Win32_NetworkAdapter or Win32_Process, monitor and manage system hardware and features. Generally, these classes are located in the root\cimv2 WMI namespace. The following table lists the Win32 class categories.WMI class represents a process on an operating system.
Source: http://msdn.microsoft.com/en-us/library/aa394084(v=VS.85).aspx

Code:
Function ClosemyApp()
Dim iCount iCount=0
Set oMyobj=GetObject(“winmgmts:\\.\root\CIMV2″)Set sCollectedProcess=oMyobj.ExecQuery(“select * from Win32_Process
where name=’QTPro.exe’ “)
For each iCount in sCollectedProcess iCount.Terminate()Next
Set sCollectedProcess=NothingSet oMyobj=Nothingmsgbox “Hurray!”
End Function