Difference between revisions of "QA/dev gui testing"

From Apache OpenOffice Wiki
< QA
Jump to: navigation, search
Line 3: Line 3:
 
[[Category: TestAutomation]]
 
[[Category: TestAutomation]]
  
 +
== JUnit 4 basics ==
  
== Write Testing Classes ==
+
== Write test class ==
 
+
=== Write GUI testing case with JUnit4 ===
+
  
 
<source lang="java">
 
<source lang="java">
Line 105: Line 104:
 
* [[QA/vclauto/A step by step example]]<br />
 
* [[QA/vclauto/A step by step example]]<br />
  
=== GUI Test Cases Writing Rules ===
+
== Best practice ==
When you want to commit test codes, you'd better verify all the codes with following rules.<br />
+
{{Template:Documentation/Caution|MUST READ THE SECTION BEFORE COMMITTING AUTOMATION CODE}}
 +
 
 +
=== Basic rules for JUnit 4 ===
 +
1. Don't us random. That makes test uncertain, hard to debug and maintain. Instead of it, prepare enough special test data to cover boundary conditions.
 +
2. Name tests properly. "testLoadFileFromServer" is better than "test".
 +
3. Clean up in @After/@AfterClass method to avoid affecting other testcases.
 +
 
 +
=== Special ruls for GUI testing ===
 
1. Every test case should have verification point.<br />
 
1. Every test case should have verification point.<br />
 
e.g. Test scenario: Inserting a table in text document.<br />
 
e.g. Test scenario: Inserting a table in text document.<br />

Revision as of 08:19, 10 August 2012


JUnit 4 basics

Write test class

package testcase;
 
import static org.junit.Assert.*;
import static testlib.AppUtil.*;
import static testl'''Bold text'''ib.UIMap.*;
 
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
 
import testlib.CalcUtil;
import testlib.Log;
 
/**
 * Before running the testing class, you need specify the AOO location firstly with system property openoffice.home.
 * 
 * @author test
 *
 */
public class SayHelloToOO {
 
	/**
	 * TestCapture helps us to do
	 * 1. Take a screenshot when failure occurs.
	 * 2. Collect extra data when OpenOffice crashes.
	 */
	@Rule
	public Log LOG = new Log();
 
 
	@Before
	public void setUp() throws Exception {
		app.start(); // make sure that OpenOffice is started before testing
	}
 
	@After
	public void tearDown() throws Exception {
		app.close(); // close OpenOffice after testing is finished avoid contaminating other test cases
	}
 
	/**
	 * Implement the case
	 */
	@Test
	public void helloOO() {
		startcenter.menuItem("File->New->Spreadsheet").select();
		calc.waitForExistence(10, 3);
		typeKeys("Hello");
		assertEquals("Assert", "Hello", CalcUtil.getCellInput("A1"));
	}
 
}

org.openoffice.test.vcl.Tester implements some methods to post keyboard/mouse event to OS.

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

The classes under package org.openoffice.test.vcl.widgets can be used to interact with VCL controls. Generally, we should specify control's Help ID to construct these classes. Then invoke other methods to perform user actions.

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();

Suggest to define UI controls centrally in testlib.UIMap. The advantage is that we can easily update our scripts when UI changes.

How to Get Help ID

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 pops 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

Add a Test Case

Best practice

Documentation caution.png MUST READ THE SECTION BEFORE COMMITTING AUTOMATION CODE

Basic rules for JUnit 4

1. Don't us random. That makes test uncertain, hard to debug and maintain. Instead of it, prepare enough special test data to cover boundary conditions. 2. Name tests properly. "testLoadFileFromServer" is better than "test". 3. Clean up in @After/@AfterClass method to avoid affecting other testcases.

Special ruls for GUI testing

1. Every test case should have verification point.
e.g. Test scenario: Inserting a table in text document.
After you inserting a table in the document, you have to verify whether the table is inserted successfully.
2. Make sure test codes are concise, readable and easy to maintain.
3. In VCLAuto, “sleep()” is usually not needed. Here is some special situation “sleep()” is needed.

  • 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.

4. Make sure test codes have no warnings.
5. When you add a new class, remember to add AOO license in front of the class.
6. Put same operations into “@Before” method to avoid codes redundant.
7. Use Ctrl+A, then Ctrl+Shift+F to format source code when you complete all the codes.
8. Test all the test codes on windows/mac/linux platforms before committing.

Personal tools