Child pages
  • ERSelenium Framework

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Screencast

http://www.wocommunity.org/podcasts/WOWODCW09-TDD.mov - 1 hour plus session on Test Driven Development with WebObjects presented by Denis Frolov on WOWODC 09. Shows how to use ERSelenium, jUnit, and Mockito with WebObjects.

Quick Start

You can also use Selenium IDE to create and edit tests:

  • Play around with test cases from ERSeleniumExample/Resources/Selenium/ using Selenium IDE.

Overview and Usage Notes

ERSelenium provides several features for effective use of SeleniumCore with WebObjects applications including:

  • Custom setup/teardown actions that can be run before/after each test.
  • Base URL independence.
  • Support of HTML and Selenese test formats (Java support is planned).
  • "On-the-fly" generation of test suites from the files in your project's source tree.
  • Bookmarkable DirectAction url to run all tests (can be used for automated testing).
  • Metacommands (special instructions specified in comments).

SeleniumCore is the powerful javascript toolkit for web applications "black-box" testing. It emulates different kinds of user actions such as: clicking the hyperlink, editing text in the input field, choosing item from the list and so on.

...

See also: Selenium

Adding the ERSelenium framework dependency to an Application

You can use ERSelenium directly from workspace:

...

add a ERSelenium test runner framework dependency to your application with Eclipse/WOLips:

  1. Add the ERSelenium.framework to your project's workspace Libraries dependency. See the tutorial: Add a Framework Dependency
  2. Enable it in the project's Properties file(Optionally. Disabled by default. Use with caution). Enable the Selenium tests direct action url in production mode via the property:
    Code Block
    SeleniumTestsEnabled=true
    
    Debug output of ERSelenium can be enabled in Properties by:
    Code Block
    log4j.logger.er.selenium = DEBUG
    

...

To run all tests point your browser to SeleniumStartTesting Direct Action:
http://baseurl/wa/SeleniumStartTesting

Example:
http://127.0.0.1localhost/cgi-bin/WebObjects/SampleProject.woa/-42421/wa/SeleniumStartTesting

To run a specific group of tests, add "/TestGroupName":

Code Block
http://baseurl/wa/SeleniumStartTesting/TestGroupName
http://127.0.0.1/cgi-bin/WebObjects/SampleProject.woa/-42421/wa/SeleniumStartTesting/registration

Some tips for writing tests for ERSelenium

  • Don't use full URLs with open/openWindow commands (http://baseurl part will be added by ERSelenium):
    Code Block
    |open|/wa/EditPerson|
    |open|/|
    
  • You can use setup/teardown methods. They should be implemented as direct actions in the separate class, which should be er.selenium.SeleniumAction-descendant. SeleniumAction class has some handy helper methods and automatically turns your selenium-related actions off when selenium is disabled in Properties. Here's the example of using selenium-related direct actions in the test (suppose that resetSessionAction() is defined in the class "Selenium"):
    Code Block
    |open|/wa/Selenium/resetSession|
    
  • You can use @repeat-@values-@done metacommands to execute specific part of the test with additional values edited in textboxes, e.g.:
    Code Block
    @repeat
        ...some actions...
        @values user1 user2 user3
        |type|user|user0|
        @values pass1 pass2 pass3
        |type|password|pass0|
        ...some more actions...
      @done
    
    The commands between @repeat and @done will be repeated several times, each time with new value in "user" and "password" input field. The values are seperated by spaces and if you have multiple @values lines, they all must have the same number of parameters. The @values section applies to the value of the next command.

...

  • Selenium IDE Firefox plugin and XPath Checker can be very handy for creating and editing Selenium tests. Selenium IDE Selenese source plugin with proper comments support resides in ERSelenium/Resources/selenese-ide-plugin.js.

Using basic flow control

ERSelenium comes with a preinstalled flowControl user-contributed extension that provides some basic flow control. You can use its commands as described in the flowControl documentation.

For example, consider a test page that displays an integer counter (in the format "Counter = n", where n is the current value of the counter), and has an "Increment" button with id="increment". The following Selenese fragment would repeatedly press the button until the counter reached 10:

Code Block

|while|!selenium.isTextPresent("Counter = 10");||
|click|increment||
|endWhile|||

Standalone runner

ERSelenium offers tests' developers several nice features - like automatic test suite generation, metacommands and URL independence. Unfortunately this leads to some troubles when trying to execute your tests with Selenium-RC. This is where StandaloneRunner can be very helpful.

...

Code Block
- test '/usr/local/wondercap2/dep/SongsterrYourApp/14662/dep/dist/SongsterrYourApp.woa/./Contents/Resources/Selenium/Commenting/LoginViaCommenting.sel' PASSED
- test '/usr/local/wondercap2/dep/SongsterrYourApp/14662/dep/dist/SongsterrYourApp.woa/./Contents/Resources/Selenium/Commenting/NotifyAboutReplies.sel' PASSED
- test '/usr/local/wondercap2/dep/SongsterrYourApp/14662/dep/dist/SongsterrYourApp.woa/./Contents/Resources/Selenium/Commenting/SignUpViaCommenting.sel' PASSED
- test '/usr/local/wondercap2/dep/SongsterrYourApp/14662/dep/dist/SongsterrYourApp.woa/./Contents/Resources/Selenium/Commenting/SuccessfulComment.sel' PASSED

...