Draft of Presentation Slides and Labs for Upcoming Selenium/Grails Talk at Sacramento Groovy Users Group
I will be presenting on the topic of Automating Selenium Browser-Based Testing For Grails Applications at the next meeting of the Sacramento Groovy Users Group (November 18, 2009). Links to the power point, and a flash version of the presentation are available .
LABS !
As part of the presentation we will allocate time for you to work through two hands-on labs. To avoid getting stuck with download and configuration hassles during the talk, you may want to pre-download the
pre-requisite software:
- Maven-2.0.9 (what I used) or greater
- Download from http://maven.apache.org/download.html
- Grails 1.1.1
- Download from http://grails.org/Download
- Java 1.5 or greater
I hope some of you will be able to go through the labs before the presentation. Even though I’ve worked through the materials successfully on my box, it’s possible that you might run into a wrinkle or two due to differences in development environments. If you do, please submit any question you may have as a comment to this blog post. This will help us publicly capture any problems (and their solutions) beforehand.
I will incorporate instructions for the labs into later drafts of the presentation slides, but for now here are the steps:
LAB 1 – Use Maven, Maven Grails, Cargo and Selenium Plugins to Launch Browser Based tests
- Download http://buildlackey.com/web_content/sac_groovy_user_group_pres_11_18/lab1.grails.selenium.using.maven.zip
- cd <unzip-dir-top-level>
- Type mvn clean install
- You should see BUILD SUCCESSFUL at the tail end of the process (which will take approximately 2 – 5 minutes, depending on how many Maven dependencies you need to download.) If you are launching Maven for the first time your local Maven repository cache will be empty and you should expect a longer wait.
- Later versions of the slides will provide a detailed explanation of what’s going on.
LAB 2 – Using Grails Selenium-rc Plug-in
- Create the App
- grails create-app books
- cd books
- grails create-domain-class com.Book
- grails generate-all com.Book
- Make sure it launches as expected
- grails run-app (see the familiar ‘Welcome to Grails’ message)
- Install plugin and Create Test
- Type
- grails install-plugin selenium-rc
- Open up grails-app/conf/Config.groovy and ensure that the grails.serverURL property is defined for every enviornment (production, development, and test.) If this property is undefined I’ve seen strange problems occur when test tests are run.
- Open an editor on the file test/selenium/HomePageTests.groovy, then type the following:
- Type
import grails.plugins.selenium.*
@Mixin(SeleniumTest)
class HomePageTests extends GroovyTestCase {
void testHomepageLoads() {
selenium.open "$contextPath/"
assertTrue selenium.isTextPresent("Welcome to Grails")
}
}
- Run the Tests to Verify Success, Then Deliberately Introduce a Failure
- Type
- grails test-app
- This will run all unit, functional and integration tests. You should see the browser pop up briefly and the tests should pass.
- To verify that you are testing what you think you are testing, you will now deliberately introduce a test failure.
- Open the file ./grails-app/views/index.gsp and replace all occurences of ‘Welcome to Grails’ with ‘Welcome to Jail’.
- Run
- grails clean
- grails test-app
- Note that the Tests FAILED message is now visible. In the last page of your output you should also see the message:
- testHomePageLoads…FAILED
- To see a detailed stack trace at the point of failure, open your folder browser on the folder test/reports/plain.
- View the file TEST-HomePageTests.txt and you should see a stack trace that describes the assertion that failed.
- Type
























on January 12th, 2010
[...] version of the talk will be simple Spring based demo app, rather than the Grails demo that I used when I gave this talk to the Sac Groovy Users [...]