GUI Testing Development

From Apache OpenOffice Wiki
< QA
Jump to: navigation, search

Write GUI test case

A simple example

You can find one simple example in the testgui project. The source code is testgui/source/testcase/gui/

package testcase.gui;
import static org.junit.Assert.*;
import static testlib.gui.AppUtil.*;
import static testlib.gui.UIMap.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import testlib.gui.CalcUtil;
import testlib.gui.Log;
 * If AOO is not installed in the default directory, please specify the system property in your command line. <br/>
 * -Dopenoffice.home="Your OpenOffice installation directory which contains soffice.bin"
public class AOOTest {
	 * Add Log to enable the following capabilities.
	 * 1. Take a screenshot when failure occurs.
	 * 2. Collect extra data when OpenOffice crashes.
	 * 3. Log any detail information.
	public Log LOG = new Log();
	 * Do some setup task before running test
	 * @throws Exception
	public void setUp() throws Exception {
		//Start OpenOffice with a clean user profile
	 * Clean task after testing
	 * @throws Exception
	public void tearDown() throws Exception {
	 * Implement test steps 
	public void testHello() {
		calc.waitForExistence(10, 3);
		assertEquals("Assert", "Hello", CalcUtil.getCellInput("A1"));


The classes under package org.openoffice.test.vcl.widgets can be used to interact with VCL controls. To construct the classes, GUI control's Help ID should be specified.

VclWindow startcenter = new VclWindow("FWK_HID_BACKINGWINDOW");;
VclButton someButton = new VclButton("SC_HID_INSWIN_CALC");;
boolean checked = someButton.getText();
VclListBox someListBox = new VclListBox("");"Item1");
String selected = someListBox.getSelText();

Generally we define GUI controls centrally in one class named testlib.gui.UIMap. The advantage is that we can easily update our scripts when GUI changes. There have been many pre-defined controls. For example:

  • app: The whole AOO application
  • startcenter: Startcenter window
  • writer: Writer window
  • calc: Calc window
  • impress: Impress window.

You can define new GUI control by add one line in the class or use one Eclipse plugin named testassistant to simplify the thing.

How to define GUI controls

Use VCL Test Assistant Eclipse Plugin
Install the plugin into your eclipse.
Open Eclipse Preferences, find the page "VCL Test Assistant" and then specify OpenOffice installation directory.
Vcl test assistant preference.png
Open "VCL Test Assistant->VCL Explorer" view.
Vcl test assistant view.png
Click Launch to start OpenOffice and then click Inspect.
Now, OpenOffice will pop up a floating windows titled "DisplayHID". Drag the gray circle to some controls and then release the button.
Inspect help id.png
Go back to VCL Explorer, you will get the Help IDs.
Help id view.png
If you want to use any control, left double click on the "Name" item of the control which you want to use, then add a name to it. Then you will find a UI control defined automatically in the last line of\test\testscript\src\testlib\ Then you can use the control by name you defined instead of using control ID. Add controls.png


testlib.gui.AppUtil inludes some methods to post keyboard/mouse event to OS.

//type shortcuts
AppUtil.typeKeys("<ctrl a><ctrl c><ctrl v>");
//Perform mouse click on screen, 200);

Add a Test Case

Personal tools