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.