Record and Playback a Sample Plug-in Test

Basic steps in recording and playing back UI tests for the eclipse IDE:

  1. Launch recording session and record user interactions.
  2. Stop recording and save recorded test.
  3. Play back the recorded test.
  4. Slower playback (optional).

  1. Launch recording session and record user interactions
    1. Look for a tool item () that looks like the run arrow with a little console under it (should be next to external tools). From its pull-down menu, select "Record Configurations..." (in Eclipse 3.4) or "Open Record Dialog..." (in 3.3) or "Record..." (in 3.2) to open the Record launch configuration window.
      Open Record Configuration
    2. In the left navigation of the launch configuration dialog, select Eclipse Application then click New (New Config icon).
      Record Launch Configuration Dialog
    3. In the Name field, type Eclipse as the name of the launch configuration.
    4. Optionally, you can edit the Workspace Data Location to match the name of your launch configuration. Let's go ahead and change it to /runtime-Eclipse.
    5. Select the Clear check box to clear the runtime workspace before recording.
    6. Clear the Ask for confirmation before clearing check box.
    7. By default, the Program to Run is set to Run a product and Eclipse IDE is selected. Leave the default values since we are testing against the Eclipse workbench.
    8. In the Plug-ins tab, select All workspace and enabled target plug-ins. If you are using a custom Target Platform, see Customizing PDE Targets.
      Record Launch Configuration Dialog
    9. When you're ready, click Apply then click Record.

      A new instance of Eclipse is launched and the recorder control opens in your development environment.

      Recorder Controll
    10. When you're ready to start recording, click the record button (red ball) in the recorder control.

      At this point, any user interactions performed within the runtime Eclipse workbench will be recorded. As you record, recorded events are displayed in the recorder console as shown below.

      Recording control view

      For our test, let's create a new Java Project.

    11. First, if the Welcome screen is open, go ahead and close it by clicking the X on the right side of the Welcome text.
      Close Welcome Window
    12. Next, open the Java Perspective. Select Window > Open Perspective > Other...
    13. In the Open Perspective dialog, select Java and click Next.
    14. Next, select File > New > Project...
    15. In the New Project wizard, expand Java and select Java Project then click Next.
    16. In the Project name field, type SampleProject then click Finish. Do not exit Eclipse yet.

  2. Stop recording and save recorded test
    1. In the Recorder control, click Pause.
      Pause
    2. To close Eclipse, select File > Exit. The Recorder control should disappear and the New UI Test dialog appears.
      New UI Test Dialog
    3. In the New UI Test dialog, type MyProjectTest/src in the Source folder field. It is recommended that tests be placed into a project separate from the code under test.
    4. In the Package field, type my.app.tests as the name of the package.
    5. In the Name field, type CreateProject as the name of the test class.
    6. Leave the Modifiers set to public.
    7. Leave the Create folders automatically if they do not exist option checked. The test project and the source (src) folder will be created automatically
    8. Leave the Add build path dependencies automatically option checked. The build path dependencies will be automatically added.
    9. Click Finish.

      You should now have a test project and a test class created and shown in the Package Explorer. Your test script should look like the following depending on your Eclipse version:

  3. Play back the recorded test
    1. To run your test, create a Test launch configuration. In the Package Explorer view, right-click the test file, CreateProject.java, and select Run As > Run Configurations...
      Run Test
    2. In the Run Configurations dialog, double-click JUnit Plug-in Test to create a new configuration. In the Test tab, Run a single test must be selected. If the Project and Test class names are not automatically populated, you can manually type the names or use the Browse and Search buttons to locate them. For our Test runner, let's use JUnit 3.
      Run Test
    3. Click the Main tab. Since we are testing against the Eclipse IDE, the Program to Run option must be set to Eclipse (should be selected by default). Let's use the default JRE.
      Run Test
    4. When you're ready, click the Run button. Let go of the mouse and watch the tests run. The application under test, (Eclipse in this case), should be launched, and the UI tests are played back.

  4. Slower playback (optional)
  5. You can slow down the playback by enabling the playback delay preference.>