Welcome to Java Demo Scripts designed by Salsabilla Aliska Putri to provide examples of how to use Sauce Labs technology. This repository contains everything you need to get started with the web, visually, functionally, and all other types of automation using Java.
- General info
- Technologies
- The starter project
- The sample scenario
- Executing the tests
- Generating the reports
In this project, testing was carried out on several features contained in Sauce Demo
Also, I've written some manual test cases that I managed in spreadsheet web-manual test saucedemo
Project is created with:
- Intellij IDEA Community 2022.1.1 - development environment for Java
- Selenium WebDriver - for automated testing of web applications
- Java 8 - basics of Java language
- Serenity with Cucumber
- Google Spreadsheet - test cases management
- Git, Git Bash, Github
The best place to start with Serenity and Cucumber is to clone or download the starter project on Github (https://github.com/serenity-bdd/serenity-cucumber-starter). This project gives you a basic project setup, along with some sample tests and supporting classes. There are two versions to choose from. The master branch uses a more classic approach, using action classes and lightweight page objects, whereas the screenplay branch shows the same sample test implemented using Screenplay.
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
+ resources
+ features Feature files
+ search Feature file subdirectories
search_by_keyword.feature
Serenity 2.2.13 introduced integration with WebdriverManager to download webdriver binaries.
Both variations of the sample project uses the sample Cucumber scenario. In this scenario, Sergey (who likes to search for stuff) is performing a search on the internet:
@test @positive
Scenario: Checkout item successfully
Given user already add item to cart
When user click on checkout button
Then checkout: your information appear
When user fill first name with "test"
And user fill last name with "feature"
And user fill zip postal code with "A5743"
And user click on continue button
Then checkout: overview page appear
The sample code in the master branch uses the Screenplay pattern. The Screenplay pattern describes tests in terms of actors and the tasks they perform. Tasks are represented as objects performed by an actor, rather than methods. This makes them more flexible and composable, at the cost of being a bit more wordy. Here is an example:
@Steps
CheckoutItemStep checkoutItemStep;
@Given("user already add item to cart")
public void userAlreadyAddItemToCart() {
checkoutItemStep.addedItem();
}
@When("user click on checkout button")
public void userClickOnCheckoutButton() {
checkoutItemStep.clickCheckout();
}
To run the sample project, you can either just run the CucumberTestSuite
test runner class, or run either mvn verify
or gradle test
from the command line.
By default, the tests will run using Chrome. You can run them in Firefox by overriding the driver
system property, e.g.
$ mvn clean verify -Ddriver=firefox
Or
$ gradle clean test -Pdriver=firefox
The test results will be recorded in the target/site/serenity
directory.
Since the Serenity reports contain aggregate information about all of the tests, they are not generated after each individual test (as this would be extremenly inefficient). Rather, The Full Serenity reports are generated by the serenity-maven-plugin
. You can trigger this by running mvn serenity:aggregate
from the command line or from your IDE.
They reports are also integrated into the Maven build process: the following code in the pom.xml
file causes the reports to be generated automatically once all the tests have completed when you run mvn verify
?
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.maven.version}</version>
<configuration>
<tags>${tags}</tags>
</configuration>
<executions>
<execution>
<id>serenity-reports</id>
<phase>post-integration-test</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
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.
We can also configure environment-specific properties and options, so that the tests can be run in different environments. Here, we configure three environments, dev, staging and prod, with different starting URLs for each:
environments {
default {
webdriver.base.url = "https://duckduckgo.com"
}
dev {
webdriver.base.url = "https://duckduckgo.com/dev"
}
staging {
webdriver.base.url = "https://duckduckgo.com/staging"
}
prod {
webdriver.base.url = "https://duckduckgo.com/prod"
}
}
You use the environment
system property to determine which environment to run against. For example to run the tests in the staging environment, you could run:
$ mvn clean verify -Denvironment=staging
See this article for more details about this feature.
For more information about Serenity BDD, you can read the Serenity BDD Book, the official online Serenity documentation source. Other sources include:
- Learn Serenity BDD Online with online courses from the Serenity Dojo Training Library
- Byte-sized Serenity BDD - tips and tricks about Serenity BDD
- For regular posts on agile test automation best practices, join the Agile Test Automation Secrets groups on LinkedIn and Facebook
- Serenity BDD Blog - regular articles about Serenity BDD