This project is a QA automation framework built using Cucumber BDD (Behavior-Driven Development) framework with Selenium and Java. It provides a structured approach for automating browser tests, ensuring efficient test case management and easier collaboration between QA engineers and stakeholders. Maven as the build automation tool for managing dependencies and executing tests. JUnit for assertion and validation of test results. There is two main step for this framework.
InsiderTaskProject
- add below property section
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
- Add dependencies
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.10.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.2.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>me.jvt.cucumber</groupId>
<artifactId>reporting-plugin</artifactId>
<version>7.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.javafaker/javafaker -->
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
</dependency>
<!--If you want to get rid of SLF4J Failed to load message from the console -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.32</version>
</dependency>
</dependencies>
- Add Build Plugins
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<parallel>methods</parallel>
<threadCount>4</threadCount>
<testFailureIgnore>true</testFailureIgnore>
<includes>
<include>**/CukesRunner*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
- under
com.sauceDemo
package, createpages
,runners
,step_definitions
andutilities
packages
- Add a
configuration.properties
file to store some credentials in order to avoid hard coding if we need and determine which type of browser we use. add following information:
browser=chrome
username=standard_user
password=secret_sauce
homepageUrl=https://www.saucedemo.com/
- Create a file with
.feature
extension to define scenarios and steps. This just a regular file.
- In feature file follow cucumber BDD (Gherkin) approach
- Create separate java classes for corresponding feature file to write test cases source code.
- Create
Hooks
class for determining common steps likeDriver.getDriver().manage().window().maximize();
andDriver.closeDriver();
for all scenarios by using@Before
and@After
annotations which come from cucumber.
6.Under runners
package, create CukesRunner
and FailedTestRunner
java classes to run step_definitions
java classes test source code
- Add below information above CukesRunner class name
@RunWith(Cucumber.class)
@CucumberOptions(
plugin = {
"html:target/cucumber-report.html",
"rerun:target/rerun.txt",
"me.jvt.cucumber.report.PrettyReports:target/cucumber",
"json:target/cucumber.json"
},
features = "src/test/resources/features",
glue = "com/sauceDemo/step_definitions",
dryRun =false,
tags = ""
)
- Add below information above FailedTestRunner class name
@RunWith(Cucumber.class)
@CucumberOptions(
glue = "com/sauceDemo/step_definitions",
features = "@target/rerun.txt"
)
7. Under pages
package, create each page of application corresponding Java Classes
to store each page related web elements to achieve Page Object Model
- Create BasePage java abstract class and add a constructor with
PageFactory.initElements()
method to extend this class from other pages classes. We achieve reusability in this way.
public abstract class BasePage {
public BasePage() {
PageFactory.initElements(Driver.getDriver(),this);
}
}
- Implementation of Singleton Design Pattern.
- Switch between different browser types easily
private static InheritableThreadLocal<WebDriver> driverPool = new InheritableThreadLocal<>();
object allow us to create a new separate instance of driver for each test in parallel testing.
- We use for getting some important test data from properties file. Like:
- BrowserType
- Username
- Password
- BaseURL
- There are a lot of useful and helpful methods to use throughout the automation project
This project structure releases 3 different report. We specify under the plugin
section in CukesRunner
class Cucumber Options
annotation. All report releases under target
directory after running project.
"html:target/cucumber-reports.html"
is basic cucumber report for sharing via email in Jenkins."me.jvt.cucumber.report.PrettyReports:target/cucumber"
is extended cucumber report to show all steps of scenario in detail."json:target/cucumber.json"
is basic json file to import test result in Jira after execution of test cases.
After 116 version of Chrome, WebDriverManager doesn't support this one. In order to handle this problem, download newest chromedriver.exe
and put it in the project directory.