br.eti.kinoshita.selenium
Class SeleniumWebTest

java.lang.Object
  extended by br.eti.kinoshita.selenium.SeleniumWebTest
Direct Known Subclasses:
DataDrivenSeleniumWebTest

public abstract class SeleniumWebTest
extends Object

This is the base class for TestNG tests that generate TAP Streams (check the annotation over the class name) and control a Selenium WebDriver.

It contains a static WebDriver and a static Configuration (from Apache commons). You will have a single WebDriver during your whole test execution. It probably won't be a problem since the driver itself is not Thread-Safe.

The configuration is a composite configuration, consisting of selenium.properties file properties and system properties. The system properties override those from selenium.properties. This may be useful speciially when running your tests in Maven, Jenkins or via command line. The selenium.properties file is loaded using the classloader, then you can replace it with a new one from your project. In case you are using Maven, just create a selenium.properties file in src/main/resources, or src/test/resources.

Beware of iframe applications (like those generated by GWT-like frameworks ;). You will have to switch from one driver to another one many times. Helpful methods may be found in classes in the br.eti.kinoshita.selenium.util package. May the force be with you my friend..

Since:
0.1
Author:
Bruno P. Kinoshita - http://www.kinoshita.eti.br, Cesar Fernandes de Almeida

Field Summary
protected  org.apache.commons.configuration.Configuration configuration
           
protected  org.openqa.selenium.WebDriver driver
          The WebDriver instance used throughout our tests.
protected static org.slf4j.Logger LOGGER
           
 
Constructor Summary
SeleniumWebTest()
           
 
Method Summary
protected  void addScreenShot(org.testng.ITestContext context, Method method, SeleniumScreenshot screenshot)
          In this method, your screen shot will be converted into a TAP Stream and then put into a TAPAttribute object.
 void addScreenShot(org.testng.ITestContext context, Method method, String description)
          Adds a screen shot to the list of attributes.
 org.apache.commons.configuration.Configuration getConfiguration()
          Gets the Selenium Web Test configuration.
 void tearDown()
          Closes the driver and quit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

protected static final org.slf4j.Logger LOGGER

driver

@Inject
protected org.openqa.selenium.WebDriver driver
The WebDriver instance used throughout our tests.


configuration

@Inject
protected org.apache.commons.configuration.Configuration configuration
Constructor Detail

SeleniumWebTest

public SeleniumWebTest()
Method Detail

tearDown

public void tearDown()
Closes the driver and quit. This method is annotated to always run.


getConfiguration

public org.apache.commons.configuration.Configuration getConfiguration()
Gets the Selenium Web Test configuration.


addScreenShot

public void addScreenShot(org.testng.ITestContext context,
                          Method method,
                          String description)

Adds a screen shot to the list of attributes. TestNG has a strange behavior when adding attributes to a context. Although I am adding attributes to a context from within a method, it does not maintain your attributes separated per method. So, say you want to add the same attribute in different methods. You will have a hard time debugging until you realize sometimes it is simply replacing your attributes. Bummer.

We are adding all screen shots as image/png. This may lead to troubles in the future, so probably it will change soon. The title of your screen shot will be its name (no creativity, sorry).

TBD: Check if we can add a way to pass the file type as parameter.

Parameters:
context - TestNG test context.
method - TestNG test method, to which we will link your attribute to.
description - Screen shot description.

addScreenShot

protected void addScreenShot(org.testng.ITestContext context,
                             Method method,
                             SeleniumScreenshot screenshot)

In this method, your screen shot will be converted into a TAP Stream and then put into a TAPAttribute object. This object will be stored in TestNG Test Context.

Later, TestTAPReporter from tap4j.org project has the logic to transform it into a YAMLish diagnostic entry in your TAP Stream. From this point on, the limit to where, how, when it will be used is your imagination.

Parameters:
context - TestNG test context.
method - TestNG test method, to which we will link your attribute to.
screenshot - A screen shot, that will be added to a TAPAttribute.
See Also:
TAPAttribute}, TestTAPReporter}, Test Anything Protocol


Copyright © 2010-2011. All Rights Reserved.