├── .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 /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | custom: ['https://www.buymeacoffee.com/tahanima'] 2 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "gradle" 9 | directory: "/" 10 | schedule: 11 | interval: "daily" 12 | - package-ecosystem: github-actions 13 | directory: "/" 14 | schedule: 15 | interval: "daily" 16 | -------------------------------------------------------------------------------- /.github/workflows/test-execution.yml: -------------------------------------------------------------------------------- 1 | name: Playwright Java CI 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v4 16 | - name: Set up JDK 11 17 | uses: actions/setup-java@v4 18 | with: 19 | java-version: '11' 20 | distribution: 'temurin' 21 | - name: Grant execute permission for gradlew 22 | run: chmod +x gradlew 23 | - name: Run Smoke Tests in Chromium 24 | run: ./gradlew test --info -Dgroups=smoke 25 | - name: Run Regression Tests in Chromium 26 | run: ./gradlew test --info -Dgroups=regression 27 | - name: Run Smoke Tests in Firefox 28 | run: ./gradlew test --info -Dbrowser=firefox -Dgroups=smoke 29 | - name: Run Regression Tests in Firefox 30 | run: ./gradlew test --info -Dbrowser=firefox -Dgroups=regression 31 | - name: Test marketplace action 32 | uses: simple-elf/allure-report-action@master 33 | if: always() 34 | id: allure-report 35 | with: 36 | allure_results: build/allure-results 37 | gh_pages: gh-pages 38 | allure_report: allure-report 39 | allure_history: allure-history 40 | - name: Deploy report to Github Pages 41 | if: always() 42 | uses: peaceiris/actions-gh-pages@v2 43 | env: 44 | PERSONAL_TOKEN: ${{ secrets.GITHUB_TOKEN }} 45 | PUBLISH_BRANCH: gh-pages 46 | PUBLISH_DIR: allure-history 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Gradle 2 | .gradle 3 | .gradletasknamecache 4 | .m2 5 | !gradle-wrapper.jar 6 | 7 | # Generated by build tool 8 | target/ 9 | build/ 10 | 11 | # Generated by IntelliJ IDEA 12 | out 13 | .idea 14 | *.ipr 15 | *.iws 16 | *.iml 17 | atlassian-ide-plugin.xml 18 | 19 | src/test/resources/testvideo/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Tahanima Chowdhury 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Playwright Java Test Automation Architecture 2 | 3 | Ready-to-use UI Test Automation Architecture using Java and Playwright. 4 | 5 | ## Features 6 | 7 | - Configuration-based architecture 8 | - Utilizes Page Objects and Page Component Objects 9 | - Data-Driven 10 | - Captures screenshot on test failure 11 | - Records video of test execution 12 | - Provides detailed test report 13 | - Supports parallel test execution 14 | 15 | ## Installation Steps 16 | 17 | In order to use the framework: 18 | 19 | 1. [Fork](https://github.com/Tahanima/playwright-java-test-automation-architecture/fork) the repository. 20 | 2. Clone, i.e, download your copy of the repository to your local machine using 21 | ``` 22 | git clone https://github.com/[your_username]/playwright-java-test-automation-architecture.git 23 | ``` 24 | 3. Import the project in [IntelliJ IDEA](https://www.jetbrains.com/idea/download/). 25 | 4. Make your desired changes. 26 | 5. 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. 27 | 6. Build and browse the allure report using 28 | ``` 29 | ./gradlew allureServe 30 | ``` 31 | 32 | ## Languages and Frameworks 33 | 34 | The project uses the following: 35 | - *[Java 11](https://openjdk.java.net/projects/jdk/11/)* as the programming language. 36 | - *[Playwright](https://playwright.dev/)* as the web browser automation framework using the Java binding. 37 | - *[Univocity Parsers](https://www.univocity.com/pages/univocity_parsers_tutorial)* to parse and handle CSV files. 38 | - *[JUnit 5](https://junit.org/junit5/)* as the testing framework. 39 | - *[Lombok](https://projectlombok.org/)* to generate getters. 40 | - *[Owner](http://owner.aeonbits.org/)* to minimize the code to handle properties file. 41 | - *[Allure Report](https://qameta.io/allure-report/)* as the test reporting strategy. 42 | - *[Gradle](https://gradle.org/)* as the Java build tool. 43 | - *[IntelliJ IDEA](https://www.jetbrains.com/idea/)* as the IDE. 44 | 45 | ## Project Structure 46 | 47 | The project is structured as follows: 48 | 49 | ```bash 50 | 📦 playwright-java-test-automation-architecture 51 | ├─ .github 52 | │  ├─ FUNDING.yml 53 | │  ├─ dependabot.yml 54 | │  └─ workflows 55 | │     └─ test-execution.yml 56 | ├─ .gitignore 57 | ├─ LICENSE 58 | ├─ README.md 59 | ├─ build.gradle 60 | ├─ gradle 61 | │  └─ wrapper 62 | │     ├─ gradle-wrapper.jar 63 | │     └─ gradle-wrapper.properties 64 | ├─ gradlew 65 | ├─ gradlew.bat 66 | ├─ settings.gradle 67 | └─ src 68 |    ├─ main 69 |    │  └─ java 70 |    │     └─ io 71 |    │        └─ github 72 |    │           └─ tahanima 73 |    │              ├─ config 74 |    │              │  ├─ Configuration.java 75 |    │              │  └─ ConfigurationManager.java 76 |    │              ├─ dto 77 |    │              │  ├─ BaseDto.java 78 |    │              │  ├─ LoginDto.java 79 |    │              │  └─ ProductsDto.java 80 |    │              ├─ factory 81 |    │              │  ├─ BasePageFactory.java 82 |    │              │  └─ BrowserFactory.java 83 |    │              ├─ ui 84 |    │              │  ├─ component 85 |    │              │  │  ├─ BaseComponent.java 86 |    │              │  │  ├─ Header.java 87 |    │              │  │  └─ SideNavMenu.java 88 |    │              │  └─ page 89 |    │              │     ├─ BasePage.java 90 |    │              │     ├─ LoginPage.java 91 |    │              │     └─ ProductsPage.java 92 |    │              └─ util 93 |    │                 └─ BrowserManager.java 94 |    └─ test 95 |       ├─ java 96 |       │  └─ io 97 |       │     └─ github 98 |       │        └─ tahanima 99 |       │           ├─ annotation 100 |       │           │  ├─ DataSource.java 101 |       │           │  ├─ Regression.java 102 |       │           │  ├─ Smoke.java 103 |       │           │  └─ Validation.java 104 |       │           ├─ e2e 105 |       │           │  ├─ BaseTest.java 106 |       │           │  ├─ LoginTest.java 107 |       │           │  └─ ProductsTest.java 108 |       │           └─ util 109 |       │              ├─ CsvToDtoMapper.java 110 |       │              └─ DataArgumentsProvider.java 111 |       └─ resources 112 |          ├─ allure.properties 113 |          ├─ config.properties 114 |          ├─ junit-platform.properties 115 |          └─ testdata 116 |             ├─ login.csv 117 |             └─ products.csv 118 | ``` 119 | 120 | ## Basic Usage 121 | 122 | - ### Configuration 123 | The project uses a [*config.properties*](./src/test/resources/config.properties) file to manage global configurations such as browser type and base url. 124 | 125 | 1. To add a new property, register a new entry in this file. 126 | ``` 127 | key=value 128 | ``` 129 | 130 | Then, add a method in the [*Configuration*](./src/main/java/io/github/tahanima/config/Configuration.java) interface in the below format. 131 | ```java 132 | @Key("key") 133 | dataType key(); 134 | ``` 135 | 136 | For example, let's say I want to add a new property named `context` with the value `dev`. In the `config.properties` file, I'll add: 137 | ``` 138 | context=dev 139 | ``` 140 | 141 | In the `Configuration` interface, I'll add: 142 | ```java 143 | @Key("context") 144 | String context(); 145 | ``` 146 | 147 | To use your newly created property, you need to use the below import statement. 148 | ```java 149 | import static io.github.tahanima.config.ConfigurationManager.config; 150 | ``` 151 | 152 | Then, you can call `config().key()` to retrieve the value of your newly created property. For the example I've provided, I need to call `config().context()`. 153 | 154 | 2. You can supply the properties present in the `config.properties` file as system properties in your test via gradle. 155 | ```bash 156 | ./gradlew test -Dkey1=value1 -Dkey2=value2 157 | ``` 158 | 159 | - ### Test Data 160 | The project uses *csv* file to store test data and [*univocity-parsers*](https://github.com/uniVocity/univocity-parsers) to retrieve the data and map it to a Java bean. 161 | 162 | To add configurations for new test data, add a new Java bean in the [*dto*](./src/main/java/io/github/tahanima/dto) package. For example, let's say I want to add test data for a `User` with the attributes `First Name` and `Last Name`. The code for this is as follows: 163 | 164 | ```java 165 | package io.github.tahanima.dto; 166 | 167 | import com.univocity.parsers.annotations.Parsed; 168 | 169 | import lombok.Getter; 170 | import lombok.ToString; 171 | 172 | @Getter 173 | @ToString(callSuper = true) 174 | public class UserDto extends BaseDto { 175 | 176 | @Parsed(field = "First Name", defaultNullRead = "") 177 | private String firstName; 178 | 179 | @Parsed(field = "Last Name", defaultNullRead = "") 180 | private String lastName; 181 | } 182 | ``` 183 | Note that the class extends from BaseDto and thus, inherits the attribute `Test Case ID`. 184 | 185 | Now, in the [*testdata*](./src/test/resources/testdata) folder you can add a csv file `user.csv` for `User` with the below contents and use it in your tests. 186 | ``` 187 | Test Case ID,First Name,Last Name 188 | TC-1,Tahanima,Chowdhury 189 | ``` 190 | For reference, check [this](./src/main/java/io/github/tahanima/dto/LoginDto.java), [this](./src/test/resources/testdata/login.csv) and [this](./src/test/java/io/github/tahanima/e2e/LoginTest.java). 191 | 192 | - ### Page Objects and Page Component Objects 193 | The project uses [*Page Objects* and *Page Component Objects*](https://www.selenium.dev/documentation/test_practices/encouraged/page_object_models/) to capture the relevant behaviors of a web page. Check the [*ui*](./src/main/java/io/github/tahanima/ui) package for reference. 194 | 195 | - ### Tests 196 | The project uses *JUnit 5* as the test runner. Check [this implementation](./src/test/java/io/github/tahanima/e2e/LoginTest.java) for reference. 197 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'io.qameta.allure' version '2.11.2' 4 | } 5 | 6 | group 'io.github.tahanima' 7 | version '1.0-SNAPSHOT' 8 | 9 | repositories { 10 | mavenCentral() 11 | } 12 | 13 | dependencies { 14 | implementation 'org.aeonbits.owner:owner:1.0.12' 15 | implementation 'com.univocity:univocity-parsers:2.9.1' 16 | implementation 'com.microsoft.playwright:playwright:1.43.0' 17 | implementation 'org.apache.commons:commons-lang3:3.14.0' 18 | implementation 'org.slf4j:slf4j-api:2.0.13' 19 | implementation 'io.qameta.allure:allure-junit-platform:2.27.0' 20 | implementation 'com.github.automatedowl:allure-environment-writer:1.0.0' 21 | 22 | compileOnly 'org.projectlombok:lombok:1.18.32' 23 | annotationProcessor 'org.projectlombok:lombok:1.18.32' 24 | testCompileOnly 'org.projectlombok:lombok:1.18.32' 25 | testAnnotationProcessor 'org.projectlombok:lombok:1.18.32' 26 | 27 | testImplementation platform('org.junit:junit-bom:5.10.2') 28 | testImplementation 'org.junit.jupiter:junit-jupiter' 29 | testImplementation 'io.github.artsok:rerunner-jupiter:2.1.6' 30 | testImplementation 'org.slf4j:slf4j-simple:2.0.13' 31 | } 32 | 33 | test { 34 | systemProperties = System.getProperties() as Map 35 | def group = System.getProperty('group', 'regression') 36 | 37 | useJUnitPlatform() { 38 | includeTags group 39 | } 40 | } 41 | 42 | tasks.register('playwright', JavaExec) { 43 | classpath = sourceSets.main.runtimeClasspath 44 | mainClass = 'com.microsoft.playwright.CLI' 45 | } 46 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tahanima/playwright-java-test-automation-architecture/ba50764dbf423e0caeb378fc97fe1051f339a5e0/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MSYS* | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'playwright-java-test-automation-architecture' 2 | 3 | -------------------------------------------------------------------------------- /src/main/java/io/github/tahanima/config/Configuration.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.config; 2 | 3 | import org.aeonbits.owner.Config; 4 | import org.aeonbits.owner.Config.LoadPolicy; 5 | import org.aeonbits.owner.Config.Sources; 6 | 7 | /** 8 | * @author tahanima 9 | */ 10 | @LoadPolicy(Config.LoadType.MERGE) 11 | @Sources({"system:properties", "classpath:config.properties", "classpath:allure.properties"}) 12 | public interface Configuration extends Config { 13 | 14 | @Key("allure.results.directory") 15 | String allureResultsDir(); 16 | 17 | @Key("base.url") 18 | String baseUrl(); 19 | 20 | @Key("base.test.data.path") 21 | String baseTestDataPath(); 22 | 23 | @Key("base.test.video.path") 24 | String baseTestVideoPath(); 25 | 26 | String browser(); 27 | 28 | boolean headless(); 29 | 30 | @Key("slow.motion") 31 | int slowMotion(); 32 | 33 | int timeout(); 34 | 35 | boolean video(); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/io/github/tahanima/config/ConfigurationManager.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.config; 2 | 3 | import org.aeonbits.owner.ConfigCache; 4 | 5 | /** 6 | * @author tahanima 7 | */ 8 | public final class ConfigurationManager { 9 | 10 | private ConfigurationManager() {} 11 | 12 | public static Configuration config() { 13 | return ConfigCache.getOrCreate(Configuration.class); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/io/github/tahanima/dto/BaseDto.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.dto; 2 | 3 | import com.univocity.parsers.annotations.Parsed; 4 | 5 | import lombok.Getter; 6 | import lombok.ToString; 7 | 8 | /** 9 | * @author tahanima 10 | */ 11 | @Getter 12 | @ToString 13 | public class BaseDto { 14 | 15 | @Parsed(field = "Test Case ID", defaultNullRead = "") 16 | private String testCaseId; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/io/github/tahanima/dto/LoginDto.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.dto; 2 | 3 | import com.univocity.parsers.annotations.Parsed; 4 | 5 | import lombok.Getter; 6 | import lombok.ToString; 7 | 8 | /** 9 | * @author tahanima 10 | */ 11 | @Getter 12 | @ToString(callSuper = true) 13 | public class LoginDto extends BaseDto { 14 | 15 | @Parsed(field = "Username", defaultNullRead = "") 16 | private String username; 17 | 18 | @Parsed(field = "Password", defaultNullRead = "") 19 | private String password; 20 | 21 | @Parsed(field = "Error Message", defaultNullRead = "") 22 | private String errorMessage; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/io/github/tahanima/dto/ProductsDto.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.dto; 2 | 3 | import com.univocity.parsers.annotations.Parsed; 4 | 5 | import lombok.Getter; 6 | import lombok.ToString; 7 | 8 | /** 9 | * @author tahanima 10 | */ 11 | @Getter 12 | @ToString(callSuper = true) 13 | public final class ProductsDto extends BaseDto { 14 | 15 | @Parsed(field = "Username", defaultNullRead = "") 16 | private String username; 17 | 18 | @Parsed(field = "Password", defaultNullRead = "") 19 | private String password; 20 | 21 | @Parsed(field = "URL", defaultNullRead = "") 22 | private String url; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/io/github/tahanima/factory/BasePageFactory.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.factory; 2 | 3 | import com.microsoft.playwright.Page; 4 | 5 | import io.github.tahanima.ui.page.BasePage; 6 | 7 | import lombok.extern.slf4j.Slf4j; 8 | 9 | /** 10 | * @author tahanima 11 | */ 12 | @Slf4j 13 | public final class BasePageFactory { 14 | 15 | private BasePageFactory() {} 16 | 17 | public static T createInstance(final Page page, final Class clazz) { 18 | try { 19 | BasePage instance = clazz.getDeclaredConstructor().newInstance(); 20 | 21 | instance.setAndConfigurePage(page); 22 | instance.initComponents(); 23 | 24 | return clazz.cast(instance); 25 | } catch (Exception e) { 26 | log.error("BasePageFactory::createInstance", e); 27 | } 28 | 29 | throw new NullPointerException("Page class instantiation failed."); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/io/github/tahanima/factory/BrowserFactory.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.factory; 2 | 3 | import static io.github.tahanima.config.ConfigurationManager.config; 4 | 5 | import com.microsoft.playwright.Browser; 6 | import com.microsoft.playwright.BrowserType; 7 | import com.microsoft.playwright.BrowserType.LaunchOptions; 8 | import com.microsoft.playwright.Playwright; 9 | 10 | /** 11 | * @author tahanima 12 | */ 13 | public enum BrowserFactory { 14 | 15 | CHROMIUM { 16 | @Override 17 | public Browser createInstance(final Playwright playwright) { 18 | return playwright.chromium().launch(options()); 19 | } 20 | }, 21 | FIREFOX { 22 | @Override 23 | public Browser createInstance(final Playwright playwright) { 24 | return playwright.firefox().launch(options()); 25 | } 26 | }, 27 | WEBKIT { 28 | @Override 29 | public Browser createInstance(final Playwright playwright) { 30 | return playwright.webkit().launch(options()); 31 | } 32 | }; 33 | 34 | public LaunchOptions options() { 35 | return new BrowserType.LaunchOptions() 36 | .setHeadless(config().headless()) 37 | .setSlowMo(config().slowMotion()); 38 | } 39 | 40 | public abstract Browser createInstance(final Playwright playwright); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/io/github/tahanima/ui/component/BaseComponent.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.ui.component; 2 | 3 | import com.microsoft.playwright.Page; 4 | 5 | /** 6 | * @author tahanima 7 | */ 8 | public abstract class BaseComponent { 9 | 10 | protected Page page; 11 | 12 | protected BaseComponent(final Page page) { 13 | this.page = page; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/io/github/tahanima/ui/component/Header.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.ui.component; 2 | 3 | import com.microsoft.playwright.Page; 4 | 5 | /** 6 | * @author tahanima 7 | */ 8 | public final class Header extends BaseComponent { 9 | 10 | public Header(final Page page) { 11 | super(page); 12 | } 13 | 14 | public void clickOnHamburgerIcon() { 15 | page.click("#react-burger-menu-btn"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/io/github/tahanima/ui/component/SideNavMenu.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.ui.component; 2 | 3 | import com.microsoft.playwright.Page; 4 | 5 | /** 6 | * @author tahanima 7 | */ 8 | public final class SideNavMenu extends BaseComponent { 9 | 10 | public SideNavMenu(final Page page) { 11 | super(page); 12 | } 13 | 14 | public void clickOnLogout() { 15 | page.click("#logout_sidebar_link"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/io/github/tahanima/ui/page/BasePage.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.ui.page; 2 | 3 | import static io.github.tahanima.config.ConfigurationManager.config; 4 | 5 | import com.microsoft.playwright.Page; 6 | 7 | import io.qameta.allure.Step; 8 | 9 | /** 10 | * @author tahanima 11 | */ 12 | public abstract class BasePage { 13 | 14 | protected Page page; 15 | 16 | public void setAndConfigurePage(final Page page) { 17 | this.page = page; 18 | 19 | page.setDefaultTimeout(config().timeout()); 20 | } 21 | 22 | public void initComponents() {} 23 | 24 | @Step 25 | public byte[] captureScreenshot() { 26 | return page.screenshot(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/io/github/tahanima/ui/page/LoginPage.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.ui.page; 2 | 3 | import static io.github.tahanima.config.ConfigurationManager.config; 4 | 5 | import com.microsoft.playwright.Locator; 6 | 7 | import io.github.tahanima.factory.BasePageFactory; 8 | import io.qameta.allure.Step; 9 | 10 | /** 11 | * @author tahanima 12 | */ 13 | public final class LoginPage extends BasePage { 14 | 15 | @Step("Navigate to the login page") 16 | public LoginPage open() { 17 | page.navigate(config().baseUrl()); 18 | 19 | return this; 20 | } 21 | 22 | @Step("Type into 'Username' textbox") 23 | public LoginPage typeUsername(final String username) { 24 | page.fill("id=user-name", username); 25 | 26 | return this; 27 | } 28 | 29 | @Step("Type into 'Password' textbox") 30 | public LoginPage typePassword(final String password) { 31 | page.fill("id=password", password); 32 | 33 | return this; 34 | } 35 | 36 | @Step("Get error message") 37 | public Locator getErrorMessage() { 38 | return page.locator(".error-message-container h3"); 39 | } 40 | 41 | @Step("Click on the 'Login' button") 42 | public ProductsPage submitLogin() { 43 | page.click("id=login-button"); 44 | 45 | return BasePageFactory.createInstance(page, ProductsPage.class); 46 | } 47 | 48 | @Step("Login attempt to Swag Labs") 49 | public ProductsPage loginAs(final String username, final String password) { 50 | open(); 51 | typeUsername(username); 52 | typePassword(password); 53 | 54 | return submitLogin(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/io/github/tahanima/ui/page/ProductsPage.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.ui.page; 2 | 3 | import com.microsoft.playwright.Locator; 4 | 5 | import io.github.tahanima.factory.BasePageFactory; 6 | import io.github.tahanima.ui.component.Header; 7 | import io.github.tahanima.ui.component.SideNavMenu; 8 | import io.qameta.allure.Step; 9 | 10 | /** 11 | * @author tahanima 12 | */ 13 | public final class ProductsPage extends BasePage { 14 | 15 | private Header header; 16 | private SideNavMenu sideNavMenu; 17 | 18 | @Override 19 | public void initComponents() { 20 | header = new Header(page); 21 | sideNavMenu = new SideNavMenu(page); 22 | } 23 | 24 | @Step("Get title of the 'Products' page") 25 | public Locator getTitle() { 26 | return page.locator(".title"); 27 | } 28 | 29 | @Step("Click on 'Logout' button from side navigation menu") 30 | public LoginPage clickOnLogout() { 31 | header.clickOnHamburgerIcon(); 32 | sideNavMenu.clickOnLogout(); 33 | 34 | return BasePageFactory.createInstance(page, LoginPage.class); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/io/github/tahanima/util/BrowserManager.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.util; 2 | 3 | import static io.github.tahanima.config.ConfigurationManager.config; 4 | 5 | import com.microsoft.playwright.Browser; 6 | import com.microsoft.playwright.Playwright; 7 | 8 | import io.github.tahanima.factory.BrowserFactory; 9 | 10 | /** 11 | * @author tahanima 12 | */ 13 | public final class BrowserManager { 14 | 15 | private BrowserManager() {} 16 | 17 | public static Browser getBrowser(final Playwright playwright) { 18 | return BrowserFactory.valueOf(config().browser().toUpperCase()).createInstance(playwright); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/io/github/tahanima/annotation/DataSource.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.annotation; 2 | 3 | import io.github.tahanima.dto.BaseDto; 4 | import io.github.tahanima.util.DataArgumentsProvider; 5 | 6 | import org.junit.jupiter.params.provider.ArgumentsSource; 7 | 8 | import java.lang.annotation.*; 9 | 10 | /** 11 | * @author tahanima 12 | */ 13 | @Documented 14 | @Target(ElementType.METHOD) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @ArgumentsSource(DataArgumentsProvider.class) 17 | public @interface DataSource { 18 | 19 | String id(); 20 | 21 | String fileName(); 22 | 23 | Class clazz(); 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/io/github/tahanima/annotation/Regression.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.annotation; 2 | 3 | import org.junit.jupiter.api.Tag; 4 | 5 | import java.lang.annotation.*; 6 | 7 | /** 8 | * @author tahanima 9 | */ 10 | @Documented 11 | @Target({ElementType.TYPE, ElementType.METHOD}) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Tag("regression") 14 | public @interface Regression {} 15 | -------------------------------------------------------------------------------- /src/test/java/io/github/tahanima/annotation/Smoke.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.annotation; 2 | 3 | import org.junit.jupiter.api.Tag; 4 | 5 | import java.lang.annotation.*; 6 | 7 | /** 8 | * @author tahanima 9 | */ 10 | @Documented 11 | @Target(ElementType.METHOD) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Regression 14 | @Tag("smoke") 15 | public @interface Smoke {} 16 | -------------------------------------------------------------------------------- /src/test/java/io/github/tahanima/annotation/Validation.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.annotation; 2 | 3 | import org.junit.jupiter.api.Tag; 4 | 5 | import java.lang.annotation.*; 6 | 7 | /** 8 | * @author tahanima 9 | */ 10 | @Documented 11 | @Target(ElementType.METHOD) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Regression 14 | @Tag("validation") 15 | public @interface Validation {} 16 | -------------------------------------------------------------------------------- /src/test/java/io/github/tahanima/e2e/BaseTest.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.e2e; 2 | 3 | import static com.github.automatedowl.tools.AllureEnvironmentWriter.allureEnvironmentWriter; 4 | 5 | import static io.github.tahanima.config.ConfigurationManager.config; 6 | 7 | import static org.junit.jupiter.api.TestInstance.*; 8 | 9 | import com.google.common.collect.ImmutableMap; 10 | import com.microsoft.playwright.Browser; 11 | import com.microsoft.playwright.BrowserContext; 12 | import com.microsoft.playwright.Page; 13 | import com.microsoft.playwright.Playwright; 14 | 15 | import io.github.tahanima.factory.BasePageFactory; 16 | import io.github.tahanima.ui.page.BasePage; 17 | import io.github.tahanima.ui.page.LoginPage; 18 | import io.github.tahanima.util.BrowserManager; 19 | 20 | import org.apache.commons.lang3.StringUtils; 21 | import org.junit.jupiter.api.*; 22 | import org.junit.jupiter.api.extension.AfterTestExecutionCallback; 23 | import org.junit.jupiter.api.extension.RegisterExtension; 24 | 25 | import java.util.Optional; 26 | 27 | /** 28 | * @author tahanima 29 | */ 30 | @TestInstance(Lifecycle.PER_CLASS) 31 | public abstract class BaseTest { 32 | 33 | protected Playwright playwright; 34 | protected Browser browser; 35 | protected BrowserContext browserContext; 36 | protected Page page; 37 | protected LoginPage loginPage; 38 | 39 | @RegisterExtension 40 | AfterTestExecutionCallback callback = 41 | context -> { 42 | Optional exception = context.getExecutionException(); 43 | 44 | if (exception.isPresent()) { 45 | captureScreenshotOnFailure(); 46 | } 47 | }; 48 | 49 | protected abstract byte[] captureScreenshotOnFailure(); 50 | 51 | protected T createInstance(Class basePage) { 52 | return BasePageFactory.createInstance(page, basePage); 53 | } 54 | 55 | @BeforeAll 56 | public void createPlaywrightAndBrowserInstancesAndSetupAllureEnvironment() { 57 | playwright = Playwright.create(); 58 | browser = BrowserManager.getBrowser(playwright); 59 | 60 | allureEnvironmentWriter( 61 | ImmutableMap.builder() 62 | .put("Platform", System.getProperty("os.name")) 63 | .put("Version", System.getProperty("os.version")) 64 | .put("Browser", StringUtils.capitalize(config().browser())) 65 | .put("Context URL", config().baseUrl()) 66 | .build(), 67 | config().allureResultsDir() + "/"); 68 | } 69 | 70 | @AfterAll 71 | public void closeBrowserAndPlaywrightSessions() { 72 | browser.close(); 73 | playwright.close(); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/io/github/tahanima/e2e/LoginTest.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.e2e; 2 | 3 | import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat; 4 | 5 | import static io.github.tahanima.config.ConfigurationManager.config; 6 | 7 | import com.microsoft.playwright.Browser; 8 | 9 | import io.github.artsok.ParameterizedRepeatedIfExceptionsTest; 10 | import io.github.tahanima.annotation.DataSource; 11 | import io.github.tahanima.annotation.Smoke; 12 | import io.github.tahanima.annotation.Validation; 13 | import io.github.tahanima.dto.LoginDto; 14 | import io.github.tahanima.ui.page.LoginPage; 15 | import io.github.tahanima.ui.page.ProductsPage; 16 | import io.qameta.allure.*; 17 | 18 | import org.junit.jupiter.api.AfterEach; 19 | import org.junit.jupiter.api.BeforeEach; 20 | import org.junit.jupiter.api.TestInfo; 21 | 22 | import java.nio.file.Paths; 23 | 24 | /** 25 | * @author tahanima 26 | */ 27 | @Feature("Login Test") 28 | public class LoginTest extends BaseTest { 29 | 30 | private static final String CSV_PATH = "login.csv"; 31 | private static final String VIDEO_PATH = "login/"; 32 | 33 | @BeforeEach 34 | public void createBrowserContextAndPageAndLoginPageInstances(TestInfo testInfo) { 35 | String testMethodName = 36 | (testInfo.getTestMethod().isPresent()) 37 | ? testInfo.getTestMethod().get().getName() 38 | : ""; 39 | 40 | if (config().video()) { 41 | browserContext = 42 | browser.newContext( 43 | new Browser.NewContextOptions() 44 | .setRecordVideoDir( 45 | Paths.get( 46 | config().baseTestVideoPath() 47 | + VIDEO_PATH 48 | + testMethodName))); 49 | } else { 50 | browserContext = browser.newContext(); 51 | } 52 | 53 | page = browserContext.newPage(); 54 | loginPage = createInstance(LoginPage.class); 55 | } 56 | 57 | @Attachment(value = "Failed Test Case Screenshot", type = "image/png") 58 | protected byte[] captureScreenshotOnFailure() { 59 | return loginPage.captureScreenshot(); 60 | } 61 | 62 | @AfterEach 63 | public void closeBrowserContextSession() { 64 | browserContext.close(); 65 | } 66 | 67 | @Smoke 68 | @Story("User enters correct login credentials") 69 | @Owner("Tahanima Chowdhury") 70 | @Description( 71 | "Test that verifies user gets redirected to 'Products' page after submitting correct login credentials") 72 | @ParameterizedRepeatedIfExceptionsTest 73 | @DataSource(id = "TC-1", fileName = CSV_PATH, clazz = LoginDto.class) 74 | public void testCorrectLoginCredentials(final LoginDto data) { 75 | ProductsPage productsPage = loginPage.loginAs(data.getUsername(), data.getPassword()); 76 | 77 | assertThat(productsPage.getTitle()).hasText("Products"); 78 | } 79 | 80 | @Validation 81 | @Story("User enters incorrect login credentials") 82 | @Owner("Tahanima Chowdhury") 83 | @Description( 84 | "Test that verifies user gets error message after submitting incorrect login credentials") 85 | @ParameterizedRepeatedIfExceptionsTest 86 | @DataSource(id = "TC-2", fileName = CSV_PATH, clazz = LoginDto.class) 87 | public void testIncorrectLoginCredentials(final LoginDto data) { 88 | loginPage.loginAs(data.getUsername(), data.getPassword()); 89 | 90 | assertThat(loginPage.getErrorMessage()).hasText(data.getErrorMessage()); 91 | } 92 | 93 | @Validation 94 | @Story("User keeps the username blank") 95 | @Owner("Tahanima Chowdhury") 96 | @Description( 97 | "Test that verifies user gets error message after submitting login credentials where the username is blank") 98 | @ParameterizedRepeatedIfExceptionsTest 99 | @DataSource(id = "TC-3", fileName = CSV_PATH, clazz = LoginDto.class) 100 | public void testBlankUserName(final LoginDto data) { 101 | loginPage.open().typePassword(data.getPassword()).submitLogin(); 102 | 103 | assertThat(loginPage.getErrorMessage()).hasText(data.getErrorMessage()); 104 | } 105 | 106 | @Validation 107 | @Story("User keeps the password blank") 108 | @Owner("Tahanima Chowdhury") 109 | @Description( 110 | "Test that verifies user gets error message after submitting login credentials where the password is blank") 111 | @ParameterizedRepeatedIfExceptionsTest 112 | @DataSource(id = "TC-4", fileName = CSV_PATH, clazz = LoginDto.class) 113 | public void testBlankPassword(final LoginDto data) { 114 | loginPage.open().typeUsername(data.getUsername()).submitLogin(); 115 | 116 | assertThat(loginPage.getErrorMessage()).hasText(data.getErrorMessage()); 117 | } 118 | 119 | @Validation 120 | @Story("User is locked out") 121 | @Owner("Tahanima Chowdhury") 122 | @Description( 123 | "Test that verifies user gets error message after submitting login credentials for locked out user") 124 | @ParameterizedRepeatedIfExceptionsTest 125 | @DataSource(id = "TC-5", fileName = CSV_PATH, clazz = LoginDto.class) 126 | public void testLockedOutUser(final LoginDto data) { 127 | loginPage.loginAs(data.getUsername(), data.getPassword()); 128 | 129 | assertThat(loginPage.getErrorMessage()).hasText(data.getErrorMessage()); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/test/java/io/github/tahanima/e2e/ProductsTest.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.e2e; 2 | 3 | import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat; 4 | 5 | import static io.github.tahanima.config.ConfigurationManager.config; 6 | 7 | import com.microsoft.playwright.Browser; 8 | 9 | import io.github.artsok.ParameterizedRepeatedIfExceptionsTest; 10 | import io.github.tahanima.annotation.DataSource; 11 | import io.github.tahanima.annotation.Smoke; 12 | import io.github.tahanima.dto.ProductsDto; 13 | import io.github.tahanima.ui.page.LoginPage; 14 | import io.qameta.allure.*; 15 | 16 | import org.junit.jupiter.api.AfterEach; 17 | import org.junit.jupiter.api.BeforeEach; 18 | import org.junit.jupiter.api.TestInfo; 19 | 20 | import java.nio.file.Paths; 21 | 22 | /** 23 | * @author tahanima 24 | */ 25 | @Feature("Products Test") 26 | public class ProductsTest extends BaseTest { 27 | 28 | private static final String CSV_PATH = "products.csv"; 29 | private static final String VIDEO_PATH = "products/"; 30 | 31 | @BeforeEach 32 | public void createBrowserContextAndPageAndLoginPageInstances(TestInfo testInfo) { 33 | String testMethodName = 34 | (testInfo.getTestMethod().isPresent()) 35 | ? testInfo.getTestMethod().get().getName() 36 | : ""; 37 | 38 | if (config().video()) { 39 | browserContext = 40 | browser.newContext( 41 | new Browser.NewContextOptions() 42 | .setRecordVideoDir( 43 | Paths.get( 44 | config().baseTestVideoPath() 45 | + VIDEO_PATH 46 | + testMethodName))); 47 | } else { 48 | browserContext = browser.newContext(); 49 | } 50 | 51 | page = browserContext.newPage(); 52 | loginPage = createInstance(LoginPage.class); 53 | } 54 | 55 | @Attachment(value = "Failed Test Case Screenshot", type = "image/png") 56 | protected byte[] captureScreenshotOnFailure() { 57 | return loginPage.captureScreenshot(); 58 | } 59 | 60 | @AfterEach 61 | public void closeBrowserContextSession() { 62 | browserContext.close(); 63 | } 64 | 65 | @Smoke 66 | @Story("Logging out from Products page should redirect to Login page") 67 | @Owner("Tahanima Chowdhury") 68 | @Description("Test that verifies user gets redirected to 'Login' page after logging out") 69 | @ParameterizedRepeatedIfExceptionsTest 70 | @DataSource(id = "TC-1", fileName = CSV_PATH, clazz = ProductsDto.class) 71 | public void testSuccessfulLogout(final ProductsDto data) { 72 | loginPage.loginAs(data.getUsername(), data.getPassword()).clickOnLogout(); 73 | 74 | assertThat(page).hasURL(data.getUrl()); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/test/java/io/github/tahanima/util/CsvToDtoMapper.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.util; 2 | 3 | import com.univocity.parsers.csv.CsvParserSettings; 4 | import com.univocity.parsers.csv.CsvRoutines; 5 | 6 | import io.github.tahanima.dto.BaseDto; 7 | 8 | import lombok.extern.slf4j.Slf4j; 9 | 10 | import java.io.FileInputStream; 11 | import java.io.IOException; 12 | import java.io.InputStreamReader; 13 | import java.nio.charset.StandardCharsets; 14 | import java.util.ArrayList; 15 | 16 | /** 17 | * @author tahanima 18 | */ 19 | @Slf4j 20 | public final class CsvToDtoMapper { 21 | 22 | private CsvToDtoMapper() {} 23 | 24 | public static Object[] map( 25 | final Class clazz, final String fileName, final String id) { 26 | var settings = new CsvParserSettings(); 27 | 28 | settings.getFormat().setLineSeparator("\n"); 29 | settings.trimValues(false); 30 | 31 | var routines = new CsvRoutines(settings); 32 | 33 | try (var reader = 34 | new InputStreamReader(new FileInputStream(fileName), StandardCharsets.UTF_8)) { 35 | ArrayList testData = new ArrayList<>(); 36 | 37 | routines.iterate(clazz, reader) 38 | .forEach( 39 | e -> { 40 | if (e.getTestCaseId().equals(id)) testData.add(e); 41 | }); 42 | 43 | return testData.toArray(); 44 | } catch (IOException e) { 45 | log.error("CsvToDtoMapper::map", e); 46 | } 47 | 48 | throw new NullPointerException("Couldn't provide test data"); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/io/github/tahanima/util/DataArgumentsProvider.java: -------------------------------------------------------------------------------- 1 | package io.github.tahanima.util; 2 | 3 | import static io.github.tahanima.config.ConfigurationManager.config; 4 | 5 | import io.github.tahanima.annotation.DataSource; 6 | import io.github.tahanima.dto.BaseDto; 7 | 8 | import org.junit.jupiter.api.extension.ExtensionContext; 9 | import org.junit.jupiter.params.provider.Arguments; 10 | import org.junit.jupiter.params.provider.ArgumentsProvider; 11 | import org.junit.jupiter.params.support.AnnotationConsumer; 12 | 13 | import java.util.stream.Stream; 14 | 15 | /** 16 | * @author tahanima 17 | */ 18 | public class DataArgumentsProvider implements ArgumentsProvider, AnnotationConsumer { 19 | 20 | private String id; 21 | private String fileName; 22 | private Class clazz; 23 | 24 | @Override 25 | public void accept(final DataSource source) { 26 | id = source.id(); 27 | fileName = config().baseTestDataPath() + source.fileName(); 28 | clazz = source.clazz(); 29 | } 30 | 31 | @Override 32 | public Stream provideArguments(final ExtensionContext context) { 33 | return Stream.of(CsvToDtoMapper.map(clazz, fileName, id)).map(Arguments::of); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/resources/allure.properties: -------------------------------------------------------------------------------- 1 | allure.results.directory=build/allure-results -------------------------------------------------------------------------------- /src/test/resources/config.properties: -------------------------------------------------------------------------------- 1 | base.url=https://www.saucedemo.com/ 2 | base.test.data.path=src/test/resources/testdata/ 3 | base.test.video.path=src/test/resources/testvideo/ 4 | browser=chromium 5 | headless=true 6 | slow.motion=50 7 | timeout=10000 8 | video=true -------------------------------------------------------------------------------- /src/test/resources/junit-platform.properties: -------------------------------------------------------------------------------- 1 | junit.jupiter.execution.parallel.enabled=true 2 | junit.jupiter.execution.parallel.mode.default=same_thread 3 | junit.jupiter.execution.parallel.mode.classes.default=concurrent 4 | junit.jupiter.execution.parallel.config.strategy=dynamic 5 | junit.jupiter.execution.parallel.config.dynamic.factor=0.5 -------------------------------------------------------------------------------- /src/test/resources/testdata/login.csv: -------------------------------------------------------------------------------- 1 | Test Case ID,Username,Password,Error Message 2 | TC-1,standard_user,secret_sauce, 3 | TC-1,problem_user,secret_sauce, 4 | TC-1,performance_glitch_user,secret_sauce, 5 | TC-2,username,secret_sauce,Epic sadface: Username and password do not match any user in this service 6 | TC-2,standard_user,password,Epic sadface: Username and password do not match any user in this service 7 | TC-2,locked_out_user,password,Epic sadface: Username and password do not match any user in this service 8 | TC-2,problem_user,password,Epic sadface: Username and password do not match any user in this service 9 | TC-2,performance_glitch_user,password,Epic sadface: Username and password do not match any user in this service 10 | TC-2,demo_username,demo_password,Epic sadface: Username and password do not match any user in this service 11 | TC-3,,demo_password,Epic sadface: Username is required 12 | TC-4,demo_username,,Epic sadface: Password is required 13 | TC-5,locked_out_user,secret_sauce,"Epic sadface: Sorry, this user has been locked out." -------------------------------------------------------------------------------- /src/test/resources/testdata/products.csv: -------------------------------------------------------------------------------- 1 | Test Case ID,Username,Password,URL 2 | TC-1,standard_user,secret_sauce,https://www.saucedemo.com/ --------------------------------------------------------------------------------