ISTQB Certified Software Test Engineer

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.