Hello,
I need some help configuring my test tasks.
I have a Selenium test framework that I am using with Gradle. You can find the basics of it here.
https://github.com/iainrose/page-objects
In my BaseTest class, which all my other tests inherit from, I define a number of system properties so I can run the tests on different web servers, browsers, selenium servers, etc.
https://github.com/iainrose/page-objects/blob/master/src/test/java/BaseTest.java
Most of the time, I want to run the tests with the default values as defined in my BaseTest class but from time to time I need to run them using different settings.
I’ve noticed that unless I duplicate the declaration of those system properties within my test task definitions in build.gradle I cannot pass in other values from the command line at runtime.
Example:
With my test task configured like this …
test {
useTestNG()
maxParallelForks = 4
}
… this still runs my tests in Firefox
./gradlew test -DBROWSER=chrome
However, if I configure my test task like this it works and the tests will run in Chrome.
test {
useTestNG()
maxParallelForks = 4
systemProperties = [
BROWSER: System.getProperty('BROWSER', 'firefox')
]
}
You can see here that I’ve had to duplicate this in all of my tasks.
https://github.com/iainrose/page-objects/blob/master/build.gradle
This also just a dummy project and in the real one I have more than 3 tasks, and also will override more than just the one system property and it just seems wrong that I have to copy and paste this in every single test task. It seems even more wrong as the default value of BROWSER that I have to add and duplicate is never actually needed as if I just run …
./gradlew test
… the test will run in Firefox regardless of which of the above two version of my test task definition I use.
I must be missing something simple, can you please help me out?