Difference between revisions of "QA/dev gui testing"

From Apache OpenOffice Wiki
< QA
Jump to: navigation, search
(Basic rules for JUnit 4)
m (How to define GUI controls)
 
(4 intermediate revisions by 3 users not shown)
Line 3: Line 3:
 
[[Category: TestAutomation]]
 
[[Category: TestAutomation]]
  
== JUnit 4 basics ==
+
= Write GUI test case =
[http://junit.sourceforge.net/doc/cookbook/cookbook.htm Here] is a short cookbook showing how to use JUnit 4. If you know Java, it's very easy for you to understand it.
+
== A simple example ==
 
+
== 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/AOOTest.java.
 
You can find one simple example in the testgui project. The source code is testgui/source/testcase/gui/AOOTest.java.
  
<source lang="java">
+
<syntaxhighlight lang="java">
 
package testcase.gui;
 
package testcase.gui;
  
Line 73: Line 70:
  
 
}
 
}
</source>
+
</syntaxhighlight>
  
 
=== testlib.gui.UIMap ===
 
=== testlib.gui.UIMap ===
 
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.  
 
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.  
<source lang="java">
+
<syntaxhighlight lang="java">
 
VclWindow startcenter = new VclWindow("FWK_HID_BACKINGWINDOW");
 
VclWindow startcenter = new VclWindow("FWK_HID_BACKINGWINDOW");
 
startcenter.click();
 
startcenter.click();
Line 86: Line 83:
 
someListBox.select("Item1");
 
someListBox.select("Item1");
 
String selected = someListBox.getSelText();
 
String selected = someListBox.getSelText();
</source>
+
</syntaxhighlight>
  
 
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:
 
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:
Line 103: Line 100:
 
[[File:vcl_test_assistant_preference.png]]<br />
 
[[File:vcl_test_assistant_preference.png]]<br />
 
Open "VCL Test Assistant->VCL Explorer" view.<br />
 
Open "VCL Test Assistant->VCL Explorer" view.<br />
[[File:vcl_test_assistant_view.png]]<br />
+
[[File:vcl_test_assistant_view.png|800px]]<br />
 
Click Launch to start OpenOffice and then click Inspect. <br />
 
Click Launch to start OpenOffice and then click Inspect. <br />
Now, OpenOffice will pops up a floating windows titled "DisplayHID". Drag the gray circle to some controls and then release the button. <br />
+
Now, OpenOffice will pop up a floating windows titled "DisplayHID". Drag the gray circle to some controls and then release the button.<br />
[[File:inspect_help_id.png]]<br />
+
[[File:inspect_help_id.png|800px]]<br />
 
Go back to VCL Explorer, you will get the Help IDs.<br />
 
Go back to VCL Explorer, you will get the Help IDs.<br />
[[File:help_id_view.png]]<br />
+
[[File:help_id_view.png|800px]]<br />
 
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 UIMap.java.(%EclipseWorkspaceDir%\test\testscript\src\testlib\UIMap.java). Then you can use the control by name you defined instead of using control ID.
 
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 UIMap.java.(%EclipseWorkspaceDir%\test\testscript\src\testlib\UIMap.java). Then you can use the control by name you defined instead of using control ID.
[[File:Add_controls.png]]<br />
+
[[File:Add_controls.png|800px]]<br />
  
 
=== testlib.gui.AppUtil ===
 
=== testlib.gui.AppUtil ===
 
testlib.gui.AppUtil inludes some methods to post keyboard/mouse event to OS.  
 
testlib.gui.AppUtil inludes some methods to post keyboard/mouse event to OS.  
<source lang="java">
+
<syntaxhighlight lang="java">
 
AppUtil.typeKeys("AB<enter>");
 
AppUtil.typeKeys("AB<enter>");
 
//type shortcuts
 
//type shortcuts
Line 120: Line 117:
 
//Perform mouse click on screen
 
//Perform mouse click on screen
 
AppUtil.click(200, 200);
 
AppUtil.click(200, 200);
</source>
+
</syntaxhighlight>
  
=== Add a Test Case ===
+
== Add a Test Case ==
 
* [[QA/vclauto/A step by step example]]<br />
 
* [[QA/vclauto/A step by step example]]<br />
 
== Best practice ==
 
{{Template:Documentation/Caution|MUST READ THE SECTION BEFORE COMMITTING AUTOMATION CODE}}
 
 
=== Special ruls for GUI testing ===
 
1. Every test case should have verification point.<br />
 
e.g. Test scenario: Inserting a table in text document.<br />
 
After you inserting a table in the document, you have to verify whether the table is inserted successfully.<br />
 
2. Make sure test codes are concise, readable and easy to maintain.<br />
 
3. In VCLAuto, “sleep()” is usually not needed. Here is some special situation “sleep()” is needed.<br />
 
* Open a file. If you want to do some operations based on a sample file or a new created file. “sleep()” is needed to wait for the file opened successfully.<br />
 
4. Make sure test codes have no warnings.<br />
 
5. When you add a new class, remember to add AOO license in front of the class.<br />
 
6. Put same operations into “@Before” method to avoid codes redundant.<br />
 
7. Use Ctrl+A, then Ctrl+Shift+F to format source code when you complete all the codes.<br />
 
8. Test all the test codes on windows/mac/linux platforms before committing.<br />
 

Latest revision as of 17:11, 25 October 2021


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/AOOTest.java.

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.
	 */
	@Rule
	public Log LOG = new Log();
 
 
	/**
	 * Do some setup task before running test
	 * @throws Exception
	 */
	@Before
	public void setUp() throws Exception {
		//Start OpenOffice with a clean user profile
		app.start(true); 
	}
 
	/**
	 * Clean task after testing
	 * @throws Exception
	 */
	@After
	public void tearDown() throws Exception {
 
	}
 
	/**
	 * Implement test steps 
	 */
	@Test
	public void testHello() {
		startcenter.menuItem("File->New->Spreadsheet").select();
		calc.waitForExistence(10, 3);
		typeKeys("Hello");
		assertEquals("Assert", "Hello", CalcUtil.getCellInput("A1"));
	}
 
}

testlib.gui.UIMap

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");
startcenter.click();
VclButton someButton = new VclButton("SC_HID_INSWIN_CALC");
someButton.click();
boolean checked = someButton.getText();
VclListBox someListBox = new VclListBox("some.listbox.id");
someListBox.select("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.
File:Testassistant.zip
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 UIMap.java.(%EclipseWorkspaceDir%\test\testscript\src\testlib\UIMap.java). Then you can use the control by name you defined instead of using control ID. Add controls.png

testlib.gui.AppUtil

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

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

Add a Test Case

Personal tools