This topic explains how to generate JUnit tests that represent the actions recorded in a web browser.
Sections include:
SOAtest can generate JUnit tests that represent a new or previously-recorded web scenario. You can set up a functional test against a Web application, then use the generated JUnit test cases to validate test results using the JUnit framework. This gives you the flexibility of a test script and the easy-to-use interface of SOAtest—without having to learn a new test scripting language.
The resulting class files are JUnit based and depend on the following jar files.
From <Parasoft Test install dir>/plugins/com.parasoft.xtest.libs_<version>:
From <Parasoft Test install dir>/plugins/com.parasoft.xtest.libs_<version>/Parasoft:
From <Parasoft Test install dir>/plugins/com.parasoft.xtest.libs.base_<version>:
From <Parasoft Test install dir>/plugins/com.parasoft.xtest.libs.base_<version>/Parasoft:
From <Parasoft SOAtest install dir>/eclipse/plugins/com.parasoft.xtest.libs.web_<version>/root/lib-java-mod:
From <Parasoft SOAtest install dir>/eclipse/plugins/com.parasoft.xtest.libs.web_<version>/root:
From <Parasoft SOAtest install dir>/eclipse/plugins/com.parasoft.xtest.license.eclipse.core.web_<version>/lib:
Before you start generating JUnit tests, perform this one-time configuration:
MyJUnitTest
.To generate JUnit tests from a scenario as you record it:
Start Recording From: Enter the URL of the site on which you would like to perform functional testing.
To record applications that "live" on the same machine as SOAtest, do not use localhost. Instead, use the machine name (e.g., mymachine.parasoft.com) or the IP address (e.g., 10.10.11.11). |
MyJUnit
).MyConvertedUnitTests
. ${project_loc:MyJUnitTest}/src
.Specify the functionality that you want to capture by following it in the browser(s). You can click links, complete and submit forms, use the navigation bar to enter open URLs, access shortcuts, go forward or back, and so on.
To ensure that recording works properly, you must wait until the page has fully loaded before performing some action. You must wait each time the page or some part of the page gets reloaded before performing an action. |
To complete forms, enter the values directly into the GUI controls as if you were actually navigating the site. For instance, type in your user name and password, select radio buttons, check or clear check boxes, and so on. As you record sessions, please note:
|
6. Close the browser window(s).
A JUnit test class will be added to the specified output location. A new project will not be created or added to the Test Case Explorer.
To generate JUnit tests that represent a previously-recorded test scenario:
MyJUnit
for the class nameMyConvertedUnitTests
.${project_loc:MyJUnitTest}/src
.Many users find it convenient to put all tests into the same project. However, you may create multiple projects if you prefer. |
To execute the generated tests:
You can also execute these tests from the command line as described in the JUnit documentation.
License information is required to run JUnit tests generated by SOAtest. The license information can be set in two ways:
<SOAtest install root>/plugins/com.parasoft.xtest.libs.web_<version>/root/
.If you want to run the tests from a machine that does not have a local installation of SOAtest—or if you want to use a different license information than one being used for the local SOAtest installation—you can control the licensing information without having to open SOAtest and modify the preferences from the UI. To do this, you pass the license information using the following constructor:
WebBrowser( String installRoot, int browserType, String ffExePath, String licenseServerLocation, int licenseServerPort, int licenseServerTimeout ) |
Each JUnit class generated by SOAtest consists of one test function that mimics the test sequence of a SOAtest test. Whenever the server returns a response, the test will make an assignment to the Response object declared within the test function. You should insert assertion statements after these assignments to validate that the response from the server is expected.
We have created comment blocks where we recommend assertion placements within the test function.
For example:
public void testA() throws Exception { WebConversation wc = new WebConversation(); WebRequest req = new GetMethodWebRequest("http://mole/tests/"); WebResponse resp = wc.getResponse(req); //Begin assertions //End assertions WebLink link = resp.getLinkWith("popup.html"); link.click(); resp = wc.getCurrentPage(); //Begin assertions //End assertions WebForm form = resp.getFormWithName("childrenForm"); resp = form.submit(); //Begin assertions //End assertions } |
In the above JUnit test function, the blocks appear each time that the WebResponse object was assigned with a new value.