Difference between revisions of "QA/test automation guide"

From Apache OpenOffice Wiki
< QA
Jump to: navigation, search
(Code)
m
 
(102 intermediate revisions by 5 users not shown)
Line 1: Line 1:
== VCL Test==
+
{{DISPLAYTITLE: Getting Started with Test Automation}}
 +
[[Category: Quality Assurance]]
 +
[[Category: TestAutomation]]
 +
 
  
 
== Introduction ==
 
== Introduction ==
  
VCLAuto is a Java library for OpenOffice UI/functional testing like [[VCLTesttool]].  
+
Two kind of approaches is supported by Apache OpenOffice.
VCLAuto can be used with JUnit. The project is under developing and will be released in Apache OpenOffice 4.0.
+
*GUI Testing: Simulating a common user to perform testing. It depends on a Java library named VCLAuto, which does testing like the old [[VCLTesttool]]. It can easily integrates with JUnit. VCLAuto provides APIs to generate user interface events such as keystrokes and mouse clicks, do GUI actions and get information from the GUI to validate functions.
 +
*UNO API Testing:  Use UNO API to verify functions.
  
'''There are a lot of testing codes in the OO project, e.g. unit test, qadevooo and smoketestoo_native. Why do we need the library?'''
+
== Notice ==
 +
There are some reasons for test failures, so please [[QA/test_env|prepare your testing machine]] before running test.
  
Generally, unit test code (pure junit/cppunit test) is executed in the build process before OO is created. It's low-level and used to verify if the source code is right before they are linked to a real product. It's a white-box testing. If you want to verify a function/method/interface is correct, put your test code in unit test.
+
== Getting the source code ==
qadevooo & smoketestoo_native uses UNO API/Macro to perform testing. To run them, a real OO product must be available. It's middle-level and used to verify if UNO api and business model work correctly. It's a gray-box testing. User interaction is not involved in this testing. It can't fully simulate a user behavior or check if GUI is correct. For example, check if user can draw a shape by dragging, check if OO automatically capitalize the first letter after typing a word, check if a button's checked when user change the selection, etc.
+
Anyone can checkout source code from our Subversion repository. Run the following command.
Vclauto is high-level black-box testing. It performs testing more like a real user.  It generates keyboard/mouse events, does GUI actions  and gets information from the GUI to validate the function.
+
<source lang="bash">
 +
svn co https://svn.apache.org/repos/asf/openoffice/trunk/test/ test
 +
</source>
 +
If you are not familiar with Subversion, see our [https://openoffice.apache.org/svn-basics.html Subversion Basics] for more information.
  
'''Background'''
+
== Getting started with Eclipse ==
 +
=== Prerequisites ===
 +
*Eclipse Java IDE: [https://www.eclipse.org/downloads/packages/ Eclipse Juno(4.2) IDE for Java Developers] or above.<br />
 +
*Apache OpenOffice
  
Actually VCLAuto is a java version of  [[VCLTesttool]], which connects to the automation server (automation module) in OpenOffice with socket. With the "-enableautomation" argument, OpenOffice will start the server with listening on the port 12479 be default.
+
=== Setup project ===
[[VCLTesttool]] is heavily used by the QA team in SUN/Oracle, but many people doesn't like it because of its drawbacks.  
+
'''Step 1.''' Open Eclipse, click menu "File->Import…", and then select "General->Existing Projects into Workspace".<br />
*The poor IDE.  (Java has many enough powerful IDEs to make writing code easily, e.g. Eclipse / Netbeans)
+
[[File:test_automation_guide_1.png]]<br />
*Hard to debug.  
+
'''Step 2.''' Click next, set "Select root directory" to the source code directory, and then check the following projects.<br />
*Hard to read the code and analyze the testing result. (A lot of code is written in Non-English. Maybe German)
+
'''testcommon''': The project includes the common test utilities and low-level implementation to do GUI testing
*Too many errors
+
'''testgui''':  The project includes the GUI testing scripts.  
*Basic language is not popular.
+
'''testuno''':  The project includes the UNO API testing scripts.
 +
[[File:test_automation_guide_2.png]]<br />
 +
'''Step 3.''' Click "Finish" to import the projects.
  
I found [[Test_Cleanup]] project starts to unify all testing code to follow the standard xUnit style, so I think it's time to clean up GUI test as well.
+
'''Step 4.''' Click menu "Window->Preferences" ("Eclipse->Preferences" on Mac) and then select "Java->Build Path->Classpath Variables" page.<br />
 +
[[File:test_automation_guide_10.png]]<br />
 +
Click "New" to create one new variable "'''openoffice.home'''", and set its value to Apache OpenOffice installation directory.<br />
 +
[[File:test_automation_guide_11.png]]<br />
 +
{{Note| '''The default installation directory of Apache OpenOffice'''<br />
 +
Mac OS X: "''/Applications/OpenOffice.app/Contents"''<br />
 +
Linux: "''/opt/openoffice3''"<br />
 +
Windows: "''C:/Program Files/OpenOffice 3''"<br />
 +
Windows 64b: "''C:/Program Files (x86)/OpenOffice 3''"
 +
}}
 +
Click "OK" to close "New Variable Entry"dialog. Then click "OK" button of preferences dialog. A message box pops up. Click "Yes".<br />
 +
[[File:test_automation_guide_12.png]]<br />
  
== Getting Started with Eclipse ==
+
=== Run testing ===
 +
'''Step 1.''' Select one test class. e.g. testcase.gui.AOOTest, and then click "Run" on the toolbar to start testing. <br />
 +
[[File:test_automation_guide_13.png]]<br />
 +
When testing is finished, JUnit view will show the result.<br />
 +
[[File:test_automation_guide_14.png]]<br />
 +
You also can select one package, click "Run", and then choose "JUnit test" to run all test classes under it.
  
=== Setup Project ===
+
== Getting started with command line ==
  
1. Import the following projects into eclipse workspace.
+
=== Prerequisites ===
 +
*JDK: [http://java.sun.com/j2se/1.5/ JDK 1.5], [http://java.sun.com/javase/6/ JDK 1.6] or above.<br />
 +
*Ant: [http://ant.apache.org/bindownload.cgi Apache Ant 1.8.2] or above.
 +
*JUnit: [https://github.com/KentBeck/junit/downloads JUnit 4.10] or above. For lazy people, if internet is available, it can be automatically installed during testing.
  
'''{AOO_SOURCE_ROOT}/testcommon'''           
+
=== Run testing  ===
The project contains the common test utilities and low-level implementation to do GUI testing
+
'''As a developer, how to run testing against an OpenOffice built by me?''' <br />
 
+
It's easy for developers to run testing after building OpenOffice. One thing you need to do is to make sure you run the commands in the build environment. The script will automatically install your build and then start testing. e.g.
'''{AOO_SOURCE_ROOT}/testscript'''                 
+
The project contains the GUI testing scripts. Test case should be written in this project.
+
 
+
2. Open "testscript/build.xml", Run the ant target "prepare.dependencies" to get all required jars. Make sure you can access to internet. Otherwise, you need manually download junit.jar (MUST be 4.10+) into "testscript/output/lib/junit.jar"
+
 
+
3. Refresh the test project
+
 
+
== Run Testing ==
+
 
+
=== Run Testing in Eclipse ===
+
1.Select a test class. e.g. testcase.SayHelloToOO
+
 
+
2.Right click the SayHelloToOO and select Run As->JUnit Test. Create a JUnit configuration for the test class.
+
 
+
3.Select Argument tab and add -Dopenoffice.home="C:\Program Files\OpenOffice.org 3\program"  into VM arguments.
+
 
+
4.Click Run to start testing
+
 
+
=== Run Testing in Terminal ===
+
Firstly make sure Apache Ant 1.8.2+ installed. In the terminal, run command "ant -version" to verify the version.
+
 
+
'''How do I run testing on my OpenOffice?'''
+
 
<source lang="bash">
 
<source lang="bash">
cd testscript
+
cd main
ant -Dtest.classes="[Your_Test_Classes]" -Dopenoffice.home="[Your_OpenOffice_Location]"
+
source MacOSXX86Env.Set.sh
 +
cd ../test && ant
 
</source>
 
</source>
  
'''How do I run build verification testing after building AOO from source code?'''
+
'''As a normal user, how to run testing against an installed OpenOffice?'''<br />
 +
Firstly compile the project with the command under test module.
 
<source lang="bash">
 
<source lang="bash">
source LinuxX86Env.Set.sh
+
ant -Dopenoffice.home="OpenOffice installation directory" compile
cd testscript && ant
+
 
</source>
 
</source>
 +
Then start testing with the command "run".
 +
e.g. Run all test classes under package bvt ("Build Verification Testing")
 +
<source lang="bash">
 +
run -Dopenoffice.home="/Applications/OpenOffice.app/Contents" -tp bvt
 +
</source>
 +
e.g. Run the given test classes
 +
<source lang="bash">
 +
run -Dopenoffice.home="/Applications/OpenOffice.app/Contents" -tc bvt.gui.BasicFunctionTest
 +
</source>
 +
On Linux use e.g. -Dopenoffice.home="/opt/openoffice4/program" instead.
  
  
''' Where to get the testing result? '''  
+
''' Where to get the testing result? '''
By default, the testing result is stored in "testscript/../testspace/output". 
+
[[File:vclautoreport.png]]
+
  
 +
By default, the testing output is stored in "test/testspace/output***". Open "test/testspace/output/result.html" in your browser to see the testing report.<br />
 +
[[File:test_automation_report.png]]<br />
  
== Write Testing Classes ==
+
Special stuff in the output directory.
Write UI testing case following JUnit 4 style like the following:
+
result.xml: Test result in HTML.
 +
result.html: Test result in XML.
 +
screenshot/: Screenshot pictures when test assert is failed.
  
 
+
== Next ==
<source lang="java">
+
Now, all things have been ready for developing new test code. If you are interested, please read [[QA/dev_gui_testing|GUI Testing Development]] and [[QA/dev_api_testing|UNO API Testing Development]] to get more information.
public class UITest {
+
 
+
  @Before
+
  public void setUp() throws Exception() {
+
    initApp();
+
  }
+
 
+
  @Test
+
  public void test() throws Exception() {
+
    // Create a new text document via main menu
+
    startcenter.menuItem("File->New->Text Document").select();
+
    typeKeys("Hello OpenOffice");
+
    writer.menuItem("Edit->Select All").select();
+
    // Copy the text
+
    typeKeys("<$copy>");
+
    assert("Text is inputted successfully.", "Hello OpenOffice", App.getClipboard());
+
  }
+
 
+
  @After
+
  public void tearDown() throws Exception() {
+
 
+
  }
+
 
+
}
+
 
+
</source>
+
 
+
The library mainly implements a bunch of vcl control proxies to perform actions on and retrieve information from OpenOffice. e.g.
+
<source lang="java">
+
VclControl startcenter = new VclControl("startcenter.id");
+
startcenter.click();
+
VclButton someButton = new VclButton("some.button.id");
+
someButton.click();
+
boolean checked = someButton.getText();
+
VclListBox someListBox = new VclListBox("some.listbox.id");
+
someListBox.select("Item1");
+
String selected = someListBox.getSelText();
+
</source>
+
Methods to post keyboard/mouse event to OS.  
+
<source lang="java">
+
typeKeys("AB<enter>");
+
//type shortcuts
+
typeKeys("<ctrl a><ctrl c><ctrl v>");
+
//Perform mouse click on screen
+
click(200, 200);
+
</source>
+

Latest revision as of 15:56, 14 September 2021


Introduction

Two kind of approaches is supported by Apache OpenOffice.

  • GUI Testing: Simulating a common user to perform testing. It depends on a Java library named VCLAuto, which does testing like the old VCLTesttool. It can easily integrates with JUnit. VCLAuto provides APIs to generate user interface events such as keystrokes and mouse clicks, do GUI actions and get information from the GUI to validate functions.
  • UNO API Testing: Use UNO API to verify functions.

Notice

There are some reasons for test failures, so please prepare your testing machine before running test.

Getting the source code

Anyone can checkout source code from our Subversion repository. Run the following command.

svn co https://svn.apache.org/repos/asf/openoffice/trunk/test/ test

If you are not familiar with Subversion, see our Subversion Basics for more information.

Getting started with Eclipse

Prerequisites

Setup project

Step 1. Open Eclipse, click menu "File->Import…", and then select "General->Existing Projects into Workspace".
Test automation guide 1.png
Step 2. Click next, set "Select root directory" to the source code directory, and then check the following projects.

testcommon: The project includes the common test utilities and low-level implementation to do GUI testing
testgui:  The project includes the GUI testing scripts. 
testuno:  The project includes the UNO API testing scripts.

Test automation guide 2.png
Step 3. Click "Finish" to import the projects.

Step 4. Click menu "Window->Preferences" ("Eclipse->Preferences" on Mac) and then select "Java->Build Path->Classpath Variables" page.
Test automation guide 10.png
Click "New" to create one new variable "openoffice.home", and set its value to Apache OpenOffice installation directory.
Test automation guide 11.png

Documentation note.png The default installation directory of Apache OpenOffice
Mac OS X: "/Applications/OpenOffice.app/Contents"
Linux: "/opt/openoffice3"
Windows: "C:/Program Files/OpenOffice 3"
Windows 64b: "C:/Program Files (x86)/OpenOffice 3"

Click "OK" to close "New Variable Entry"dialog. Then click "OK" button of preferences dialog. A message box pops up. Click "Yes".
Test automation guide 12.png

Run testing

Step 1. Select one test class. e.g. testcase.gui.AOOTest, and then click "Run" on the toolbar to start testing.
Test automation guide 13.png
When testing is finished, JUnit view will show the result.
Test automation guide 14.png
You also can select one package, click "Run", and then choose "JUnit test" to run all test classes under it.

Getting started with command line

Prerequisites

Run testing

As a developer, how to run testing against an OpenOffice built by me?
It's easy for developers to run testing after building OpenOffice. One thing you need to do is to make sure you run the commands in the build environment. The script will automatically install your build and then start testing. e.g.

cd main
source MacOSXX86Env.Set.sh
cd ../test && ant

As a normal user, how to run testing against an installed OpenOffice?
Firstly compile the project with the command under test module.

ant -Dopenoffice.home="OpenOffice installation directory" compile

Then start testing with the command "run". e.g. Run all test classes under package bvt ("Build Verification Testing")

run -Dopenoffice.home="/Applications/OpenOffice.app/Contents" -tp bvt

e.g. Run the given test classes

run -Dopenoffice.home="/Applications/OpenOffice.app/Contents" -tc bvt.gui.BasicFunctionTest

On Linux use e.g. -Dopenoffice.home="/opt/openoffice4/program" instead.


Where to get the testing result?

By default, the testing output is stored in "test/testspace/output***". Open "test/testspace/output/result.html" in your browser to see the testing report.
File:Test automation report.png

Special stuff in the output directory.

result.xml: Test result in HTML. 
result.html: Test result in XML.
screenshot/: Screenshot pictures when test assert is failed.

Next

Now, all things have been ready for developing new test code. If you are interested, please read GUI Testing Development and UNO API Testing Development to get more information.

Personal tools