From ad6138772c436dcfe7bee9c3497713d53ed8152a Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Tue, 24 Jan 2023 10:08:47 +0200 Subject: [PATCH 1/4] add test fro chrome browser --- .github/workflows/ci.yml | 20 ++++++++++++++ src/test/java/TestRunners/TestBrowser.java | 31 ++++++---------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 813a1de..28b7e0b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,3 +39,23 @@ jobs: # uses: github/super-linter@v4 # env: # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + test: + runs-on: ubuntu-latest + continue-on-error: true + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + java-version: 11 + distribution: "zulu" + - name: Remove Chrome + run: sudo apt purge google-chrome-stable + - name: Remove default Chromium + run: sudo apt purge chromium-browser + - name: Install a new Chromium + run: sudo apt install -y chromium-browser + - name: Test with Maven + run: mvn -Dtest=TestBrowser test + diff --git a/src/test/java/TestRunners/TestBrowser.java b/src/test/java/TestRunners/TestBrowser.java index 77d21d6..7938774 100644 --- a/src/test/java/TestRunners/TestBrowser.java +++ b/src/test/java/TestRunners/TestBrowser.java @@ -29,6 +29,7 @@ public void testDesktopBrowser() { Configuration.testUILogLevel = LogLevel.DEBUG; Configuration.softAsserts = true; Configuration.browser = "chrome"; + Configuration.headless = true; open("https://www.google.com"); UIAssert("the url is not correct", getSelenideDriver().getCurrentUrl().equals("https://www.google.com/")); @@ -42,41 +43,20 @@ public void testDesktopBrowser() { System.out.println(getListOfCommandsTime()); raiseSoftAsserts(); + stop(); } @Test public void setDriverTest() { ChromeOptions options = new ChromeOptions(); Configuration.softAsserts = false; - options.addArguments("--user-agent=Agent", "--ignore-certificate-errors"); + options.addArguments("--user-agent=Agent", "--ignore-certificate-errors", "--headless"); Configuration.chromeOptions = options; selenideBrowserCapabilities.setBrowserName("chrome"); open("https://www.whatsmyua.info/"); E(byCssSelector("textarea")).waitFor(10).untilHasText("Agent"); sleep(1000); - } - - @Test - @DisplayName("Laptop browser test case") - public void testDesktopBrowserSafari() { - Configuration.automationType = DESKTOP_PLATFORM; - Configuration.browser = "safari"; - Configuration.serverLogLevel = "all"; - Configuration.softAsserts = true; - open("https://www.google.com"); - System.out.println(getTestUIDriver().getCurrentUrl()); - executeJs("arguments[0].value='TestUI';", googleLandingPage.getGoogleSearchInput() - .getSelenideElement().getWrappedElement()); - googleLandingPage.getGoogleSearch().given() - .then().click().saveScreenshot("/Users/alvarolasernalopez/Documents/screen" + - ".png"); stop(); - open("https://www.google.com"); - googleLandingPage.getGoogleSearch().given().waitFor(10).untilIsVisible() - .then().click().saveScreenshot("/Users/alvarolasernalopez/Documents/screen" + - ".png"); - - raiseSoftAsserts(); } @@ -86,6 +66,7 @@ public void testDesktopBrowserStatusCode() { Configuration.automationType = DESKTOP_PLATFORM; Configuration.logNetworkCalls = true; Configuration.browser = "chrome"; + Configuration.headless = true; open("https://www.google.com") .getNetworkCalls().logAllCalls().filterByExactUrl("https://www.google.com/") .logFilteredCalls() @@ -107,11 +88,13 @@ public void testDesktopBrowserStatusCode() { public void testDesktopCustomDriverBrowser() { Configuration.automationType = DESKTOP_PLATFORM; Configuration.browser = "chrome"; + Configuration.headless = true; open("https://www.google.com"); stop(); ChromeOptions options = new ChromeOptions(); String userAgent = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"; options.addArguments("--user-agent=" + userAgent); + options.addArguments("--headless"); ChromeDriver chromeDriver = new ChromeDriver(options); setDriver(chromeDriver); open("https://www.whatsmyua.info/"); @@ -128,6 +111,7 @@ public void testAndroidBrowserOneLine() { Configuration.useAllure = false; Configuration.softAsserts = true; Configuration.browser = "chrome"; + Configuration.headless = true; Configuration.testUILogLevel = LogLevel.DEBUG; open("https://loadero.com/login") .given("I set element").setElement(byCssSelector("#username")) @@ -139,5 +123,6 @@ public void testAndroidBrowserOneLine() { .then("I find the submit").setElement(byCssSelector("[type=\"submit\"]")) .and("I click on it").click(); raiseSoftAsserts(); + stop(); } } From 6dc2a3e98dba31d83495b224e5f37324aba6ef97 Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Tue, 24 Jan 2023 11:09:28 +0200 Subject: [PATCH 2/4] fix path for screenshot --- src/test/java/TestRunners/TestBrowser.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/test/java/TestRunners/TestBrowser.java b/src/test/java/TestRunners/TestBrowser.java index 7938774..046b7f6 100644 --- a/src/test/java/TestRunners/TestBrowser.java +++ b/src/test/java/TestRunners/TestBrowser.java @@ -36,9 +36,7 @@ public void testDesktopBrowser() { executeJs("arguments[0].value='TestUI';", googleLandingPage.getGoogleSearchInput() .getSelenideElement().getWrappedElement()); googleLandingPage.getGoogleSearch() - .then().saveScreenshot("~/Documents" + - "/screen" + - ".png"); + .then().saveScreenshot("~/target/screen.png"); logAverageTime(); System.out.println(getListOfCommandsTime()); From 799fe253f45b36adffcf5d42818b08f600c6b749 Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Thu, 30 Mar 2023 08:52:39 +0200 Subject: [PATCH 3/4] split integration test in other CI job file --- .github/workflows/ci.yml | 20 ----------------- .github/workflows/ci_integration.yml | 32 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/ci_integration.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 28b7e0b..813a1de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,23 +39,3 @@ jobs: # uses: github/super-linter@v4 # env: # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - test: - runs-on: ubuntu-latest - continue-on-error: true - - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 11 - uses: actions/setup-java@v2 - with: - java-version: 11 - distribution: "zulu" - - name: Remove Chrome - run: sudo apt purge google-chrome-stable - - name: Remove default Chromium - run: sudo apt purge chromium-browser - - name: Install a new Chromium - run: sudo apt install -y chromium-browser - - name: Test with Maven - run: mvn -Dtest=TestBrowser test - diff --git a/.github/workflows/ci_integration.yml b/.github/workflows/ci_integration.yml new file mode 100644 index 0000000..0ed6f42 --- /dev/null +++ b/.github/workflows/ci_integration.yml @@ -0,0 +1,32 @@ +name: TestUI CI integration tests workflow + +on: + push: + branches: + - master + pull_request: + branches: + - master + + workflow_dispatch: + +jobs: + integration_test: + runs-on: ubuntu-latest + continue-on-error: true + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + java-version: 11 + distribution: "zulu" + - name: Remove Chrome + run: sudo apt purge google-chrome-stable + - name: Remove default Chromium + run: sudo apt purge chromium-browser + - name: Install a new Chromium + run: sudo apt install -y chromium-browser + - name: Integration browser test with Maven + run: mvn -Dtest=TestBrowser test From 6485a7c2dae92eb8a0c64fdea97894df351405c1 Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Fri, 31 Mar 2023 18:09:53 +0200 Subject: [PATCH 4/4] fix new version of chrome issue with remote origin --- pom.xml | 4 ++-- src/test/java/TestRunners/TestBrowser.java | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index aaee65d..d349c78 100644 --- a/pom.xml +++ b/pom.xml @@ -66,7 +66,7 @@ maven-surefire-plugin 3.0.0-M3 - true + false -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar" @@ -170,7 +170,7 @@ com.codeborne selenide - 6.10.1 + 6.12.2 org.slf4j diff --git a/src/test/java/TestRunners/TestBrowser.java b/src/test/java/TestRunners/TestBrowser.java index 046b7f6..2058495 100644 --- a/src/test/java/TestRunners/TestBrowser.java +++ b/src/test/java/TestRunners/TestBrowser.java @@ -5,6 +5,7 @@ import org.junit.Test; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; +import org.openqa.selenium.remote.DesiredCapabilities; import pages.GoogleLandingPage; import testUI.Configuration; @@ -48,7 +49,8 @@ public void testDesktopBrowser() { public void setDriverTest() { ChromeOptions options = new ChromeOptions(); Configuration.softAsserts = false; - options.addArguments("--user-agent=Agent", "--ignore-certificate-errors", "--headless"); + options.addArguments( + "--user-agent=Agent", "--ignore-certificate-errors", "--headless", "--remote-allow-origins=*"); Configuration.chromeOptions = options; selenideBrowserCapabilities.setBrowserName("chrome"); open("https://www.whatsmyua.info/"); @@ -89,8 +91,9 @@ public void testDesktopCustomDriverBrowser() { Configuration.headless = true; open("https://www.google.com"); stop(); - ChromeOptions options = new ChromeOptions(); String userAgent = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"; + ChromeOptions options = new ChromeOptions(); + options.addArguments("--remote-allow-origins=*"); options.addArguments("--user-agent=" + userAgent); options.addArguments("--headless"); ChromeDriver chromeDriver = new ChromeDriver(options);