If you want to run your Selenium (WebDriver) tests from Gradle you can do it like this:
1. Add Jetty plugin to build.gradle:
apply plugin: 'jetty'
2. Create a src/selenium/java folder in you project root.
3. Add a SourceSet to build.gradle:
sourceSets {
selenium
}
4. Add Selenium dependencies to build.gradle:
seleniumCompile 'junit:junit:4.11' seleniumCompile 'org.seleniumhq.selenium:selenium-java:2.30.0'
Add jettyDaemon and selenium tasks to build.gradle:
task jettyDaemon(type: org.gradle.api.plugins.jetty.JettyRun) {
daemon = true
}
task selenium(type: Test, dependsOn: jettyDaemon) {
testClassesDir = sourceSets.selenium.output.classesDir
classpath = sourceSets.selenium.runtimeClasspath
}
5. If you are using Eclipse, add Selenium dependencies to the Eclipse classpath in build.gradle:
eclipse {
classpath {
plusConfigurations += configurations.seleniumCompile
}
}
You can now place you Selenium tests in src/selenium/java and run:
gradle clean selenium
For a complete example check out https://github.com/shagstrom/spring-mvc-hibernate-skeleton .
Thanks for the post!
Did u forget to declare the seleniumCompile configuration? Should that extend testCompile/testRuntime
Also: what is the need for “clean”? Anything special with any tasks?
In old versions of Gradle you had to declare configurations for sourceSets. Since version 1.0 (or maybe later) it’s implicit when you declare a sourceSet.
There is no need to add “clean” when you run
gradle seleniumthe first time, but if you were to run it again, without any code change, the selenium tests would not run. Gradle does it this way so that it doesn’t have to recompile code if there has not been a code change. In any case, I do it out of habit, since I always want the selenium tests to run when I run the commandgradle selenium.I have upgraded
selenium-javato 2.30.0 so that it works with the latest version of Firefox.Cool, u learn something every day
I still declared a seleniumCompile just so I could extend the testCompile config (that way I avoided the straight cpy/paste, which always makes me feel like a thief)
Hello,
you could add
outputs.upToDateWhen { false }
to the selenium task to ensure that it always runs.
B.
Nice. Thanks!