Tuesday, October 23, 2012

essential tools for writing effective selenium tests (100 mcg)

When writing Selenium tests, Selenium API alone is not enough. There are some tools which are essential in functional testing.

1. Firefox Browser

Selenium has implemented most popular browsers such as Internet Explorer, Safari, Opera, iPhone, Android and Firefox. In a project, due to cost constraint, usually it is very difficult to writing tests for many browsers, I choose to use Firefox driver since it comes with a Screenshot saving function to allow recording of screenshot at anytime. I choose to take a screenshot before and after clicking a WebElement which invoke a HTTP request so when when things go wrong, I can combine the log on build machine and the screenshot series to figure out the cause of the problems. Another reason I choose to use Firefox is the availability of Firebug.


2. Firebug

https://getfirebug.com/

Even you are not writing Selenium tests, as long as you are doing web development, Firebug should be included in your toolkit. I use Firebug to inspect the web pages and design a searching strategy for the WebElements. And for none significant information, just right click the element and select "Copy XPath" from the popup menu, and the information is ready to use,



WebDriver webDriver = new FirefoxDriver();
webDriver.findElements(By.xpath("/html/body/div/div/div[3]");

This query will return the WebElement for the bug. While these two lines of code may not be meaningful to most people, but if it is in a Page object, it becomes instantly meaningful. That's the reason we need to introduce a Page model into Selenium based function tests, see design of page (500 mcg) for nutrition information.


public class FirebugHomePage {

   WebDriver webDriver = new FirefoxDriver();

   public WebElement getLargeFirebugImage() {
      webDriver.findElement(By.xpath("/html/body/div/div/div[3]");
   }
}


No comments:

Post a Comment