Start | | Maven | Quickstart | |
---|---|
Run | | Command Line | IDE Support | Java JDK | Troubleshooting | | Environment Switching |
Report | | Configuration | Logging | |
Advanced | | Contributing | |
This project is a test harness for using Playwright with Java for both UI and API testing. It is set up as a multi-module Maven project with two modules: ui
for UI-based tests and api
for API-based tests.
The Framework uses Playwright and TestNG client implementations.
<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>1.49.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.10.2</version>
</dependency>
- Intellij IDE -
Recommended
- Java JDK 17
- Apache Maven
Normally you will use your IDE to run a test via the *Test.java
class. With the Test
class,
we can run tests from the command-line as well.
Note that the mvn test
command only runs test classes that follow the *Test.java
naming convention.
You can run a single test or a suite or tests like so :
mvn test -Dtest=UITest
Note that the mvn clean install
command runs all test Classes that follow the *Test.java
naming convention
mvn clean install
To minimize the discrepancies between IDE versions and Locales the <sourceEncoding>
is set to UTF-8
<properties>
...
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
...
</properties>
You can specify the profile to use when running Maven from the command line like so:
mvn clean test -Ptest
Example of a maven profile
<profiles>
...
<profile>
<id>test</id>
<properties>
<config.file>config-test.properties</config.file>
</properties>
</profile>
...
</profiles>
The Java version to use is defined in the maven-compiler-plugin
<build>
...
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
...
</plugins>
</pluginManagement>
...
</build>
The Framework uses SLF4J You can instantiate the logging service in any Class like so
private static final LogManager log = new LogManager(UITest.class);
you can then use the logger like so :
logger.info("This is a info message");
logger.warn("This is a warning message");
logger.debug("This is a info message");
logger.error("This is a error message");
The Framework uses Extent Reports Framework to generate the HTML Test Reports
The example below is a report generated automatically by Extent Reports open-source library.
This project is open source and available under the MIT License.
- Execute the following commands to resolve any dependency issues
cd ~/install directory path/playwright-java-test-harness
mvn clean install -DskipTests
Spotted a mistake? Questions? Suggestions?