Serenity BDD is a library that makes it easier to write high quality automated acceptance tests, with powerful reporting and living documentation features. It has strong support for both web testing with Selenium, and API testing using RestAssured.
The project has build scripts for both Maven and Gradle, and follows the standard directory structure used in most Serenity projects:
src
+ main
+ test
+ java Test runners and supporting code
+ swaglabs
+ Pages
+ StepDefinition
+ resources
+ features Feature files
Feature: Authorization
@authorization
Scenario Outline: Login functionality
Given I am already on Login Page
When I input "<username>" as username
And I input "<password>" as password
And I click login button
Then I should get response "<response>"
Examples:
| username | password | response |
| standard_user | secret_sauce | redirected to Inventory Page |
| locked_out_user | secret_sauce | Epic sadface: Sorry, this user has been locked out. |
| problem_user | secret_sauce | redirected to Inventory Page |
| performance_glitch_user | secret_sauce | redirected to Inventory Page |
| | | Epic sadface: Username is required |
| standard_user | | Epic sadface: Password is required |
| wrong_user | secret_sauce | Epic sadface: Username and password do not match any user in this service |
A more imperative-style implementation using the Action Classes pattern can be found in the action-classes
branch. The glue code in this version looks this this:
@Given("I am already on Login Page")
public void iAmAlreadyOnLoginPage() {
login.open();
}
@When("I input {string} as username")
public void iInputAsUsername(String username) {
login.inputUsername(username);
}
@And("I input {string} as password")
public void iInputAsPassword(String password) {
login.inputPassword(password);
}
@And("I click login button")
public void iClickLoginButton() {
login.clickLoginButton();
}
The sample projects both use some Serenity features which make configuring the tests easier. In particular, Serenity uses the serenity.conf
file in the src/test/resources
directory to configure test execution options.
The WebDriver configuration is managed entirely from this file, as illustrated below:
webdriver {
driver = chrome
}
headless.mode = true
chrome.switches="""--start-maximized;--test-type;--no-sandbox;--ignore-certificate-errors;
--disable-popup-blocking;--disable-default-apps;--disable-extensions-file-access-check;
--incognito;--disable-infobars,--disable-gpu"""
Serenity uses WebDriverManager to download the WebDriver binaries automatically before the tests are executed.
- Clone this repository
git clone https://github.com/AnjarTiyo/saucedemo-testautomation.git
- Go to saved directory
cd saucedemo-testautomation
- Generate report using following code
mvn clean verify
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Anjar Tiyo Saputro - @anjartiyo.s - anjar.jog@gmail.com
Project Link: https://github.com/AnjarTiyo/saucedemo-testautomation