Interface JUnitSeleniumRC

public interface JUnitSeleniumRC

JUnit + Selenium RC

Let's take a look at some JUnit code designed to test a standalone version of the
Smart GWT Showcase:
Trees >> Editing
example. The overall test class, TreeTest, contains a test, testTree1, targeted at the
TreeGrid in the
example, and a test, testTree2, targeted at the SearchForm/ListGrid. As recommended by the
official
Selenium
documentation, we create
the HttpCommandProcessor separately from DefaultSelenium to provide a
way to
invoke the new user extension command waitForElementClickable() which Smart GWT
defines.
(See our Selenium User Guide described in AutomatedTesting.)

The test class TreeTest was initially generated by exporting the Selenium script for testTree1
in JUnit 4
format, but it was modified by hand as mentioned above to support the
waitForElementClickable().
Below we look at the two test cases testTree1 and testTree2. Note that in each case, we
maximize
the Selenium browser window in accordance with the best practices mentioned in the User Guide.

If you'd like to experiment with making changes to the sample JUnit code, one improvement that
simplifies
things is to add a myClick() function that handles both the
waitForElementClickable() and
the click on a supplied locator. Even just assigning each unique locator to a
local Java
variable so it can be reused for multiple calls will make the code simpler to follow and
maintain.

Verify that the Salary of Cheryl Pearson, who reports to Gene, is 5650

For this test, the locators were generated by Selenium IDE for us but we did modify the code
to make use of the function waitForElementClickable().

Note that though the locator for Cheryl includes the salary, it will match based on the first
field, EmployeeId, which is the primary key, so the test will correctly compare the contents
of Cheryl's salary against the value 5650 and fail if it doesn't match. If for some reason
your test requires matching a specific field rather than the default fields and ordering
generated automatically, you can hand edit the locator.

1. Click on the SearchForm button, revealing a Charles Madigen popup,
2. Issue a MouseMove on the Charles Madigen popup, revealing a list of his reports,
3. Click on his report Joan Little, filling the ListGrid with her reports,
4. Click on the salary column header twice, sorting by descending salary, and
5. Verify the salary in the top row (top salary) is 9400

This test required more hand modification than the previous one. In particular three
modifications were made:

A mouseMove command was manually added to the Selenium IDE script,

A call to waitForGridDone() was added to assure the sorting was done before
we ran verifyText, and

We manually removed all but row qualifier from the automatically generated scLocator for
step #5.

The first modification is required because our user extensions don't record mouseMove
events, and the second is needed to ensure the sorts are complete before verifyText runs--for
details see the User Guide (described in AutomatedTesting).
The final modification is
just a reflection of what our intent is in step #5; we want to operate on the top row,
regardless of its contents, so we don't want our locator matching based on the EmployeeId or
Name fields of the records. (Matching by EmployeeId in the locator as automatically
generated would make the test verify that Kelly Fetterman's salary is 9400 rather than that
9400
is the highest salary.)