RapUITesting

From Eclipsepedia

Revision as of 11:59, 29 May 2007 by B.muskalla.gmx.net (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Template:Attention

| RAP wiki home | RAP project home |

Contents

Writing UI Tests for RAP applications

This document will describe one way how to do UI tests for you RAP applications. For this way, we use the combination of JUnit, Selenium and Selenium RC to have automatic UI tests which can be integrated into your JUnit testsuite.

We will provide a simple example application to demonstrate the usage of the several tools.

Requirements

If you don't have it, you need at least these files in order to follow the tutorial:

Extract these files in a directory of your choice.

Creating the sample application

First we need something to test. Therefor I put together a little example application to demonstrate the UI testing approach.

Just create a new plugin project, add org.eclipse.rap.ui.workbench as a dependency and create the following class:

package org.eclipse.rap.demo.ui.tests;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.lifecycle.IEntryPoint;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class TestApp implements IEntryPoint {

	public Display createUI() {
		Display d = new Display();
		final Shell s = new Shell(d, SWT.SHELL_TRIM);
		s.setLayout(new GridLayout());
		s.setText("App Title");
		final Button b1 = new Button(s, SWT.PUSH);
		b1.setText("Before");
		b1.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				MessageDialog.openInformation(s, "MessageBox",
						"Changing the button text now...", null);
				b1.setText("After");
			}
		});
		s.pack();
		s.open();
		return d;
	}

}

As you can see, this is a really tiny RAP example - but big enough to be worth to test it.

Preparing the tests

Now create a new java project and add the JUnit library. Additionally, you need to add the selenium-java-client-driver.jar to your project in order to use the Selenium Remote Control.

As we


Creating the test cases

Running the Selenium RC server

The Selenium RC server is a little server written in Java which cares about the interaction between your Junit tests and the browser instances. As it offers some webservices for us, we need to start it before running our tests.

Test it!