Posts

Showing posts from July, 2014

Rally + Custom apps + RestAPI to customize reports / test cases

Image
If you are looking to generate custom reports based on the various fields under requirements/ build / test cases then going the Rest API way is not the right solution. Rally provides something called the custom apps which can help you achieve what you want: https://help.rallydev.com/custom If you are not happy with the custom apps that Rally provides then your last resort is the Excel Add-in that rally provides : https://help.rallydev.com/rally-add-excel-installation-user-guide The link above has details that provide information about how to use the add-in.If you have troubles during the installation then make sure you have "visual studio tools for office 2010 runtime" installed!

Testing the Page Layout with Selenium Webdriver

Image
If you are looking to test Overlapping objects with selenium webdriver? page layout of a website? Easiest way to do that: webelement.getPosition() and webelement.getDimension() . These two methods are quite good when it comes to testing the layout of a webpage. I did a quick test and found that the location would return the location of the element relative to the left top corner of the page. That means this should always return the same value irrespective of monitor resolution or window size. If you can record the location and element dimension once and store these values somewhere, You can then run automated tests using selenium to find whether the position or dimension of the element changed. If that change is greater than a delta value, then it means the alignment of the element has changed and the test has Failed!

Book Review - Selenium WebDriver Practical Guide

Image
  In the past few automation years (years where you have new tools that create a big bang effect) everyone wants to know what is it that the open-source world has to offer via Selenium WebDriver. Whether you are new to automation or you are someone who has dipped his feet using other tools, want to know more about: How does WebDriver fit into an agile /Continuous Integration environment? How Selenium WebDriver is able to automate the testing on multiple browsers?   Are there common tips that can be used while automating your scenarios? How do you create a test automation framework that has a collection of libraries and answers to all other business needs? How the book is laid out: It starts with the evolution of selenium and how it got its name, touches upon the bare minimum basics of the tool using Java. This is great, since the hardest thing about starting an automation project is often getting your basics right. The examples in the support files and downl

Get the style of a web object using selenium webdriver

Image
There are too many posts on this topic but they are all scattered in bits and pieces, bringing it all to one place to solve how to get the background color or any other css property of an element using webdriver These days elements are rarely styled with just inline styles. For example: 1 < div style = "color:red" >text</ div > An element’s style will also be dependent on its parent elements, as well as its class (ie style sheets). 1 2 3 < div style = "color:red" >    < span class = "bigtext" >text</ span > </ div > How do you get the actual style of the element (ie the computed style)? For example color WebElement elem = driver.findElement(By.xpath("//a[contains(@class,'test')]")); System.out.println(elem.getCssValue("color")); System.out.println(elem.getCssValue("background-color")); String color = elem.getCssValue("color&qu

Some cool testing tips

Image
This is an old one but i thought it was worth a share! P.S Click on the image and download to zoom in!

Trim / Remove spaces in Xpath?

Image
If you are wondering how you can trim the spaces in your xpath, this is how: The normalize-space function strips leading and trailing white-space from a string, replaces sequences of white-space characters by a single space, and returns the resulting string. Example : Which one is better? //td[starts-with(normalize-space(),'Text to Trim')] //td[starts-with(normalize-space(text()),' Text to Trim ')] The second option is better as it targets at the specific nodes More string functions in XPATH: Functions Description starts-with( string1 ,  string2 ) Returns true if the first string starts with the second string. contains( string1 ,  string2 ) Returns true if the first string contains the second string. substring( string offset length ) Returns a section of the string. The section starts at  offset (which is a number), and is as long as the value provided at  length. substring-before( string1 ,  string2 ) Returns the part of  string1  up unti

Java- code to find the earliest date + Selenium WebDriver to perform actions

Image
 Here is an interesting code that will Pick elements from a webpage  Convert the text into time                Put all the collected time into a sorted date set Pick the earliest date in the set Use this date to perform desired action on the webpage  SortedSet dates = new TreeSet(); String time; List elements = driver.findElements(By.xpath("//a[contains(text(), ':')]")); for (WebElement webElement : elements) { time = webElement.getText(); if (!(time.equals(""))) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm"); Date date = simpleDateFormat.parse(time); //System.out.println(simpleDateFormat.format(date)); dates.add(date); } } Date earliest = dates.first(); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); String found = sdf.format(earliest); String id = driver.findElement(By.xpath("//a[contains(text(),'"+found+"')]")).g

Partial screenshot / Highlight element before screenshot - Selenium WebDriver

Image
If you are using selenium web-driver and you want to either highlight element while taking screenshots or take the screenshot of a particular element, here you go : We can get the element screenshot by cropping entire page screenshot as below: File screenshot = (( TakesScreenshot ) driver ). getScreenshotAs ( OutputType . FILE ); BufferedImage fullImg = ImageIO . read ( screenshot ); //Get the location of element on the page Point point = ele . getLocation (); //Get width and height of the element int eleWidth = ele . getSize (). getWidth (); int eleHeight = ele . getSize (). getHeight (); //Crop the entire page screenshot to get only element screenshot BufferedImage eleScreenshot = fullImg . getSubimage ( point . getX (), point . getY (), eleWidth , eleHeight ); ImageIO . write ( eleScreenshot , "png" , screenshot ); //Copy the element screenshot to disk FileUtils . copyFile ( screenshot , new File ( "c:\\partial.png" ))

Find a Frame ID in Firepath / Firebug

Image
If you are into web automation you would always encounter frames that need to be identified and switched to. Here are simple steps that help you do the same: If you are not able to recognize a web-element on a webpage. Chances are that it is in a frame ,  Just right click on the webpage and you will see that it's a Frame. This can also be seen in firepath's name Steps to find the frame properties : Inspect on the element using firepath Click on the dropdown with the name of the frame Right click on the name and "inspect in DOM" tab Maximize the elements and look for an id attribute inside frame elements

Set Cookies in Selenium Webdriver / Run JavaScript

Image
There have been instances where I would run JavaScript snippets from Java's WebDriver WebDriver driver = new AnyDriverYouWant (); if ( driver instanceof JavascriptExecutor ) { (( JavascriptExecutor ) driver ). executeScript ( "yourScript();" ); } Example: ((JavascriptExecutor) driver).executeScript("window.focus()"); You can find more documentation on this in the JavaDocs of JavascriptExecutor . Now the above example is good with JS being run directly buy what if you want to set a cookie? If you are new to setting cookies then read this:  http://www.quirksmode.org/js/cookies.html Cookie ck = new Cookie ( "name" , "value" ); driver . manage (). addCookie ( ck ); Cookie cookie = new Cookie(name, value, domain, path, expiry); Read this for Selenium!