Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "SWTBot/Generator"

(Extending it)
m (typo fixing)
Line 80: Line 80:
 
This is useful to start the recorder from menus, buttons or anything. Just make sure the bundle you're developing depends on '''org.eclipse.swtbot.generator''' and when relevent, invoke the following code to open the recorder Window:
 
This is useful to start the recorder from menus, buttons or anything. Just make sure the bundle you're developing depends on '''org.eclipse.swtbot.generator''' and when relevent, invoke the following code to open the recorder Window:
 
<source lang="java">
 
<source lang="java">
org.eclipse.swtbot.generator.ui.StartpRecoder.openRecorder()
+
org.eclipse.swtbot.generator.ui.StartupRecorder.openRecorder();
 
</source>
 
</source>
  

Revision as of 05:22, 1 September 2013


SWTBot
Website
Update Sites
Community
Mailing List
Forums/Newsgroups
IRC
Contribute
Open Bugzilla tickets
Open Gerrit reviews
Browse Source
Continuous Integration


Purpose and limitations

What it does

The test generator can be enabled on any Eclipse-based application at runtime. It monitors at UI events as they are performed by user and the generate some pieces of code that can be reused later in automated tests to playback user actions.

Limitations

Some conceptual limitations of UI recorders (which are true for SWTBot Generator, but also for Selenium or other recorder/playback engines):

  • There are several ways to identify a widget, the recorder will choose only one, that may not be the best
  • The recorder understand "atomic" UI operation, which may be too fined-grained compared to what you want to test
  • The generator is not aware of your code style and tastes, so it may generate code that is not conform to your standards
  • The generator doesn't know what to check, it's just a bot: it's your role to add assertions and other checks

All those points mean that the generation of code is only something that makes you save time by replacing some code writting, but the generated code always needs to be reviewed and enriched with assertions and probably improved.

A limitation that is specific to this recorder and Eclipse is that it does not (yet) support GEF.

How to get the maximal benefit from it

Speed up the process of creating a test: instead of writing directly code, start by running your test scenario with the generator enabled. You'll get a huge part of your code already written down, ready to go into a TestCase. Then improve that code is necessary and add your assertions and checks.

Ask users to provide their scenarios as code: If possible, when a user has a bug, ask him to start the recorder (you could embed its enablement in a higher-level menu - Help > Record usage scenario -to prevent end-users from doing complex operations); and ask your users to post the generated code. It will reduce the gap between users reports and unit tests.

Screencast

Here is a screencast presenting SWTBot Recorder and Generator: https://vimeo.com/55953990

Installation

The Test recorder and generator is a single plugin to install in any RCP application (may it be your Eclipse IDE, or a bundled RCP application. You can get it from the SWTBot update-site/p2 repository (starting from version 2.0.6).

With p2 UI: TODO screenshot of installation

With p2 director, install bundle org.eclipse.swtbot.generator:

java -jar plugins/org.eclipse.equinox.laucher_*.jar -application org.eclipse.equinox.p2.director -repository <choose_a_SWTBot_p2_repo> -installIU org.eclipse.swtbot.generator

Enablement

At startup for a Run Configuration from IDE

Ensure the org.eclipse.swtbot.generator bundle is part of your Lauch Configuration TODO: screenshot

Set the -Dorg.eclipse.swtbot.generator.enable=true system property TODO: screenshot

At startup for a RCP app

Ensure org.eclipse.swtbot.generator bundle is installed in your application (use ls or OSGi console at runtime to check that).

Set the -Dorg.eclipse.swtbot.generator.enable=true system property in your config.ini. Example for JBoss Developer Studio, in jbdevstudio/studio/jbdevstudio.ini, line 17:

  1. -vm
  2. /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
  3. -startup
  4. plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
  5. --launcher.library
  6. plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.200.v20120522-1813
  7. -product
  8. com.jboss.jbds.product.product
  9. -showsplash
  10. platform\:/base/plugins/com.jboss.jbds.product
  11. --launcher.XXMaxPermSize
  12. 256m
  13. --launcher.defaultAction
  14. openFile
  15. -vmargs
  16. -Djboss.discovery.directory.url=https://devstudio.jboss.com/updates/6.0/devstudio-directory.xml
  17. -Dorg.eclipse.swtbot.generator.enable=true
  18. -Xms512m
  19. -Xmx1024m
  20. -Dosgi.instance.area.default=@user.home/workspace

Programmatically from a plugin

This is useful to start the recorder from menus, buttons or anything. Just make sure the bundle you're developing depends on org.eclipse.swtbot.generator and when relevent, invoke the following code to open the recorder Window:

org.eclipse.swtbot.generator.ui.StartupRecorder.openRecorder();

Usage

The generator window generates code, copy-paste it where you want

Extending it

Rules mechanism

The recorder places some SWT listeners that look at events and generate code from each event. A Generator support is just a set of "rules" that are classes that process (or not) the current event to generate some code. Processing an event is divided in 2 pieces:

  1. Create an accessor for the widget (eg: bot.button("blah")
  2. create an action on the widget (eg: .click())

There are 2 kinds of rules:

Those rules are easy to test with JUnit and SWTBot.

Adding and contributing a rule

Recommended way to create and contribute a rule is:

  1. Set up environment as described in the 2 first paragraph of contribution guide : set up target-platform and get source for org.eclipse.swtbot.generator and org.eclipse.swtbot.generator.test in IDE
  2. Write a test for your rule. Use the RecordComboTest as example. Run tests, ensure it's failing.
  3. Write a rule for the event(s) you're trying to support. Add this rule to the SWTBotGenerationRules.
  4. Run your tests and ensure it's now green.
  5. Contribute test and rule to SWTBot as a Gerrit patch.

Contribute your own Bot support

There is an extension point for that in org.eclipse.swtbot.generator. We recommend you to get the source for the org.eclipse.swtbot.generator plugin and see what's in it. The default SWTBot support is installed as an extension too, so you can take it as an example.

Contributing

The contributions tools and process are the same as for any SWTBot part. See SWTBot/Contributing.

Back to the top