Thursday, July 2, 2015
Webdriver reporting for Selenide Test Cases
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
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
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
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
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
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.)
<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
if we specify
Monday, October 29, 2012
VBScript Selenium 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
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
Monday, January 9, 2012
Clustering atechnique for improving test case Prioritization
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??
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
Selenium WebDriver,Running Scripts in a Remote Machine
Wednesday, August 3, 2011
Who Coined the term "BUG" ?
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
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
<!--
<!--[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
