This information is out of date – please see http://www.grails.org/Selenium+plugin
Version 0.4 of the grails selenium plugin is now available.
This version adds:
- scripts to create and run tests
- a postResults url for displaying the final test results
Details are as follows:
run-selenium
Runs Selenium in the specified browser.
Specify the path to your browser as a command line parameter i.e.
grails run-selenium /usr/bin/firefox
or, if the executable is on the path you would just need
grails run-selenium firefox
In your application.properties, you can specify:
selenium.auto=true
selenium.close=true
selenium.multiWindow=true
selenium.highlight=true
selenium.resultsUrl=/your/url/here (defaults to ${appContext}/selenium/postResults)
selenium.runInterval=1000
selenium.baseUrl=
See http://selenium.openqa.org/installing.html (section titled Continuous Integration) for more information on selenium and continuous integration.
create-selenium-test
Generates a new empty selenium test.
Supply the path of the test you want to create, relative to ‘web-app/selenium/tests’. The extension of this must be one of html, psv, gsp. The test file will be created using the syntax based on the file extension.
Example use:
grails create-selenium-test registration/errors/InvalidUsername.gsp
creates
web-app/selenium/tests/registration/errors/InvalidUsername.gsp
create-selenium-domain-test
Generates a new selenium test for the given domain class.
Supply the name of the domain class you want to test, followed by and extension that identifies the sytax to use. The extension of this must be one of html, psv, gsp.
Example use:
grails create-selenium-domain-test book.gsp
creates
web-app/selenium/tests/book.gsp
The generated test exercises the default grails scaffolding for CRUD functionality.
postResults page
A basic postResults page is provided, and if required the results can be saved to xml.
When using grails run-selenium, you can add properties to application.properties:
- selenium.auto=true
- selenium.resultsUrl=/your/url/here (defaults to ${appContext}/selenium/postResults)
- selenium.saveXmlTo=/tmp/selenium.xml
By default resultsUrl is set as ${appContext}/selenium/postResults which is provided as a basic HTML implementation. Nothing fancy.
Download here or install with
grails install-plugin http://www.javathinking.com/grails/grails-selenium-plugin/0.4/grails-selenium-0.4.zip






{ 14 comments… read them below or add one }
Note, when specifying the browser path on the command line spaces are a problem – so ‘program files’ won’t work. As a workaround, run ‘grails run-selenium’ without a parameter and you will be prompted. Here, you can enter ‘c:\program files\mozilla firefox\firefox.exe’. Alternatively, you could add ‘c:\program files\mozilla firefox’ to your path.
I’ll look into better command line parsing when I get time.
Nice work Paul! 8 days from requesting to receiving “create-selenium-domain-test” is pretty impressive.
Hi Paul, I’ve approved your access to the Grails plug-in repo
If you just type
grails release-plugin
Your plug-in will be made available from the central repo
I like selenium, so I was very glad to find this Grails plugin. Sadly, I can not get it to work.
I follow the instructions at http://docs.codehaus.org/display/GRAILS/Selenium+plugin
and at the command grails create-selenium-test mytest.html I get an error:
No such property: appContext for class: CreateSeleniumTest_groovy
Also grail run-selenium fails with an exception: Error executing script RunSelenium: No such property: appContext for class: RunSelenium_groovy
groovy.lang.MissingPropertyException: No such property: appContext for class: RunSelenium_groovy
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:49)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:59)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:169)
at gant.Gant$_processTargets_closure13.doCall(Gant.groovy:416)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:226)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:899)
at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:946)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrentN(ScriptBytecodeAdapter.java:77)
at gant.Gant$_processTargets_closure13.call(Gant.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:226)
I tried this with grails 1.0.1 and 1.0.2. Same result. Do I miss something? Do you have any idea, what is wrong?
Paul, nice stuff here. I’ve been using your plugin for a few days and I have made some modifications and have ideas for a few more. Also I wrote a format file for Selenium IDE to understand your .psv format and I’d like to make that available. I couldn’t find another way to contact you, so if you want some collaboration please send me an email. Thanks! (I’m assuming you can see the email I entered above.)
Gerd, I think I know the problem – I have been using a slightly modified version of grails – see here http://jira.codehaus.org/browse/GRAILS-2534
This modification defines appContext in Init.groovy and allows you to define a custom context path in several ways. Hopefully this will make it into the next release of grails.
I’m sorry for the confusion – I’d completely forgotten about this dependency. If you don’t want to apply the complete patch, then adding
appContext=grailsAppName
to/scripts/Init.groovy at approx line 113, just before
configSlurper = new ConfigSlurper(grailsEnv)
might get it working for now.
Kris, sounds good, I’ll email you when I am back from holiday.
Graeme, thanks for the access. I’m back from holiday now, so I’ll try to add the plugins to the repository soon.
Running grails 1.0.2 with the patch that you recommended I with the appContext=grailsAppName
I am getting the following error.
HTTP ERROR: 404
/WEB-INF/grails-app/views/selenium/suite.jsp
RequestURI=/BMAMImportTool/WEB-INF/grails-app/views/selenium/suite.jsp
in the suites box eventhough I have tests in the web-app/selenium/tests directory created by the create-selenium-tests script.
Everything else works correctly. Any ideas about what the problem might be?
Lance
Lance – I’ve easily recreated the problem you describe. I’m wondering if it is a problem with grails-1.0.2 ?
I wrote the plugin using grails-1.0.1, and it seems that under 1.0.2 it can’t resolve views contained in plugins.
As a workaround, you can copy
plugins/selenium-0.4/grails-app/views/selenium
to
grails-app/views/selenium
and all seems well.
Will have to investigate further to see if it is my problem or an issue with grails…
Thanks for letting me know.
I’ve just spent some time testing it in 1.0.1, and everything is fine there, so it must be a problem with 1.0.2.
Further investigation shows it is a known issue and will be resolved in 1.0.3 (when it is released)
http://jira.codehaus.org/browse/GRAILS-2685
http://www.nabble.com/1.0.2-and-plugin-views-issue-td16196632.html
Once again, thanks for bringing it to my attention. Until 1.0.3 is released, I’d suggest just copying the plugin views into your app as described above.
Good luck!
Do you think you might release a 0.4.1 to make up for the ppContext issue? I really don’t see myself making modifications to my Grails installation – or I risk making the same mistake you did
I’ll be releasing a new version soon – I don’t have much time online at the moment!
grails-selenium-0.5 released, hopefully fixes the issues with grails 1.0.3