Wiki source code of ERSelenium Framework

Version 41.1 by Pascal Robert on 2012/07/19 21:10

Show last authors
1 = Screencast =
2
3 [[http:~~/~~/www.wocommunity.org/podcasts/WOWODCW09-TDD.mov>>url:http://www.wocommunity.org/podcasts/WOWODCW09-TDD.mov||shape="rect"]] - 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.
4
5 = Quick Start =
6
7 * Checkout the Project Wonder - the ERSelenium is in the Wonder/Frameworks/Misc folder.
8 * Examine test cases from Wonder/Examples/Misc/ERSeleniumExample/Resources/Selenium/main/ and from [[BugTracker>>url:http://wiki.objectstyle.org/confluence/display/WONDER/Getting+Started+with+BugTracker||shape="rect"]] in Eclipse text editor.
9 * Launch ERSeleniumExample and point your browser to SeleniumStartTesting Direct Action url (e.g. [[http:~~/~~/localhost/cgi-bin/WebObjects/ERSeleniumExample.woa/-42422/wa/SeleniumStartTesting>>url:http://localhost/cgi-bin/WebObjects/ERSeleniumExample.woa/-42422/wa/SeleniumStartTesting||shape="rect"]]).
10 * or Launch BugTracker and point your browser to SeleniumStartTesting Direct Action url (e.g. [[http:~~/~~/localhost/cgi-bin/WebObjects/BugTracker.woa/-42422/wa/SeleniumStartTesting>>url:http://localhost/cgi-bin/WebObjects/BugTracker.woa/-42422/wa/SeleniumStartTesting||shape="rect"]]).
11
12 You can also use Selenium IDE to create and edit tests:
13
14 * Launch FireFox and install [[Selenium IDE Firefox plugin>>url:https://addons.mozilla.org/en-US/firefox/addon/2079/||shape="rect"]].
15 * Using [[Selenium IDE format plugin installation instructions>>url:http://wiki.openqa.org/display/SIDE/Contributed+Extensions+and+Formats||shape="rect"]] install Selenese-ide-plugin.js (it is in ERSelenium/Resources).
16
17 {{tip title="Opening Tests in Selenium IDE"}}
18 You need to select Selenese in the Options -> Format submenu before the Selenium IDE will allow you to open tests in the Selenese format
19 [[image:attach:Picture 4.jpg]]
20 {{/tip}}
21
22 * Play around with test cases from ERSeleniumExample/Resources/Selenium/ using Selenium IDE.
23
24 = Overview and Usage Notes =
25
26 ERSelenium provides several features for effective use of [[SeleniumCore>>url:http://openqa.org/selenium-core/||shape="rect"]] with WebObjects applications including:
27
28 * Custom setup/teardown actions that can be run before/after each test.
29 * Base URL independence.
30 * Support of HTML and Selenese test formats.
31 * "On-the-fly" generation of test suites from the files in your project's source tree.
32 * Bookmarkable DirectAction url to run all tests (can be used for automated testing).
33 * Metacommands (special instructions specified in comments).
34
35 //[[//SeleniumCore//>>url:http://openqa.org/selenium-core/||shape="rect"]]// //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~:// //[[doc:WO.Selenium]]//
36
37 = Adding the ERSelenium framework dependency to an Application =
38
39 You can add a ERSelenium test runner framework dependency to your application with Eclipse/WOLips:
40
41 1. Add the ERSelenium.framework to your project's Libraries dependency. See the tutorial: [[Add a Framework Dependency>>doc:Add a Framework Dependency]]
42 1. (Optionally. Disabled by default. Use with caution). Enable the Selenium tests direct action url in production mode via the property: {{code}}
43 SeleniumTestsEnabled=true
44 {{/code}} Debug output of ERSelenium can be enabled in Properties by:
45
46 {{code}}
47
48 log4j.logger.er.selenium = DEBUG
49
50 {{/code}}
51
52 Other ERSelenium properties:
53
54 * **SeleniumTestsRoot="SomeOtherPath"** - change the tests location. By default ERSelenium will search for tests in "Resources/Selenium".
55 * **SeleniumReportPath="PathName"** - specified the path to the report file, which is created after the testing is done. "./Contents/Resources/" is the default value.
56
57 In your SeleniumTestsRoot folder (Resources/Selenium by default) you should create tests hierarchy. Tests are divided into groups, each group is located in its own folder. In each folder there should be a collection of test files, each in one of the formats, supported by ERSelenium. Example hierarchy:
58
59 {{code}}
60
61 ./Resources
62 ./Selenium
63 ./registration
64 ./successful.sel
65 ./alreadyexists.sel
66 ./shop
67 ./buyitem.html
68 ./notenoughmoney.html
69 ./transfer.sel
70
71 {{/code}}
72
73 You can use both standard HTML and wiki-like Selenese formats for writing tests although Selenese format is usually a preferred choice.
74
75 To run all tests point your browser to SeleniumStartTesting Direct Action:
76 [[http:~~/~~/baseurl/wa/SeleniumStartTesting>>url:http://baseurl/wa/SeleniumStartTesting||shape="rect"]]
77
78 Example:
79 [[http:~~/~~/localhost/cgi-bin/WebObjects/SampleProject.woa/-42421/wa/SeleniumStartTesting>>url:http://localhost/cgi-bin/WebObjects/SampleProject.woa/-42421/wa/SeleniumStartTesting||shape="rect"]]
80
81 To run a specific group of tests, add "/TestGroupName":
82
83 {{code}}
84
85 http://baseurl/wa/SeleniumStartTesting/TestGroupName
86 http://127.0.0.1/cgi-bin/WebObjects/SampleProject.woa/-42421/wa/SeleniumStartTesting/registration
87
88 {{/code}}
89
90 = Some tips for writing tests for ERSelenium =
91
92 * Don't use full URLs with open/openWindow commands ([[http:~~/~~/baseurl>>url:http://baseurl||shape="rect"]] part will be added by ERSelenium):
93 * {{code}}
94 |open|/wa/EditPerson
95 |open|/
96 {{/code}}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"):
97 * {{code}}
98 |open|/wa/Selenium/resetSession
99 {{/code}}You can use @repeat-@values-@done metacommands to execute specific part of the test with additional values edited in textboxes, e.g.: {{code}}
100 @repeat
101 ...some actions...
102 @values user1 user2 user3
103 |type|user|user0
104 @values pass1 pass2 pass3
105 |type|password|pass0
106 ...some more actions...
107 @done
108 {{/code}} 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.
109
110 //Note: in Selenese format, lines that don't begin with "|" are treated as comments, so metacommands in the example above will be safely processed by Selenium IDE.//
111
112 * [[Selenium IDE Firefox plugin>>url:http://release.openqa.org/selenium-ide/0.8.7/selenium-ide-0.8.7.xpi||shape="rect"]] and [[XPath Checker>>url:https://addons.mozilla.org/ru/firefox/addon/1095||shape="rect"]] 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.
113
114 == Using basic flow control ==
115
116 ERSelenium comes with a preinstalled [[flowControl>>url:http://wiki.openqa.org/display/SEL/flowControl||shape="rect"]] user-contributed extension that provides some basic flow control. You can use its commands as described in the [[flowControl documentation>>url:http://wiki.openqa.org/display/SEL/flowControl||shape="rect"]].
117
118 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 {{code language="none"}}id="increment"{{/code}}. The following Selenese fragment would repeatedly press the button until the counter reached 10:
119
120 {{code}}
121
122 |while|!selenium.isTextPresent("Counter = 10");||
123 |click|increment||
124 |endWhile|||
125
126 {{/code}}
127
128 = Standalone runner =
129
130 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.
131
132 [[Selenium-RC>>url:http://seleniumhq.org/documentation/remote-control/||shape="rect"]] is essentially a selenium-server and a set of client libraries that you can use. You can write any kind of client application that sends particular commands to the server and receives back status codes. Among these commands are typical selenium commands ("click", "type" and so on) and several specific ("open specified browser"). Selenium-RC does a great job of preparing the browser profile (it turns off confirmation dialog boxes, clears cookies and so on) and gives a lot of other nice features. One of the most useful is the ability to execute tests from the command line. It's a typical task that is usually executed on build server on regular or per-commit basis.
133
134 The problem is that if you have your tests written with ERSelenium flavor, you won't be able to run them directly with Selenium-RC - as you won't even have a test suite file. But you can do this with StandaloneRunner. To execute the tests you must have Selenium-RC server running in the background. Note that it should be started in windowed mode (not via SSH) - i.e. not in the headless mode. Assuming that you have your application built, you should use the following commands:
135
136 {{code}}
137
138 YourApp.woa/YourApp <tests root folder> <application root url> <selenium-rc server host> <selenium-rc server port> <browser type> \
139 -DWOApplicationClass=er.selenium.rc.StandaloneRunner -Dfile.encoding=utf-8
140
141 {{/code}}
142
143 This will execute the tests using the Selenium-RC server on the specified host and port with the specified browser. The <application root url> will be used as a root url for all urls that are used in tests. Tests from <tests root folder> will be executed (they will be searched for recursively).
144
145 Note, that two last arguments are essential: -DWOApplicationClass substitutes your application's application class with er.selenium.rc.StandaloneRunner, which will do all the testing and then exit without entering WOApplication's requests handling loop. The last argument ensures proper encoding.
146
147 Here is the real-world example commands:
148
149 {{code}}
150
151 cd /Library/WebObjects/Applications
152 ./YourApp.woa/YourApp ./YourApp.woa/Contents/Resources/Selenium http://localhost/cgi-bin/WebObjects/YourApp.woa localhost 4444 '*firefox' \
153 -DWOApplicationClass=er.selenium.rc.StandaloneRunner -Dfile.encoding=utf-8
154
155 {{/code}}
156
157 This will execute tests from **/Library/WebObjects/Applications/YourApp.woa/Contents/Resources/Selenium** using the [[http:~~/~~/localhost/cgi-bin/WebObjects/YourApp.woa>>url:http://localhost/cgi-bin/WebObjects/YourApp.woa||shape="rect"]] as the root url in firefox browser using Selenium-RC server on **localhost** on its default port **4444**.
158
159 The sample of successful output is:
160
161 {{code}}
162
163 - test '/usr/local/wondercap2/dep/YourApp/14662/dep/dist/YourApp.woa/./Contents/Resources/Selenium/Commenting/LoginViaCommenting.sel' PASSED
164 - test '/usr/local/wondercap2/dep/YourApp/14662/dep/dist/YourApp.woa/./Contents/Resources/Selenium/Commenting/NotifyAboutReplies.sel' PASSED
165 - test '/usr/local/wondercap2/dep/YourApp/14662/dep/dist/YourApp.woa/./Contents/Resources/Selenium/Commenting/SignUpViaCommenting.sel' PASSED
166 - test '/usr/local/wondercap2/dep/YourApp/14662/dep/dist/YourApp.woa/./Contents/Resources/Selenium/Commenting/SuccessfulComment.sel' PASSED
167
168 {{/code}}
169
170 All tests in tests root folder are always executed (even if there are failures). The executed command will fail if one of the tests fails.