From 41f8cbc8a1d03b2e77c7bbb37aa7eddf5f40fa8f Mon Sep 17 00:00:00 2001 From: Muhammad Mujtaba Afzal Date: Thu, 30 Mar 2023 01:06:57 +0500 Subject: [PATCH 1/8] Create maven.yml --- .github/workflows/maven.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..adf8362 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,33 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Java CI with Maven + +on: + push: + branches: [ "configure-ci" ] + pull_request: + branches: [ "configure-ci" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 18 + uses: actions/setup-java@v3 + with: + java-version: '18' + - name: Build with Maven + run: mvn test --file pom.xml + + # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive + - name: Update dependency graph + uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 From 8a74e2328dc98482dea72018f2f1902e18c07fd0 Mon Sep 17 00:00:00 2001 From: bitsplz Date: Thu, 30 Mar 2023 01:18:57 +0500 Subject: [PATCH 2/8] added webdriver manager and jdk distribution in maven.yml --- .github/workflows/maven.yml | 1 + pom.xml | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index adf8362..4bccec2 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -25,6 +25,7 @@ jobs: uses: actions/setup-java@v3 with: java-version: '18' + distribution: 'temurin' - name: Build with Maven run: mvn test --file pom.xml diff --git a/pom.xml b/pom.xml index fdf3d31..121c7fe 100644 --- a/pom.xml +++ b/pom.xml @@ -28,11 +28,11 @@ 7.7.0 test - + - com.epam.healenium - healenium-web - 3.3.1 + io.github.bonigarcia + webdrivermanager + 5.3.2 From 5ad8633a9158d46ac7e59a83003eca9eacd95a33 Mon Sep 17 00:00:00 2001 From: bitsplz Date: Thu, 30 Mar 2023 01:19:48 +0500 Subject: [PATCH 3/8] added webdriver manager and jdk distribution in maven.yml --- src/test/java/tests/SwagLabs/BaseTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/tests/SwagLabs/BaseTest.java b/src/test/java/tests/SwagLabs/BaseTest.java index aaeccfa..ddccbb8 100644 --- a/src/test/java/tests/SwagLabs/BaseTest.java +++ b/src/test/java/tests/SwagLabs/BaseTest.java @@ -1,5 +1,6 @@ package tests.SwagLabs; +import io.github.bonigarcia.wdm.WebDriverManager; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; @@ -19,10 +20,10 @@ public class BaseTest { @BeforeClass public void setupBeforeTest(){ + WebDriverManager.chromedriver().setup(); this.options = new ChromeOptions(); this.options.addArguments("start-maximized"); System.setProperty("webdriver.http.factory", "jdk-http-client"); - System.setProperty("webdriver.chrome.driver","C:\\Users\\mujtaba.afzal\\Documents\\ChromeDriver\\chromedriver.exe"); this.driver = new ChromeDriver(this.options); this.properties = UtilsConfig.getProperties("SwagLabs"); this.XPATH = UtilsConfig.getProperties("xpath"); From 55dd332ba9aaad21737936b214bdefd50c909095 Mon Sep 17 00:00:00 2001 From: bitsplz Date: Thu, 30 Mar 2023 01:27:57 +0500 Subject: [PATCH 4/8] add script to install chrome in ci --- .github/workflows/maven.yml | 4 ++++ scripts/InstallChrome.sh | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 scripts/InstallChrome.sh diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 4bccec2..0195913 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -26,6 +26,10 @@ jobs: with: java-version: '18' distribution: 'temurin' + - name: Install Google Chrome + run: | + chmod +x ./scripts/InstallChrome.sh + ./scripts/InstallChrome.sh - name: Build with Maven run: mvn test --file pom.xml diff --git a/scripts/InstallChrome.sh b/scripts/InstallChrome.sh new file mode 100644 index 0000000..0876ac0 --- /dev/null +++ b/scripts/InstallChrome.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -ex +wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb +sudo apt install ./google-chrome-stable_current_amd64.deb \ No newline at end of file From 340b712aef2e16e86fefcf54f10f1dd2dfc3c7cc Mon Sep 17 00:00:00 2001 From: bitsplz Date: Thu, 30 Mar 2023 01:33:03 +0500 Subject: [PATCH 5/8] add code to run chrome in headless mode --- src/test/java/tests/SwagLabs/BaseTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/tests/SwagLabs/BaseTest.java b/src/test/java/tests/SwagLabs/BaseTest.java index ddccbb8..8135eed 100644 --- a/src/test/java/tests/SwagLabs/BaseTest.java +++ b/src/test/java/tests/SwagLabs/BaseTest.java @@ -23,6 +23,9 @@ public void setupBeforeTest(){ WebDriverManager.chromedriver().setup(); this.options = new ChromeOptions(); this.options.addArguments("start-maximized"); + this.options.addArguments("--no-sandbox"); + this.options.addArguments("--disable-dev-shm-usage"); + this.options.addArguments("--headless"); System.setProperty("webdriver.http.factory", "jdk-http-client"); this.driver = new ChromeDriver(this.options); this.properties = UtilsConfig.getProperties("SwagLabs"); From 1eb04cb5c81fc7d43ee2986f348c9d6335285fc0 Mon Sep 17 00:00:00 2001 From: bitsplz Date: Thu, 30 Mar 2023 02:08:56 +0500 Subject: [PATCH 6/8] updated the applyfilter method in homepage --- src/test/java/pageobjects/swaglabs/HomePage.java | 4 ++-- src/test/java/tests/SwagLabs/HomePageTests.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/pageobjects/swaglabs/HomePage.java b/src/test/java/pageobjects/swaglabs/HomePage.java index b849201..60d6978 100644 --- a/src/test/java/pageobjects/swaglabs/HomePage.java +++ b/src/test/java/pageobjects/swaglabs/HomePage.java @@ -17,8 +17,8 @@ public void applyFilter(String value) { driver.findElement(By.xpath("//select[@class='product_sort_container']/option[@value='" + value + "']")).click(); } //get the filter value - public String getAppliedFilter() { - return driver.findElement(By.xpath("//div[@class='right_component']/span/span")).getText(); + public Boolean chkAppliedFilter(String filter) { + return driver.findElement(By.xpath("//span[contains(text(),'"+filter+"')]"))!=null; } public String getPageHeading() { diff --git a/src/test/java/tests/SwagLabs/HomePageTests.java b/src/test/java/tests/SwagLabs/HomePageTests.java index 533a792..ced3093 100644 --- a/src/test/java/tests/SwagLabs/HomePageTests.java +++ b/src/test/java/tests/SwagLabs/HomePageTests.java @@ -21,7 +21,7 @@ public void beforeEach(){ @Test(description = "Verify Filter should be applied successfully") public void applyFilter(){ homePage.applyFilter(properties.getProperty("sort_filter")); - Assert.assertEquals(homePage.getAppliedFilter(), properties.getProperty("sort_filter_text")); + Assert.assertTrue(homePage.chkAppliedFilter(properties.getProperty("sort_filter_text"))); } @Test(description = "Verify product page should be opened successfully") public void goToProductPage(){ From 8aabc8fd30503dd333fc562f6dc92de1a889e126 Mon Sep 17 00:00:00 2001 From: bitsplz Date: Thu, 30 Mar 2023 02:12:59 +0500 Subject: [PATCH 7/8] remove unwanted code from maven.yml --- .github/workflows/maven.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 0195913..9847922 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -31,8 +31,4 @@ jobs: chmod +x ./scripts/InstallChrome.sh ./scripts/InstallChrome.sh - name: Build with Maven - run: mvn test --file pom.xml - - # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive - - name: Update dependency graph - uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 + run: mvn test --file pom.xml \ No newline at end of file From 0cd80a0c8ac5030f3af2a6d82833bdec0560bb19 Mon Sep 17 00:00:00 2001 From: bitsplz Date: Thu, 30 Mar 2023 12:26:25 +0500 Subject: [PATCH 8/8] change branch in maven.yml and minor tweaks --- .github/workflows/maven.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 9847922..9aeaadc 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -6,13 +6,13 @@ # separate terms of service, privacy policy, and support # documentation. -name: Java CI with Maven +name: Run Selenium Tests on: push: - branches: [ "configure-ci" ] + branches: [ "master" ] pull_request: - branches: [ "configure-ci" ] + branches: [ "master" ] jobs: build: @@ -30,5 +30,5 @@ jobs: run: | chmod +x ./scripts/InstallChrome.sh ./scripts/InstallChrome.sh - - name: Build with Maven + - name: Run Tests with Maven run: mvn test --file pom.xml \ No newline at end of file