CubicTest - Tutorial
Download CubicTest
First, go to the download page and download CubicTest. We recommend the update site version for Eclipse 3.4 Ganymede users, and the "rich client" version for users that do not have minimum Eclipse 3.4 Ganymede or Java 5 installed.
If the rich client version is used, unzip the zip file to your hard drive.
Start CubicTest
Update site version: Start Eclipse and open the CubicTest perspective (Window -> Open Perspecive -> Other... -> CubicTest)
Rich client: Double click on the "eclipse.exe" file in the folder where you unzipped CubicTest to start CubicTest.
Writing your first CubicTest test
Create a New CubicTest Project
- Right-click in the "package explorer" view (top left frame) in Eclipse, and select:
- New -> New CubicTest Project
- Follow the instructions on screen.
An empty test will appear in the Editor window with an initial, empty first page/state.
Short introduction to the CubicTest test model
- Tests in CubicTest consists of a series of pages/states and transitions between the page/states.
- Each page/state can have several page elements in them, which means that they should be asserted present on the page. Examples of page elements include text, links, text fields, buttons etc. These page elements can also be the subject of user interactions.
- Transitions take the "test user" from one page/state to the next. A transition can consist of several user interactions on page elements from the source page. Together these user interactions form the transition.
Examples of user interactions include entering text into a text field, clicking a link and "mouse over" an image. When a transition has multiple user interactions (e.g. filling out a form) only the last one (e.g. "click Submit") is assumed to trigger the transition to the next page/state.
For more info about the domain model, see the wiki item Essential Concepts in CubicTest.
Create assertions for the initial page/state
Add some page elements (e.g. links) to the first page that appears in the new test.
Page elements to assert is found in the palette on the left of the graphical test editor.
Create a user interaction
After some page elements are added to the page, create a User Interaction transition that leads from one page to another:
- *Right click on the page/state* -> choose "Add user interaction"
- Select the page element to apply user action to (in the first column, e.g. a link).
- Then select the action type (second column, e.g. "Click").
- For page elements that accept text input, the input goes into the third column.
- You can create several user inputs in the same transition by clicking the "Add new user input"-button.
- Press OK to add the transition
A new target Page/State is automatically created. Here you can add page elements (e.g. Text) to assert the presence of some result of the user interaction.
Run the test
To run this test in a web browser,
- Right click in the test editor -> Run As --> "Run CubicTest with Selenium".
This will open up a browser and run the tests. The test model in the CubicTest editor will be colored with the results. - Alternatively, right click in the test editor -> choose "Run Test with Watir Runner"
This will run the tests in Internet Explorer using Watir. Ruby and Watir must be installed, see http://wtr.rubyforge.org/install.html
TIP: Use Google Chrome for running tests, as it starts faster and looks better in multiwindow mode. Default browser for your tests can be changed in the file test-project.properties in your CubicTest project.
Recording tests
Alternatively to creating a test manually (as described above), tests can be recorded by interacting with an existing web application.
The recorder requires that Firefox or Opera is installed.
To record a test,
- Right click in the background of a Test and choose "Record" (or right click on an arbitrary Page/State and choose "Record from this Page/State")
Firefox/Opera will open and load the start point URL. - To record page element assertions, right click on the page in Firefox on "page elements" (e.g. a link) and choose e.g. "Assert link present".
To record text-present-assertions, first highlight/select the text and then right click and choose "assert text present". - To record user interactions, interact with the page as normal. The interactions will be recorded, and "click" events will trigger the transition to a new state. Text input will not automatically trigger a transition to a new state. Observe that user interactions are added to the Cubic test model in the background.
To stop recording,
- Right click in the graphical test editor -> toggle "Record" off.
Custom Test Steps
A Custom Test Step is a way to write test code for test steps that you cannot model in CubicTest with the Graphical Test Editor and elements from the palette.
Custom Test Steps let you write any code you want, and to use any libraries you want on the classpath. The code can be run and debugged using standard Eclipse mechanisms.
Initially, CubicTest Custom Test Steps only support Selenium RC but the other frameworks (HTML export, Selenium export and Watir) will follow.
To create a Custom Step and add it to a test:
- Right click on a folder in the package explorer view then "New -> New CubicTest Custom Test Step".
- Complete the wizard that opens, and the custom step editor will open.
- Drag and drop the created .custom file into a test's Graphical Test Editor, and the custom step will be added to the test.
All installed CubicTest exporters (e.g. Selenium, Watir, HTML Prototype) can provide an implementation of the Custom Test Step, such that the test and custom step can work with different frameworks.
To create a Selenium RC implementation of the custom test step:
- Open the custom test step (either open the .custom file, or double click on a Custom Step in the Graphical Test Editor).
- Press the Selenium RC link to create a custom test step class using Selenium RC. Provide a suitable name.
- After the class is created, click on the Selenium RC link again for a shortcut to open the class.
- Implement the class using Selenium RC. The Selenium RC Javadoc is attached. Check out the ICustomTestStep interface for javadoc for CustomTestStep itself.
To launch a test with a custom test step in it, you need to right click on the CubicTest and select "Run As -> Run CubicTest with Selenium". This starts up with firefox as the default browser. To change the browser please edit the launch configuration by opening the "run dialog" found in the toolbar.
Creating a test suite and running tests from the command line
When a new CubicTest Project is created, a default JUnit test named "CustomTestSuite.java" is created. Here you can launch tests using a SeleniumRunner object provided by CubicTest. The default implementation runs all tests within the "tests" folder.
The feature is called Custom Test Suite since you can use all the Java code and all libraries you want, e.g. for custom setup and teardown of tests.
The SeleniumRunner object can be configured the same way as the test runner launched from the GUI. See its JavaDoc and setter methods. It also has options for whether to keep the test browser open between tests or not.
To run the Custom Test Suite, right click on the class and select Run As --> JUnit Test.
To run it from the command line:
- Ensure that Maven 2 is installed and has minimum Java 5 as its JRE.
- Change directory to the CubicTest test project folder and type mvn test
- This will open upen up the test browser and run the test suite.
For users that want to model which files to run (and not add them with code), there is a test suite editor for specifying which tests to run. Right click on the "test suites" folder and select "New CubicTest Test Suite".
To add tests, make sure the .ats suite file is open and drag and drop test files it into the editor. The advantage of this approach is that renaming/moving of tests automatically is updated in the suite.
This .ats suite file can be lauched from the GUI or from a Custom Test Suite.
Viewing samples
The Rich Client version of CubicTest comes with sample tests. To view them in CubicTest, press File -> Import... -> Existing Projects into Workspace -> Select root directory: <CubicTest install dir>/samples/CubicShopTest -> Press OK