This project is a Cucumber Selenium UI automation test example framework for teaching automated testing. It is written in Java using Cucumber BDD, TestNG and produces reports of test results. It is integrated with BrowserStack to run tests on remote browsers and devices.
Have the Cucumber for Java, Gherkin & TestNG plugin installed in IntelliJ. Have Java 17 or newer installed. Set Project Settings Structure and SDK to: 17
- Implement the step definitions to get the smoke test feature working.
- Execute the tests against another browser locally other than the default: Chrome.
- Get all four smoke tests to run all at once in parallel.
- Create new smoke tests of your own choosing to extend the suite e.g. purchasing clothing.
Right-click the feature file and select "Run" or "Debug" to start the test.
To run the tests, use your CI or point Maven to the project and use the goals:
mvn clean test -Psmoke
To run a specific test, use the Cucumber filter:
mvn clean test -Dcucumber.filter.tags=@smk1
By default, all tests run in parallel but if you wish to run a test in series mode then tag the test or scenario with
the annotation: @serial
To change the amount of tests which run in parallel, change the value of data-provider-thread-count="5" in the
testng.xml file i.e. smoke.xml
When writing tests using this framework, you can easily leverage these tests to run against an Appium grid with the following settings:
| Browser type | System property value |
|---|---|
| Appium Mobile | AppiumMobile |
You can set Appium properties using the following to create a request (for capability values information, see http://appium.io/docs/en/writing-running-appium/caps/) :
- appium.browser.name
- appium.device.name
- appium.platform.name
- appium.os.version
There is a special pre-set Appium driver for WinAppDriver that can be used for Windows desktop testing by using:
| Browser type | System property value |
|---|---|
| Windows Driver (WinAppDriver) | AppiumWindowsTenRemote |
For more Appium driver capabilities information, see: http://appium.io/docs/en/writing-running-appium/caps/
To point your tests to a Selenium grid, at runtime or through VM options in your IDE, pass the following property:
-Dselenium.grid.url=http://localhost:4444/wd/hub
When running tests on a remote grid, you must specify a "Remote" type browser, e.g. ChromeRemote:
-Dbrowser.type=ChromeRemote
To point your tests to Browserstack at runtime or through VM options in your IDE, pass the following properties:
-Dbrowserstack.username=TESTUSER
-Dbrowserstack.access.key=KEY123!
To override Browserstack logging levels from their default to turning all logs off, pass the following property:
-Dbrowserstack.logging=OFF
To override Browserstack logging levels from their default to turning all logs on and at error level, pass the following property:
-Dbrowserstack.logging=ON
Properties are retrieved by default from a file called dev1.properties, which should be located under:
src > main > resources > properties
The properties declared here can be overridden, however, if specified as a system property at runtime.
For example, if you declare the following property in your dev1.properties file:
browser.type=EdgeLocal
You also pass the following at runtime:
-Dbrowser.type=EdgeLocal
Logging can be easily added to tests by using the static methods from the Log class.
Available logging levels are:
| Logging Level | Method |
|---|---|
| Info | Log.Info("This is an info level message"); |
| Warn | Log.Warn("This is a warning level message"); |
| Error | Log.Info("This is an error level message"); |
| Debug | Log.Info("This is a debug level message"); |
Cucumber reports can be published to Cucumber online for viewing upto 24 hours later at which they will be destroyed.
To enable cucumber reports change cucumber.publish.enabled=false to cucumber.publish.enabled=true in
src/test/resources/cucumber.properties.
- Selenium - Browser automation framework
- Maven - Dependency management
- TestNG - Testing framework
- WebDriverManager - Local webdriver binary management
- Don't use Selenium to cover tests which are better placed at unit or integration level
- Be familiar with and use the pageObjects pattern
- Preferred web element selector order preference: id > name > css > xpath
- Avoid
Thread.sleep(), prefer explicit waits such as: FluentWait or WebDriverWait - Use relative URLs