Skip to main content

Posts

Showing posts from May, 2011

Selenium Tutorial - Verifiying Application Elements

Disclaimer: Objective of this post is to demonstrate how I use Selenium to do soft assertion over collection of element. I don't assert in any way that this is right approach and you are most welcome to prove me  wrong. So you want to verify collection of elements on you web page. And I assume that you want tests to continue to execute even in the wake of error with some elements. For example you want to test whether text labels for - 'username', 'password' appear on web page. (Though you may like to stop the test execution if 'username', 'password' elements them selves are not there) The worse approach I could think of is to write all assertions in one test, something like - public void testElements() { Assert.assertTrue(selenium.isElementPresent("UserNameTextLabel"), "Username Text label is not available on page"); Assert.assertTrue(selenium.isElementPresent("PasswordTextLabel"), "Password Text label is not

Selenium Function Library + File Handler

Here is my first attempt towards building Selenium Function Library . Here is a class which deals with File handling. Hence test data can be externalized in to notepad, excel, word pad instead of hard coding it in Selenium Scripts. So you can fetch test data using excel, csv etc and supply it to Selenium, more over you can execute same Selenium script for different set of data. Java jars which I used here are jxl and Apache HSSF /** * Performs read/write operations on files * */ public class FileHandler { /** * Retrieves the data from the properties file using variable name. * * @param path * to Property file. * @param variableName * stored in the properties file. * * @return value of property * @throws Exception */ public static String getDataFromPropertiesFile(String path, String variableName) throws Exception { } /** * Retrieves the Excel cell value based on the row and column number. * * @param path * @param she

Selenium Automation Framework / Reusbale Functions / Library

I have had hunch about this from long and finally I am going to work on it. As the name suggests I would be developing Selenium library which could be plugged in and used for web UI automation. And I would be working on Java Selenium client, that is Selenium 1.0 and would extend it for Selenium 2.0. So here is my wish list what I would take up for this - Writing Safe Selenium api which checks for presence of element before carrying out operation File read and write operation - using text/excel/csv HTML parsing, i.e. reading number of rows in table, get table data etc. Such methods are very popular in QTP world and there is no inbuilt api in Selenium for same.

HTML Parsing using jsoup

Came across jsoup of late, while automating web accessibility tests using Selenium. Selenium gets me the page html and jsoup does the magic of extracting required information from html to find if web page is accessibility compliant or not. You would largely be dealing with Document (which in turn extends Element ) and Elements classes when using jsoup. Consider you want to find all 'class' attributes in "div" of a web page then you could use some thing like - Document document = Jsoup.parse(selenium.getHTMLSource);         Elements elements = document.getElementsByTag("div");         for(Iterator divIterator=elements.iterator(); divIterator.hasNext();) {             System.out.println(divIterator.next().attr("class")); } Not only this, if you know the attribute value you could also find out if it appears under correct node. It could be used in automating aria test for attribute role for a web page. For a detailed list of jsoup capa

A Dream Died

Not long ago when Dave proposed to have dedicated Selenium site on Stack Exchange . And proposal was badly stuck at 70% and when few us of decided to ask more and more selenium users to commit to it to make it see day of light - After weeks of commit and persuading user we reached 92% commit but then. Well Stack Overflow did not like the ides of having a dedicated selenium site and proposed to merge it with another software testing proposal on Stack Exchange, Which was largely looked down upon at by Selenium Community. Though we were ready for browser automation proposal but merging Selenium proposal with a field like software testing was way to general for us to accept, though we were ready to have it collaborated with browser automation kind of proposal.