ISTQB Certified Software Test Engineer

Thursday, July 2, 2015

Webdriver reporting for Selenide Test Cases

Selenide is one of the functional automation testing frameworks developed on top of Selenium-Webdriver with a concise UI testing approach.
Selenide is developed on top of Selenium-Webdriver Java bindings,the test cases designing using selenide will follow Page-Object design pattern which is most widely used pattern for selenium automation.
Most of us use Selenium-WebDriver reporting which is one of the good reporting frameworks developed by vorburger for generating test reports for Selenium-Webdriver test cases,if we use JUnit as an unit testing framework.
This reporting is dependent on the Webdriver initation during our test suite execution,but in selenide we don't initate or quit a browser since the selenide framework handles that automatically.Integrating webdriver reporting framework to selenide test cases needs a simple configuration,so that reports will be automatically generated after this configuration.
You can find the code in my github page ,which contains test cases for selenium site automation developed using page object pattern

Sunday, June 28, 2015

A SQL Based Data Driven Framework for Selenium using Excel

While Developing Selenium Test Cases,executing test cases with multiple data sets is required.There are several apis like Apache Poi,JExcel,Open CSV ,using which one need to come up with there suitable implementation for data retrieval and to integrate with their test cases.This requires some coding on top these apis,to make these apis,to meet their requirements.

There is one such api which is developed on top of apache poi,which supports SQL operations like Select,Update,Delete on your Spread Sheet Data .The Framework is called Fillo developed by Codoid.Using this framework retrieving data from data sources is easy,since one has to write SQL queries on Spread Sheet instead of some java implementation.

Codoid Treats the sheet name as a table,first row as column names,remaining columns as a table.If you 10 scenarios you need to use 10 sheets in spread sheet one for each scenario,where sheet name represents the scenario name.

In the below image UserLogin is a table name,which is a scenario name that contains data which need to be validated against login test.The first row represents the column names,mapped to fields in our UI.The User role is a filter variable which will be specified as where condition variable in our SQL Query.If we dont specify where in our query,the script will be executed with all 5 rows of data.If Filter Variable is Specified script will be executed based on where condition.If we use LoginFailed as filter variable,then the script will be executed with 3 rows of data.

Usage of Fillo in our Script.

Fillo fillo=new Fillo();
Connection connection=fillo.getConnection("C:\\Test.xlsx");
String strQuery="Select * from Sheet1 where UserRole like 'LoginFailed'
Recordset recordset=connection.executeQuery(strQuery);

while(recordset.next())
{
driver.findElement(By.Id("UserName")).sendKeys(rs.getField("UserName"));
driver.findElement(By.Id("Password")).sendKeys(rs.getField("Password"));
driver.findElement(By.Id("LogIn")).click();
if( Assert.assertTrue(driver.findElement(By.Id("Logout")).getText(),"Logout"))
{
System.out.println("Login Success");
}
else {
System.out.println("Login Failed");
}

}
recordset.close();
connection.close();

More Details on Fillo can be found at Fillo WebSite

Sunday, May 25, 2014

Ignoring JS Errors in HTML Unit Driver --Here is the Solution

When you are using one of the greates features of Selenium,Headless browser,we may find several issues like javascript handling,unable to handle ajax calls and soon... Here is the confiuration of Htmlunit driver,so that we can over come those issues.

HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.){
@override
public WebClient modifyWebClient(WebClient client){ webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setThrowExceptionOnFailingStatusCode(true); webClient.getOptions().setThrowExceptionOnScriptError(true); return client; } }; driver.setJavaScriptEnabled(true);

Friday, October 25, 2013

Seleniumr-Handling Unexpected Popups

Some times When we are doing automation using Selenium , sometimes unexpected popups/alert message will appear on the screen.An automation engineer doesn't have a code to handle this when it is unexpected (since it is inconsistent),this leads to script failure.
In Selenium there is way to handle these unexpected alert/popup messages in the following way.
When ever we have unexpected popup/alert appears in the application,it throws an unhandled alert exception and script will fail. So We have to handle this unhandled alert exception in our test method and then we need to switch to the original content.

Example:
@Test
public void googleTest(){
try{
driver.get("http://google.com");
driver.findElementById("q").sendkeys("selenium");
}
catch(UnHandledAlertException e){
driver.switchTo().alert().accept();
driver.switchTo().defaultContent();
}}


The above test method explains about handling unexpected popups.
When ever we have an UnHandlerdAlertException,catch that excption,switch to alert and accept that alert.
Then Switch to Default Content means the original Content.

Wednesday, June 5, 2013

Protected Mode Settings not for Same Zones IEDriver Selenium


Using IEDriver in Selenium may lead to some security issues like Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (WARNING: The server did not provide any stacktrace information)
The Protected mode settings may be different,these are managed by administrator and we are not authorized to change these settings,i n these cases adding capabilities to the driver instance may overcome these issues.
Below is the code.

DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
WebDriver driver = new InternetExplorerDriver(caps);


More about IE Protected Mode Click here

Thursday, May 2, 2013

Element Not Present in Selenium Webdriver

Some times when we are automating the applications using web driver,we need to check whether an element is present or not.If it is present a particular method has to be called,if the element is not present another method has to be called.

For example In User Profile page if user has permissions to edit,editProfile script should be called,if user doesn't have permissions to edit viewProfile should be called.

But in webdriver if element appears then it will work fine,if it is not present then it will directly throw an exception(ElementNotFound or NoSuchElement).If it throws an exception,this should be handled, we need to call viewProfile method as per the above example in CatchBlock.

If we have same kind of scenario for some other element then we need to call that as well in catch block which is not a good solution.

So to handle this type of scenarios we need to write an user defined generic function which can verify an element is present or not.


Simply call the above method in test method of your script



if element is present if goes in one flow,else it takes another flow

Tuesday, February 19, 2013

Handling Scalable Vector Graphics(svg) elements in Selenium

Scalable Vector Graphics is an XML based vector image format for two-dimensional graphics that has support for interactivity and animation Selenium as functional testing tool,needs to identify SVG graphic elements as well when we test web applications whose UI is implemented using SVG.The Tags for these svg elements in DOM are not HTML tags.

All the SVG elements may have same attribute values or the values that may change dynamically.It is not possible to identify the elements based on Tag in xpath expression(since these tags may not be identified by dom as they are not html tags.) Small SVG example Hello, World!

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width='300px' height='300px'>
<title>Small SVG example</title>
<circle cx='120' cy='150' r='60' style='fill: gold;'> <animate attributeName='r' from='2' to='80' begin='0' dur='3' repeatCount='indefinite' /></circle>
<polyline points='120 30, 25 150, 290 150' stroke-width='4' stroke='brown' style='fill: none;' />
<polygon points='210 100, 210 200, 270 150' style='fill: lawngreen;' />
<text x='60' y='250' fill='blue'>Hello, World!</text>
</svg>
The above is the SVG used to Create a Circle,polygon and Polyline as shown in the graphics above.In order to identify a circle the Xpath expression should be framed as

//*[@cx ='120']

if we specify
//circle[@cx='120']
the circle tag could not be identified by Selenium. So when identifying the SVG graphics using generic Xpath expression is preferable(using * instead of identiying using tag name) Please email me if you have any issues with handling SVG graphics using selenium.

Monday, October 29, 2012

VBScript Selenium WebDriver

Selenium Web driver supports a wide variety of client drivers implemented in different languages,but it does not support Vb script client drivers which is playing a key role in QTP automation. QTP and Selenium are the two widely used functional automation tools which are always different(in terms of licensing ,the languages they support for scripting). But now VBS webdriver is an api used to implement selenium web driver using VB script(Now This is common for QTP & Selenium:)). Now one can automate their application using selenium ,choosing vbscript as their scripting language. Please see the below link for more details VBS Webdriver.

Tuesday, April 24, 2012

Handling Element not visible exception in Selenium


While working with Selenium Web driver in your project,there will be some scenarios like handling Smart Menus(Drop down menus),hidden buttons,hidden links etc...
Some times using wait's will solve the problem of handling hidden elements,but not every time.

For example if we are using drop down menu,when we click on Main menu,the drop down will be populated.When we change the mouse position the drop down will close.In such scenarios it will be difficult to click on sub menu.

This can be handled by using JavaScriptExecutor Class of Web driver.Using this class we need to change the CSS property of that web element(By default this element is invisble)as below.
JavascriptExecutor js=(JavascriptExecutor)driver; js.executeScript("$('"+CssSelector+"').css({'display':'block'});");

Example:
<span class="main">Outer Span
<span>Inner Span</span>
<ul style="display:none">
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</span>
The list in the inner span is invisible,assume that it will be visible when we place mouse on the outer span. This scenario is difficult to handle using web driver,because when we change mouse position the list may go invisble. This case will be handled in web driver by using the following piece of code.

driver.findElement(By.ClassName("main")).click();
//click on Span,then change CSS property of UL using JavaScript Executor
JavascriptExecutor js=(JavascriptExecutor)driver;
js.executeScript("$('span.main ul').css({'display':'block'});");

Thursday, March 29, 2012

Running a Selenium Script Parallelly using Web Driver

If we want to run a Selenium Script across multiple machines parallelly we are using Selenium Grid.
Using Selenium web driver we can achieve this parallel execution with the help of Remote Web driver class and starting Standalone jar on the remote machine(remote machine may be your local some times).
But with this approach you can run the script in multiple browsers in the same
machine.
The prerequisites to implement this using web driver are
1.Browsers to be installed in the machine
2.Standalone Selenium Server jar has to be started.
Here is the sample code


import static org.junit.Assert.assertTrue;

import java.net.MalformedURLException;
import java.net.URL;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class GoogleTest {

public static WebDriver driver;
@BeforeClass
public static void main(String args[]) throws Exception{

DesiredCapabilities browsers[] ={DesiredCapabilities.firefox(),DesiredCapabilities.internetExplorer()};

for(DesiredCapabilities capabilities :browsers){

System.out.println("Executing Google Test in"+capabilities.getBrowserName());
driver =new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), capabilities);

driver.get("http://google.com");
driver.get("http://www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Cheese!");
element.submit();
System.out.println("Page title is: " + driver.getTitle());
assertTrue(driver.getTitle().contains("cheese!"));


}

}
}

Monday, February 6, 2012

WebDriver Backed Selenium---Selenium RC Integrated with WebDriver

Selenium Launched its version2 and they named it as Webdriver.The working and api of this webdriver is quite simple when compared with the Selenium RC which is implemented on JavaSCript and whose api is quite complex.

Many people started working in RC and they are getting familiar with this api, Thought works released their version 2 suddenly which is different from their version 1 .This makes the selenium testers a bit confusion.

Later in their second version they integrated Selenium RC api and they named it as Webdriver backed selenuim,using which testers can write their Test cases using RC as well as Webdriver apis.

Monday, January 9, 2012

Clustering atechnique for improving test case Prioritization

Providing a quality product is a challenge for every originization.Different organizations follow different approaches for improving their quality standards,but for every approach a TestPlan and testcases are needed.

Consider an application which is having some hundreds of Test cases,if we need to perform a sanity test over the application ,How can we test??

What are the test cases that we need to test in sanity testing??'


For each and every test case we will assign some priority and we start testing high priority test cases in this situation.Now the question is How can we assign priority??
There are many ways to assign priority but one efficient technique is to use Clustering approach(Data Mining concept).
Clustering is a Datamining technique in which the objects(for us test cases)are divided into groups and objects in the same group will have similar futures.These groups are also called clusters.


How can we performing clustering on test cases??
The closest test cases in terms of code coverage are grouped into cluster.


How can we prioritize those test cases??

We can Prioritize them using
1.Code COverage
2.Code complexity
3.Fault History Information.


"A clustering approach to improve testcase prioritization" by Ryan Carlson an employee of "Microsoft" explained this process in IEEE international conference on software Maintenance.

Tuesday, November 1, 2011

RemoteWebDriver cannot be cast to org.openqa.selenium.Takes Screenshot,error in Selenium

Finally I am running Selenium Scripts in a Remote Machine.This time I need a Screen Shot of the Browser which initiated in Remote Machine.

So I googled and found a piece of code which Can do this task for me.This is the Code.

File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));

I appended this to my script and executed the script,I got the following error in logs.
org.openqa.selenium.remote.RemoteWebDriver cannot be cast to
org.openqa.selenium.TakesScreenshot.

So finally i found a fix for this error,and got screen shot of the remote machine.Here is the code which worked for me.

public class GoogleTest extends TestCase{

@Test
public void testSearch() throws Exception {
URL url = new URL( "http", "localhost", 4444, "/wd/hub" );
DesiredCapabilities capabilities =DesiredCapabilities.internetExplorer();
capabilities.setJavascriptEnabled(true);
WebDriver driver = new RemoteWebDriver(url,capabilities);
driver.get("http://www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Cheese!");
element.submit();
System.out.println("Page title is: " + driver.getTitle());
Thread.sleep(3000);
assertTrue(driver.getTitle().contains("Cheese!"));
WebDriver augmentedDriver = new Augmenter().augment(driver);
File screenshot = ((TakesScreenshot)augmentedDriver).
getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, new File(
"c:\\screenshot\\googlesearch-webdriverapi.png"));
driver.quit();
}


}

Selenium WebDriver,Running Scripts in a Remote Machine

Selenium is famous for its Cross Browser Testing.With the new changes in Selenium2(Re-implementation of Web driver),running test scripts becomes easier compared to Selenium RC.Selenium web driver does not have any server,but its native API initiates the browser directly.
But this is not suitable for the scenarios where there is a need of running selenium scripts remotely,because we are not running any server.In RC since we are running RC server,we can do that easily.
People of Thought Works came up with a solution for running selenium test remotely.
Here is the procedure for running a selenium test Remotely.

1.Download selenium-server-standalone-2.*.jar Click here to download the jar(If this jar is deprecated please try for a new jar.Just type selenium standalone jar for web driver in Google for new jar).Download the jar file in remote machine.

2.Run the following command java -jar < downloaded jar filepath>in remote machine.

3.Then run the following java code from the machine from which you are going to initiate the remote machine.


import java.io.File;
import java.net.URL;
import org.openqa.selenium.OutputType;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
public class SeleniumTest {
public static void main(String s[]) throws Exception {
URL url = new URL( "http", "localhost", 4444, "/wd/hub" );
DesiredCapabilities capabilities =DesiredCapabilities.internetExplorer();
System.out.println("1");
capabilities.setJavascriptEnabled(true);
System.out.println("2");
WebDriver driver = new RemoteWebDriver(url,capabilities);
System.out.println("4");
driver.get("http://www.google.com");
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\screenshot\\googlesearch-webdriverapi.png"));
driver.quit();
}
}

Change the following statement in your code.

URL url = new URL( "http", "localhost", 4444, "/wd/hub" );

instead of localhost give the remote machine ip address.

Wednesday, August 3, 2011

Who Coined the term "BUG" ?

Every software tester is familiar with the word bug.They Used this word very often.
Who disocovered it?In what application they foound this?
It was very difficult to answer......:)

The term bug was coind by "Grace Hopper" for the first time in 1945.
In 1945, Grace Murray Hopper was working on the Harvard University Mark II Aiken Relay Calculator (a primitive computer).
On the 9th of September, 1945, when the machine was experiencing problems, an investigation showed that there was a moth trapped between the points of Relay #70, in Panel F.

Thursday, July 28, 2011

Selenium2.0---Webdriver

Thought Works released their latest version of Selenium(Selenium 2.0).Selenium 2.0 also contains 3 components Selenium IDE,Web Driver and Selenium Grid.
In Selenium2.0 Remote Control is replaced by Web driver.This Web driver is very quick in test execution when compared to Selenium RC.

Major advantages with Web driver when compared to Selenium RC is

1.Selenium RC uses a Proxy through Java Script to launch a browser which usually takes some time,but coming to Web driver it supports some native apis for each web browser(Special api for each browser)so that web browser can be launched quickly using these apis.
2.The API of SeleniumRC is quite complex when compared to Web driver api.
Till now Webdriver supports only Java api.Drivers for all other langauges are still in development stage.
The Webdriver api will be available in the following link
Webdriver API

Wednesday, July 27, 2011

Mock Objects for quick Unit Testing

For large or smalle Code of Applications it is Programmers job to test their code.Unit Testing one of the levels in Software Testing is purely for the developers.They have to write unit tests and they have to examine(test) their code.

A good unit test case is a small piece of code(mostly written in a single method)which is for testing specific functionality.In Large,complex well designed systems different objects have to work together to accomplish a particular task.
For example in order to write a simple test case to verify Login functionality user name and password has to be taken from database and using these as inputs test case has to be executed.

So if we are using database we have to create many objects(eg:Objects for Prepared statements,Result Set,DB Connection etc..).It is a complicated task to create some 'N' objects for testing simple unit test case.Creating these 'N' doesn't make our unit test to be completed in quick time.

Mock Objects are the Objects which Pretended to be as Real Objects makes this process easier.A mock object is a replacement for a real object that we create for the express purpose of testing. Mock objects were championed by Tim Mackinnon, Steve Freeman, and Philip Craig


There are Many Frameworks for effective usage of mock objectes in our unit tests like JMock,Mockito,EasyMock etc..

Tuesday, July 26, 2011

FITNESSE A USER ACCEPTANCE TESTING TOOL


What is User Acceptance Testing?

User Acceptance Testing is often the final step before rolling out the application. Usually the end users who will be using the applications test the application before ‘accepting’ the application. This type of testing gives the end users the confidence that the application being delivered to them meets their requirements.
User Acceptance Testing – How to Test?
The user acceptance testing is usually a black box type of testing. In other words, the focus is on the functionality and the usability of the application rather than the technical aspects. It is generally assumed that the application would have already undergone Unit, Integration and System Level Testing.
However, it is useful if the User acceptance Testing is carried out in an environment that closely resembles the real world or production environment.
The steps taken for User Acceptance Testing typically involve one or more of the following:
.......1) User Acceptance Test (UAT) Planning
.......2) Designing UA Test Cases
.......3) Selecting a Team that would execute the (UAT) Test Cases
.......4) Executing Test Cases
.......5) Documenting the Defects found during UAT
.......6) Resolving the issues/Bug Fixing
.......7) Sign Off
What is Fitnesse?
FitNesse is a web server, a wiki, and an automated testing tool for software. It is based on Framework for Integrated Test (FIT). FitNesse is designed to support acceptance testing. Fitnesse allows users of a developed system to enter specially formatted input. This input is interpreted and tests are created automatically. These tests are then executed by the system and output is returned back to the user. The advantage of this approach is very fast feedback from users. The developer of the system to be tested needs to provide some support (classes named "fixtures").

Monday, June 27, 2011

IE Script Error while running Selenium RC


Today while running Selenium RC in IE8 in windows 7 i have got this error.I googled to find a solution for the above error and atlast i was passed.
1.Open command prompt and run it in adminstartor mode.
Right click on CMD and click on Run as Administrator




2.Run Selenium server jar and continue running your tests.

Script error will be fixed and we will get a result

Friday, January 7, 2011

CSS Conditional comments

Cascading style sheets(CSS) conditional comments are used to fix browser issues.They work only for windows ie.Other browsers treat these lines of code as commnets except ie due to their syntax.Here is the example
<!--
<!--[if IE 6]>
.header{
width:600px;
}<![endif]-->
-->

The above piece of code should be added in head section of the html file.
For example if we set the width to 700px in ie6 the width will be reset to 600px due to this conditional comments.
So we can solve ie cross browser issues using this by writing styles individually for each ie.
U can have clear idea on this conditional comments with this example
<p><!--[if IE]>
According to the conditional comment this is Internet Explorer<br />
<![endif]-->
<!--[if IE 5]>
According to the conditional comment this is Internet Explorer 5<br />
<![endif]-->
<!--[if IE 5.0]>
According to the conditional comment this is Internet Explorer 5.0<br />
<![endif]-->
<!--[if IE 5.5]>
According to the conditional comment this is Internet Explorer 5.5<br />
<![endif]-->
<!--[if IE 6]>
According to the conditional comment this is Internet Explorer 6<br />
<![endif]-->
<!--[if IE 7]>
According to the conditional comment this is Internet Explorer 7<br />
<![endif]-->
<!--[if gte IE 5]>
According to the conditional comment this is Internet Explorer 5 and up<br />
<![endif]-->
<!--[if lt IE 6]>
According to the conditional comment this is Internet Explorer lower than 6<br />
<![endif]-->
<!--[if lte IE 5.5]>
According to the conditional comment this is Internet Explorer lower or equal to 5.5<br />
<![endif]-->
<!--[if gt IE 6]>
According to the conditional comment this is Internet Explorer greater than 6<br />
<![endif]-->
</p>


Copy the above code and save in html file and run the html file in different ie versions,so that u can clearly understand coditional comments