RCP Robot Example: Create a Java Project in the SDK
The first example for
RCP Robot is a test for the Eclipse SDK. The test creates a few projects using the New Plug-in Project Wizard and then checks if the projects are actually there.
If you are interested in FIT, have a look at the non-GUI example first:
CreateJavaProjectFITTest.
Download
Importing
The zip file needs to be
imported to your workspace.
The imported project looks like this, together with the prerequisites.
Let's have a look around. First, the test waits for the window to open. The title bar of the Eclipse will contain the text "Java - Eclipse SDK".
public void testCreateProject
() throws Exception {
rcpRobot.
waitForShellShowing("Java - Eclipse SDK");
createProject
("Example1");
createProject
("Example2");
createProject
("Example3");
}
Then we call a helper method to create the plug-in projects.
private void createProject
(String projectName
) {
rcpRobot.
enterKeyCombination("Ctrl+n");
rcpRobot.
waitForShellShowing("New");
rcpRobot.
delay(500);
rcpRobot.
enterString("plug");
rcpRobot.
delay(500);
rcpRobot.
enterSpecialKey("Enter");
rcpRobot.
enterSpecialKey("Enter");
rcpRobot.
enterString(projectName
);
// flip to next wizard page
rcpRobot.
enterKeyCombination("Alt+n");
rcpRobot.
delay(500);
rcpRobot.
enterKeyCombination("Alt+F");
rcpRobot.
enterSpecialKey("Enter");
//wait to open the plug-in editor
rcpRobot.
delay(2000);
}
The robots drives the Eclipse GUI using the keyboard. Ctrl+n opens the New Project Wizard. We wait for the wizard to open. It's title bar contains just "New". Then we enter "plug" to filter the wizards. We want the Plug-in Project Wizard. We hit enter twice and reach the next wizrad page. We let the robot enter the project name. With Alt+n we move to the next wizard page. With Alt+F we finish the wizard. The project has been created an you can observe this in the Package Explorer while the test is running.
The robot has no eyes but needs to check this as well. The following method asserts that a node "Example1" exists in the "Package Explorer".
public void testProjectNames() {
rcpRobot.assertNodeExistsInView("Package Explorer", "Example1");
rcpRobot.assertNodeExistsInView("Package Explorer", "Example2");
rcpRobot.assertNodeExistsInView("Package Explorer", "Example3");
}
Running the example
The example includes a launch configuration called CreateJavaProjectRobotJUnitTest. Use this launch config to start a second instance of the Eclipse SDK.
You will see a second Workbench. The robot creates mouse and keyboard events. Keep the second Eclipse on top, don't change the focus! Hands off mouse and keybord while the test runs.
After the last test, the second Eclipse SDK will close and in the hosting SDK you will see the JUnit view showing a green bar.
There are 911 comments on this page. [Display comments]