Selenium WebDriver

This page describes the specifics on the Selenium WebDriver usage.
IBM.com Selenium Jazz.net Documentation developerWorks
Selenium Selenium - RQM Selenium - RTW Selenium - RFT

This page describes some specifics about the Selenium Webdriver for Automated GUI testing. This is similar to RFT. The notices differences are documented here: Selenium-RFT.
On can execute the Selenium tests from the Eclipse environment, but also initiate these tests from RQM. For this the RQM jUnit/Selenium Adapter is leveraged. This is basically the RQM jUnit/Selenium Adapter

Page Contents

Using

Selenium Snippets

Poll for elements which are not there:

WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Clean the input-field:

element2.sendKeys(Keys.HOME,Keys.chord(Keys.CONTROL,"a"),Keys.DELETE);
//package org.openqa.selenium.example;
package selenium.vanlint5.nl;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Selenium2Example  {
    public static void main(String[] args) {
        // Create a new instance of the Firefox driver
        // Notice that the remainder of the code relies on the interface,
        // not the implementation.
        WebDriver driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        // And now use this to visit Google
        driver.get("http://business.vanlint5.nl/test");
        // Alternatively the same thing can be done like this
        // driver.navigate().to("http://www.google.com");

        // Find the text input element by its name
        WebElement element = driver.findElement(By.partialLinkText("login"));
        element.click();

        // Enter Userid
        element = driver.findElement(By.name("userid"));
        element.click();
        element.clear();
        element.sendKeys(Keys.HOME,Keys.chord(Keys.CONTROL,"a"),Keys.DELETE);
		element.sendKeys("clmadmin");

        // Enter Password
        element = driver.findElement(By.name("password"));
        element.click();
        element.clear();
        element.sendKeys(Keys.HOME,Keys.chord(Keys.CONTROL,"a"),Keys.DELETE);
		element.sendKeys("clmadmin");


		element = driver.findElement(By.xpath("//input[@value='Login']") );
		element.click();

        // Activate Celcius Convertor
        element = driver.findElement(By.partialLinkText("Celcius"));
        element.click();


        for (int i=0;i<10;i++) {
	        element = driver.findElement(By.name("cvalue"));
	        element.click();
	        element.clear();
	        element.sendKeys(Keys.HOME,Keys.chord(Keys.CONTROL,"a"),Keys.DELETE);
			element.sendKeys(""+i);
			String textvalue=element.getAttribute("value");
			System.out.println("Value: " + textvalue);
			element.submit();
			// sleep(1000);
			element = driver.findElement(By.name("cvalue"));
			textvalue=element.getAttribute("value");
			System.out.println("Value: " + textvalue);
        }

        element = driver.findElement(By.partialLinkText("List"));
        element.click();

        element = driver.findElement(By.partialLinkText("Logoff"));
        element.click();

		//sleep(10000);
        driver.quit();
    }

    static void sleep(int length) {
    //Close the browser
    try {
		Thread.sleep(length);
	} catch (InterruptedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
    };
}

Selenium Installation

What I've done is in line with the documentation. One comment to share:

WARNING! Be aware that the dir command results in \ characters. In the properties file you use / . For all directories etc. It took me a day to figure that out.

M2_REPO definition.

Other Resources:

  1. Documentation tip: Check for the RTW Eclipse client.
  2. Automated Testing with Selenium and Cucumber
  3. DeverloperWorks Article Run automated Selenium JUnit tests (Good one!)
  4. Get started with Selenium 2
  5. Documentation