Selenium RC Extending GrailsSelenium...

Last updated by fletcherr 2 years ago

Extending GrailsSeleniumTestCase

Instead of using the SeleniumTest mixin you can extend grails.plugins.selenium.GrailsSeleniumTestCase which provides everything the mixin does with some additional capabilities. Firstly you can use some of the more advanced assertions provided by the SeleneseTestBase class as well as the various verify methods, the seleniumEquals method, etc. See the documentation for SeleneseTestBase for details.

Using assert, verify and waitFor convenience methods

Extending GrailsSeleniumTestCase enables you to directly assert, verify or waitFor certain Selenium conditions. Any Selenium method starting with is can be used as a boolean assertion by replacing the is with assert, verify or waitFor in the method call. Likewise any Selenium method starting with get can be used as an equality assertion. The following table gives some examples:

Without GrailsSeleniumTestCaseWith GrailsSeleniumTestCase
assertTrue selenium.isTextPresent("Welcome to Grails")assertTextPresent("Welcome to Grails")
verifyTrue selenium.isVisible("myElement")verifyVisible("myElement")
waitFor { selenium.isAlertPresent() }waitForAlertPresent()
assertEquals("Expected text", selenium.getText("myElement"))assertText("Expected text", "myElement")
waitFor { selenium.getXpathCount("//ul/li") == 3 }waitForXpathCount 3, "//ul/li"

You can also use assertNot*, verifyNot* and waitForNot* to test negated conditions.

Currently there is no way to pass message arguments to these convenience methods, although this will hopefully be added in a future version of the plugin.