ISTQB Certified Software Test Engineer

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'});");