Testing XPages

When testing XPages with Selenium, you can easily pre-generate the JUnit test code with the browser plugin. But when you then change the structure of the XPage (f.e. by moving the components from an XPage to a custom control), all the IDs of the JUnit test will not work anymore.

That’s why it is better to use CSS selectors to access the generated fields:


With the selector „id*=’idOfTheComponent'“ you can access the elements by their component id, idependently of their full generated client id.

Here is an example with a small XPage with a radio group and a listbox:


A simple XPage to test (SimpleDemo.xsp)

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

        <xp:selectItem itemLabel="1" itemValue="1" />
        <xp:selectItem itemLabel="2" itemValue="2" />

    <xp:listBox id="listBoxSimpleDemo" multiple="true">
        <xp:selectItem itemLabel="1" itemValue="1" />
        <xp:selectItem itemLabel="2" itemValue="2" />
        <xp:selectItem itemLabel="3" itemValue="3" />

 The JUnit Test

package ch.hasselba.xpages.test.seleniumdemo;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class SimpleDemo {

	private WebDriver driver;
	private String baseUrl = "";
	private StringBuffer verificationErrors = new StringBuffer();

	public void setUp() throws Exception {
		driver = new FirefoxDriver();
		driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

	public void tearDown() throws Exception {
		String verificationErrorString = verificationErrors.toString();
		if (!"".equals(verificationErrorString)) {

	public void testDemo() throws Exception {
		List elemRadio = driver.findElements(By

		Select select = new Select(driver.findElement(By
		List listSelect = select.getOptions();
		for (WebElement listElem : listSelect) {


	public void reloadPage() {

The Maven pom.xml file

<project xmlns="http://maven.apache.org/POM/4.0.0"



Dieser Beitrag wurde unter Allgemein, Java, Web, XPages abgelegt und mit , , , , , , , verschlagwortet. Setze ein Lesezeichen auf den Permalink.

3 Antworten zu Testing XPages

  1. There is still 2 things I think

    1. to record and get this kind of selector automatically
    2. When you have a view or a repeatcontrol

    There is probably some workaround for manually creating the testfiles for testing an application would probably be quite big work if you can’t record it. Also if views and repeats needs a special setup that will probably also be a problem.

  2. Hi Sven, I finally managed to install Selenium and the *%ç“* proper version of Firefox.

    Just to make sure – your pom.xml is just there to install Selenium? I installed everything manually, so I shouldn’t need it.

    In any case, this has pushed me to start proper Selenium testing of my webprojects. Thanks!

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.