Ready-to-use UI Test Automation Architecture using Java and Playwright.
- Configuration-based architecture
- Utilizes Page Objects and Page Component Objects
- Data-Driven
- Captures screenshot on test failure
- Records video of test execution
- Provides detailed test report
- Supports parallel test execution
In order to use the framework:
- Fork the repository.
- Clone, i.e, download your copy of the repository to your local machine using
git clone https://github.com/[your_username]/playwright-java-test-automation-architecture.git
- Import the project in IntelliJ IDEA.
- Make your desired changes.
- Use IntelliJ IDEA to run your desired tests. Alternatively, you can use the terminal to run the tests, for example
./gradlew test -Dbrowser=firefox -Dheadless=false
to run all the tests using the firefox browser in headed mode. - Build and browse the allure report using
./gradlew allureServe
The project uses the following:
- Java 11 as the programming language.
- Playwright as the web browser automation framework using the Java binding.
- Univocity Parsers to parse and handle CSV files.
- JUnit 5 as the testing framework.
- Lombok to generate getters.
- Owner to minimize the code to handle properties file.
- Allure Report as the test reporting strategy.
- Gradle as the Java build tool.
- IntelliJ IDEA as the IDE.
The project is structured as follows:
π¦ playwright-java-test-automation-architecture
ββ .github
β ββ FUNDING.yml
β ββ dependabot.yml
β ββ workflows
β ββ test-execution.yml
ββ .gitignore
ββ LICENSE
ββ README.md
ββ build.gradle
ββ gradle
β ββ wrapper
β ββ gradle-wrapper.jar
β ββ gradle-wrapper.properties
ββ gradlew
ββ gradlew.bat
ββ settings.gradle
ββ src
ββ main
β ββ java
β ββ io
β ββ github
β ββ tahanima
β ββ config
β β ββ Configuration.java
β β ββ ConfigurationManager.java
β ββ dto
β β ββ BaseDto.java
β β ββ LoginDto.java
β β ββ ProductsDto.java
β ββ factory
β β ββ BasePageFactory.java
β β ββ BrowserFactory.java
β ββ ui
β β ββ component
β β β ββ BaseComponent.java
β β β ββ Header.java
β β β ββ SideNavMenu.java
β β ββ page
β β ββ BasePage.java
β β ββ LoginPage.java
β β ββ ProductsPage.java
β ββ util
β ββ BrowserManager.java
ββ test
ββ java
β ββ io
β ββ github
β ββ tahanima
β ββ annotation
β β ββ DataSource.java
β β ββ Regression.java
β β ββ Smoke.java
β β ββ Validation.java
β ββ e2e
β β ββ BaseTest.java
β β ββ LoginTest.java
β β ββ ProductsTest.java
β ββ util
β ββ CsvToDtoMapper.java
β ββ DataArgumentsProvider.java
ββ resources
ββ allure.properties
ββ config.properties
ββ junit-platform.properties
ββ testdata
ββ login.csv
ββ products.csv
-
The project uses a config.properties file to manage global configurations such as browser type and base url.
-
To add a new property, register a new entry in this file.
key=value
Then, add a method in the Configuration interface in the below format.
@Key("key") dataType key();
For example, let's say I want to add a new property named
context
with the valuedev
. In theconfig.properties
file, I'll add:context=dev
In the
Configuration
interface, I'll add:@Key("context") String context();
To use your newly created property, you need to use the below import statement.
import static io.github.tahanima.config.ConfigurationManager.config;
Then, you can call
config().key()
to retrieve the value of your newly created property. For the example I've provided, I need to callconfig().context()
. -
You can supply the properties present in the
config.properties
file as system properties in your test via gradle../gradlew test -Dkey1=value1 -Dkey2=value2
-
-
The project uses csv file to store test data and univocity-parsers to retrieve the data and map it to a Java bean.
To add configurations for new test data, add a new Java bean in the dto package. For example, let's say I want to add test data for a
User
with the attributesFirst Name
andLast Name
. The code for this is as follows:package io.github.tahanima.dto; import com.univocity.parsers.annotations.Parsed; import lombok.Getter; import lombok.ToString; @Getter @ToString(callSuper = true) public class UserDto extends BaseDto { @Parsed(field = "First Name", defaultNullRead = "") private String firstName; @Parsed(field = "Last Name", defaultNullRead = "") private String lastName; }
Note that the class extends from BaseDto and thus, inherits the attribute
Test Case ID
.Now, in the testdata folder you can add a csv file
user.csv
forUser
with the below contents and use it in your tests.Test Case ID,First Name,Last Name TC-1,Tahanima,Chowdhury
-
The project uses Page Objects and Page Component Objects to capture the relevant behaviors of a web page. Check the ui package for reference.
-
The project uses JUnit 5 as the test runner. Check this implementation for reference.