|
| 1 | +# Playwright Automated Testing Framework |
| 2 | + |
| 3 | +[](https://github.com/cmccarthyIrl/playwright-java-test-harness/actions/workflows/run.yml) |
| 4 | + |
| 5 | +# Index |
| 6 | +<table> |
| 7 | +<tr> |
| 8 | + <th>Start</th> |
| 9 | + <td> |
| 10 | + | <a href="#maven">Maven</a> |
| 11 | + | <a href="#quickstart">Quickstart</a> | |
| 12 | + </td> |
| 13 | +</tr> |
| 14 | +<tr> |
| 15 | + <th>Run</th> |
| 16 | + <td> |
| 17 | + | <a href="#command-line">Command Line</a> |
| 18 | + | <a href="#ide-support">IDE Support</a> |
| 19 | + | <a href="#java-jdk">Java JDK</a> |
| 20 | + | <a href="#troubleshooting">Troubleshooting</a> | |
| 21 | + | <a href="#environment-switching">Environment Switching</a> |
| 22 | + </td> |
| 23 | +</tr> |
| 24 | +<tr> |
| 25 | + <th>Report</th> |
| 26 | + <td> |
| 27 | + | <a href="#configuration">Configuration</a> |
| 28 | + | <a href="#logging">Logging</a> | |
| 29 | + </td> |
| 30 | +</tr> |
| 31 | +<tr> |
| 32 | + <th>Advanced</th> |
| 33 | + <td> |
| 34 | + | <a href="#contributing">Contributing</a> | |
| 35 | + </td> |
| 36 | +</tr> |
| 37 | +</table> |
| 38 | + |
| 39 | +# Playwright Java Test Harness |
| 40 | + |
| 41 | +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. |
| 42 | + |
| 43 | +# Maven |
| 44 | + |
| 45 | +The Framework uses [Playwright](https://spring.io/guides/gs/testing-web/) and [TestNG](https://testng.org/) client implementations. |
| 46 | + |
| 47 | +```xml |
| 48 | + <dependency> |
| 49 | + <groupId>com.microsoft.playwright</groupId> |
| 50 | + <artifactId>playwright</artifactId> |
| 51 | + <version>1.49.0</version> |
| 52 | + </dependency> |
| 53 | + |
| 54 | + <dependency> |
| 55 | + <groupId>org.testng</groupId> |
| 56 | + <artifactId>testng</artifactId> |
| 57 | + <version>7.10.2</version> |
| 58 | + </dependency> |
| 59 | +``` |
| 60 | + |
| 61 | +# Quickstart |
| 62 | + |
| 63 | +- [Intellij IDE](https://www.jetbrains.com/idea/) - `Recommended` |
| 64 | +- [Java JDK 17](https://jdk.java.net/java-se-ri/11) |
| 65 | +- [Apache Maven](https://maven.apache.org/docs/3.6.3/release-notes.html) |
| 66 | + |
| 67 | +# Command Line |
| 68 | + |
| 69 | +Normally you will use your IDE to run a test via the `*Test.java` class. With the `Test` class, |
| 70 | +we can run tests from the command-line as well. |
| 71 | + |
| 72 | +Note that the `mvn test` command only runs test classes that follow the `*Test.java` naming convention. |
| 73 | + |
| 74 | +You can run a single test or a suite or tests like so : |
| 75 | + |
| 76 | +``` |
| 77 | +mvn test -Dtest=UITest |
| 78 | +``` |
| 79 | + |
| 80 | +Note that the `mvn clean install` command runs all test Classes that follow the `*Test.java` naming convention |
| 81 | + |
| 82 | +``` |
| 83 | +mvn clean install |
| 84 | +``` |
| 85 | + |
| 86 | +# IDE Support |
| 87 | + |
| 88 | +To minimize the discrepancies between IDE versions and Locales the `<sourceEncoding>` is set to `UTF-8` |
| 89 | + |
| 90 | +```xml |
| 91 | + |
| 92 | +<properties> |
| 93 | + ... |
| 94 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| 95 | + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> |
| 96 | + ... |
| 97 | +</properties> |
| 98 | +``` |
| 99 | + |
| 100 | +# Environment Switching |
| 101 | + |
| 102 | +You can specify the profile to use when running Maven from the command line like so: |
| 103 | + |
| 104 | +``` |
| 105 | +mvn clean test -Ptest |
| 106 | +``` |
| 107 | + |
| 108 | +Example of a maven profile |
| 109 | +```xml |
| 110 | + |
| 111 | +<profiles> |
| 112 | + ... |
| 113 | + <profile> |
| 114 | + <id>test</id> |
| 115 | + <properties> |
| 116 | + <config.file>config-test.properties</config.file> |
| 117 | + </properties> |
| 118 | + </profile> |
| 119 | + ... |
| 120 | +</profiles> |
| 121 | +``` |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | +# Java JDK |
| 126 | + |
| 127 | +The Java version to use is defined in the `maven-compiler-plugin` |
| 128 | + |
| 129 | +```xml |
| 130 | + |
| 131 | +<build> |
| 132 | + ... |
| 133 | + <pluginManagement> |
| 134 | + <plugins> |
| 135 | + ... |
| 136 | + <plugin> |
| 137 | + <groupId>org.apache.maven.plugins</groupId> |
| 138 | + <artifactId>maven-compiler-plugin</artifactId> |
| 139 | + <configuration> |
| 140 | + <source>17</source> |
| 141 | + <target>17</target> |
| 142 | + </configuration> |
| 143 | + </plugin> |
| 144 | + ... |
| 145 | + </plugins> |
| 146 | + </pluginManagement> |
| 147 | + ... |
| 148 | +</build> |
| 149 | +``` |
| 150 | + |
| 151 | +# Logging |
| 152 | + |
| 153 | +The Framework uses [SLF4J](https://www.slf4j.org/) You can instantiate the logging service in any Class |
| 154 | +like so |
| 155 | + |
| 156 | +```java |
| 157 | +private static final LogManager log = new LogManager(UITest.class); |
| 158 | +``` |
| 159 | + |
| 160 | +you can then use the logger like so : |
| 161 | + |
| 162 | +```java |
| 163 | +logger.info("This is a info message"); |
| 164 | +logger.warn("This is a warning message"); |
| 165 | +logger.debug("This is a info message"); |
| 166 | +logger.error("This is a error message"); |
| 167 | +``` |
| 168 | + |
| 169 | + |
| 170 | +# Extent Reports |
| 171 | + |
| 172 | +The Framework uses [Extent Reports Framework](https://extentreports.com/) to generate the HTML Test Reports |
| 173 | + |
| 174 | +The example below is a report generated automatically by Extent Reports open-source library. |
| 175 | + |
| 176 | +<img src="https://github.com/cmccarthyIrl/playwright-java-test-harness/blob/main/common/src/main/java/com/cmccarthyirl/common/demo/playwright-extent-report.png" height="400px"/> |
| 177 | + |
| 178 | + |
| 179 | +# License |
| 180 | +This project is open source and available under the [MIT License](https://github.com/cmccarthyIrl/playwright-java-test-harness/blob/main/LICENSE). |
| 181 | + |
| 182 | +# Troubleshooting |
| 183 | + |
| 184 | +- Execute the following commands to resolve any dependency issues |
| 185 | + 1. `cd ~/install directory path/playwright-java-test-harness` |
| 186 | + 2. `mvn clean install -DskipTests` |
| 187 | + |
| 188 | +# Contributing |
| 189 | + |
| 190 | +Spotted a mistake? Questions? Suggestions? |
| 191 | + |
| 192 | +[Open an Issue](https://github.com/cmccarthyIrl/playwright-java-test-harness/issues) |
| 193 | + |
0 commit comments