Execute Test on Firefox
We authored our first test & and executed it on the chrome browser (which is the default browser for test execution).
Now let’s see how to execute the same test in the Firefox browser.
Pre-Requisites
Make sure you have installed the latest version of Firefox
Config changes specific to Firefox
Edit the default.properties file under config folder, like below:
web.target
indicates the browser to be used to execute tests.
web.target: firefox
web.console.log: false
# Web Config
# Web url of web application under test
web.url:http://google.com
# Target Browser. Supported values <any | chrome | firefox | msedge |responsive>
web.target:firefox
# Enable web console log
web.console.log:false
Please note: We have to disable the browser console log, as this is not supported yet.
Execute test from IDE
Creating separate config for Firefox
By default, the config used to execute tests is default.properties.
However, as we observed, we needed few config changes for Firefox. So instead of modifying default.properties let’s override it.
How do we override default.properties ?
Create a file firefox.properties and specify properties to override. That’s it.
Now, when we use firefox.properties below table illustrates the values read from config
Property | Would be read from | Why ? | Property value |
---|---|---|---|
web.console.log | firefox.properties | property is overridden | false |
web.target | firefox.properties | property is overridden | firefox |
web.url | default.properties | No over rides available in firefox.properties | http://google.com |
Use firefox.properties config while running tests
Now that we created a separate config for Firefox, we need to supply it during test execution
Pass the config to the Gradle task as below:
./gradlew clean runWebTests -Dconfig=firefox
This would trigger the tests with firefox.properties as config. Once the execution is complete the Allure reports are can be fetched with the below command
./gradlew allureServe
Creating Gradle task to execute tests for firefox config
Another way to execute tests is to create a Gradle task-specific to firefox config as below:
task runWebTestsOnFirefox(type: Test) {
systemProperties = [
config : "firefox"
]
filter {
excludeTestsMatching "*.mobile.*"
excludeTestsMatching "*.api.*"
excludeTestsMatching "*.db.*"
}
outputs.upToDateWhen { false }
useTestNG {
parallel = "methods"
threadCount Integer.parseInt(System.getProperty("sessions", "2"))
includeGroups System.getProperty("tags", "web")
testLogging.showStandardStreams = true
useDefaultListeners true
outputDirectory = file("$buildDir/" + System.getProperty('tags', 'NONE'))
}
}
Call the task like below:
./gradlew clean runWebTestsOnFirefox