From 62fdd8874c83074b2fb23c97cda6df89828da737 Mon Sep 17 00:00:00 2001 From: deepanshusri <103935065+deepanshusri@users.noreply.github.com> Date: Wed, 12 Oct 2022 21:03:31 +0530 Subject: [PATCH 01/18] Create maven.yml --- .github/workflows/maven.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 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..65b2bf7 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,27 @@ +# 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://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: Java CI with Maven + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn test -D suite=single.xml + From b9ffc280fa15ada865b50e2862b31f3e49027cae Mon Sep 17 00:00:00 2001 From: deepanshusri <103935065+deepanshusri@users.noreply.github.com> Date: Wed, 12 Oct 2022 22:20:52 +0530 Subject: [PATCH 02/18] Update TestNGTodo1.java --- src/test/java/com/lambdatest/TestNGTodo1.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/lambdatest/TestNGTodo1.java b/src/test/java/com/lambdatest/TestNGTodo1.java index 62577d1..7e692ac 100644 --- a/src/test/java/com/lambdatest/TestNGTodo1.java +++ b/src/test/java/com/lambdatest/TestNGTodo1.java @@ -20,8 +20,8 @@ public class TestNGTodo1 { @BeforeMethod public void setup(Method m, ITestContext ctx) throws MalformedURLException { - String username = System.getenv("LT_USERNAME") == null ? "Your LT Username" : System.getenv("LT_USERNAME"); - String authkey = System.getenv("LT_ACCESS_KEY") == null ? "Your LT AccessKey" : System.getenv("LT_ACCESS_KEY"); + String username = deepanshulambdatest; + String authkey = rsoHTTxvRGQOV7jvQJJwPzKYQSyXYHKqC3SOgIWgKJ9G9sWZbk; ; String hub = "@hub.lambdatest.com/wd/hub"; @@ -106,4 +106,4 @@ public void tearDown() { driver.quit(); } -} \ No newline at end of file +} From d9a34efdcdc7c567518f74fa445dc796ad7e33e3 Mon Sep 17 00:00:00 2001 From: deepanshusri <103935065+deepanshusri@users.noreply.github.com> Date: Wed, 12 Oct 2022 22:21:07 +0530 Subject: [PATCH 03/18] Create maven-publish.yml --- .github/workflows/maven-publish.yml | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/maven-publish.yml diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml new file mode 100644 index 0000000..8a6cae4 --- /dev/null +++ b/.github/workflows/maven-publish.yml @@ -0,0 +1,34 @@ +# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created +# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path + +name: Maven Package + +on: + release: + types: [created] + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + server-id: github # Value of the distributionManagement/repository/id field of the pom.xml + settings-path: ${{ github.workspace }} # location for the settings.xml file + + - name: Build with Maven + run: mvn test -D suite=single.xml + + - name: Publish to GitHub Packages Apache Maven + run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml + env: + GITHUB_TOKEN: ${{ github.token }} From 8bf5a4d3b1afa2a23c44de0fb6ba62643af0d4bf Mon Sep 17 00:00:00 2001 From: deepanshusri <103935065+deepanshusri@users.noreply.github.com> Date: Wed, 12 Oct 2022 22:23:14 +0530 Subject: [PATCH 04/18] Update TestNGTodo2.java --- src/test/java/com/lambdatest/TestNGTodo2.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/lambdatest/TestNGTodo2.java b/src/test/java/com/lambdatest/TestNGTodo2.java index 3530993..304f313 100644 --- a/src/test/java/com/lambdatest/TestNGTodo2.java +++ b/src/test/java/com/lambdatest/TestNGTodo2.java @@ -20,8 +20,8 @@ public class TestNGTodo2 { @BeforeMethod public void setup(Method m, ITestContext ctx) throws MalformedURLException { - String username = System.getenv("LT_USERNAME") == null ? "Your LT Username" : System.getenv("LT_USERNAME"); - String authkey = System.getenv("LT_ACCESS_KEY") == null ? "Your LT AccessKey" : System.getenv("LT_ACCESS_KEY"); + String username = "deepanshulambdatest"; + String authkey = "rsoHTTxvRGQOV7jvQJJwPzKYQSyXYHKqC3SOgIWgKJ9G9sWZbk"; ; /* @@ -118,4 +118,4 @@ public void tearDown() { driver.quit(); } -} \ No newline at end of file +} From 9c760423a37a877af8680896687c172d8518db91 Mon Sep 17 00:00:00 2001 From: deepanshusri <103935065+deepanshusri@users.noreply.github.com> Date: Wed, 12 Oct 2022 22:24:10 +0530 Subject: [PATCH 05/18] Create maventest.yml --- .github/workflows/maventest.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/maventest.yml diff --git a/.github/workflows/maventest.yml b/.github/workflows/maventest.yml new file mode 100644 index 0000000..65b2bf7 --- /dev/null +++ b/.github/workflows/maventest.yml @@ -0,0 +1,27 @@ +# 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://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: Java CI with Maven + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn test -D suite=single.xml + From 6216310c8e8c153657ff1e7b25ed49f2866ce665 Mon Sep 17 00:00:00 2001 From: deepanshusri <103935065+deepanshusri@users.noreply.github.com> Date: Wed, 12 Oct 2022 22:24:25 +0530 Subject: [PATCH 06/18] Delete maven-publish.yml --- .github/workflows/maven-publish.yml | 34 ----------------------------- 1 file changed, 34 deletions(-) delete mode 100644 .github/workflows/maven-publish.yml diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml deleted file mode 100644 index 8a6cae4..0000000 --- a/.github/workflows/maven-publish.yml +++ /dev/null @@ -1,34 +0,0 @@ -# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created -# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path - -name: Maven Package - -on: - release: - types: [created] - -jobs: - build: - - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - java-version: '11' - distribution: 'temurin' - server-id: github # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Build with Maven - run: mvn test -D suite=single.xml - - - name: Publish to GitHub Packages Apache Maven - run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml - env: - GITHUB_TOKEN: ${{ github.token }} From ad987703b7839320c113bbbc8f418970b507d2a5 Mon Sep 17 00:00:00 2001 From: deepanshusri <103935065+deepanshusri@users.noreply.github.com> Date: Wed, 12 Oct 2022 22:24:32 +0530 Subject: [PATCH 07/18] Delete maven.yml --- .github/workflows/maven.yml | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml deleted file mode 100644 index 65b2bf7..0000000 --- a/.github/workflows/maven.yml +++ /dev/null @@ -1,27 +0,0 @@ -# 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://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven - -name: Java CI with Maven - -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - java-version: '11' - distribution: 'temurin' - cache: maven - - name: Build with Maven - run: mvn test -D suite=single.xml - From e3c8c371f9d676733780d762b291cca847983dc2 Mon Sep 17 00:00:00 2001 From: deepanshusri <103935065+deepanshusri@users.noreply.github.com> Date: Wed, 12 Oct 2022 22:28:02 +0530 Subject: [PATCH 08/18] Update TestNGTodo1.java --- src/test/java/com/lambdatest/TestNGTodo1.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/lambdatest/TestNGTodo1.java b/src/test/java/com/lambdatest/TestNGTodo1.java index 7e692ac..ee60847 100644 --- a/src/test/java/com/lambdatest/TestNGTodo1.java +++ b/src/test/java/com/lambdatest/TestNGTodo1.java @@ -20,8 +20,8 @@ public class TestNGTodo1 { @BeforeMethod public void setup(Method m, ITestContext ctx) throws MalformedURLException { - String username = deepanshulambdatest; - String authkey = rsoHTTxvRGQOV7jvQJJwPzKYQSyXYHKqC3SOgIWgKJ9G9sWZbk; + String username = "deepanshulambdatest"; + String authkey = "rsoHTTxvRGQOV7jvQJJwPzKYQSyXYHKqC3SOgIWgKJ9G9sWZbk"; ; String hub = "@hub.lambdatest.com/wd/hub"; From 88c3fe9526ac492f5398ba11d141a904120db45e Mon Sep 17 00:00:00 2001 From: deepanshusri <103935065+deepanshusri@users.noreply.github.com> Date: Wed, 12 Oct 2022 22:54:24 +0530 Subject: [PATCH 09/18] Create maven.yml --- .github/workflows/maven.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 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..251a424 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,26 @@ +# 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://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: Java CI with Maven + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn test -D suite=single.xml From 3fa2645c2182e6193029cc0e79445d602e360bc1 Mon Sep 17 00:00:00 2001 From: deepanshusri <103935065+deepanshusri@users.noreply.github.com> Date: Thu, 16 Feb 2023 21:35:40 +0530 Subject: [PATCH 10/18] Update TestNGTodo1.java --- src/test/java/com/lambdatest/TestNGTodo1.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/lambdatest/TestNGTodo1.java b/src/test/java/com/lambdatest/TestNGTodo1.java index ee60847..66a5948 100644 --- a/src/test/java/com/lambdatest/TestNGTodo1.java +++ b/src/test/java/com/lambdatest/TestNGTodo1.java @@ -21,7 +21,7 @@ public class TestNGTodo1 { @BeforeMethod public void setup(Method m, ITestContext ctx) throws MalformedURLException { String username = "deepanshulambdatest"; - String authkey = "rsoHTTxvRGQOV7jvQJJwPzKYQSyXYHKqC3SOgIWgKJ9G9sWZbk"; + String authkey = "f8xr8eV7hpJJixO6sbVmPazAH4C8VoAUhEANPjikayLTXNlJKs"; ; String hub = "@hub.lambdatest.com/wd/hub"; From 53bc9f9ff9cf17bfbab8274cce283e2362e01a73 Mon Sep 17 00:00:00 2001 From: deepanshusri <103935065+deepanshusri@users.noreply.github.com> Date: Thu, 8 Jun 2023 18:46:43 +0530 Subject: [PATCH 11/18] Create Jenkinsfile --- Jenkinsfile | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..1d25d3a --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,40 @@ +pipeline { + agent any + + stages { + stage('Checkout') { + steps { + // Checkout the source code from your version control system + // For example, using Git + git 'https://github.com/deepanshusri/java-testng-selenium.git' + } + } + + stage('Build') { + steps { + // Build your Java project + // For example, using Apache Maven + bat 'mvn clean package' + bat 'mvn install' + } + } + + stage('Test') { + steps { + // Run tests for your Java project + // For example, using Apache Maven + // bat 'mvn test' + bat 'mvn test -D suite=single.xml' + } + } + + stage('Deploy') { + steps { + // Deploy your Java project to a server or a container + // For example, using Docker + bat 'docker build -t your-image .' + bat 'docker run -d -p 8080:8080 your-image' + } + } + } +} From 21d486f0b0519703c350b719864172686db1e570 Mon Sep 17 00:00:00 2001 From: deepanshusri <103935065+deepanshusri@users.noreply.github.com> Date: Thu, 8 Jun 2023 18:51:14 +0530 Subject: [PATCH 12/18] Update Jenkinsfile --- Jenkinsfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1d25d3a..79a1aee 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,8 +14,8 @@ pipeline { steps { // Build your Java project // For example, using Apache Maven - bat 'mvn clean package' - bat 'mvn install' + sh 'mvn clean package' + sh 'mvn install' } } @@ -24,7 +24,7 @@ pipeline { // Run tests for your Java project // For example, using Apache Maven // bat 'mvn test' - bat 'mvn test -D suite=single.xml' + sh 'mvn test -D suite=single.xml' } } @@ -32,8 +32,8 @@ pipeline { steps { // Deploy your Java project to a server or a container // For example, using Docker - bat 'docker build -t your-image .' - bat 'docker run -d -p 8080:8080 your-image' + sh 'docker build -t your-image .' + sh 'docker run -d -p 8080:8080 your-image' } } } From 1859ef653037721b7b4bcd1a5a43f51229f33e2d Mon Sep 17 00:00:00 2001 From: deepanshusri <103935065+deepanshusri@users.noreply.github.com> Date: Mon, 12 Feb 2024 13:12:47 +0530 Subject: [PATCH 13/18] Update TestNGTodo1.java --- src/test/java/com/lambdatest/TestNGTodo1.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/com/lambdatest/TestNGTodo1.java b/src/test/java/com/lambdatest/TestNGTodo1.java index 66a5948..a2d5f0c 100644 --- a/src/test/java/com/lambdatest/TestNGTodo1.java +++ b/src/test/java/com/lambdatest/TestNGTodo1.java @@ -32,6 +32,8 @@ public void setup(Method m, ITestContext ctx) throws MalformedURLException { caps.setCapability("build", "TestNG With Java"); caps.setCapability("name", m.getName() + " - " + this.getClass().getName()); caps.setCapability("plugin", "git-testng"); + caps.setCapability("tunnel", true); + String[] Tags = new String[] { "Feature", "Falcon", "Severe" }; caps.setCapability("tags", Tags); From c917cd5cb4bad88522519dacda9f3ad779674b99 Mon Sep 17 00:00:00 2001 From: deepanshusri <103935065+deepanshusri@users.noreply.github.com> Date: Mon, 12 Feb 2024 13:14:25 +0530 Subject: [PATCH 14/18] Update TestNGTodo1.java --- src/test/java/com/lambdatest/TestNGTodo1.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/lambdatest/TestNGTodo1.java b/src/test/java/com/lambdatest/TestNGTodo1.java index a2d5f0c..fd7cebc 100644 --- a/src/test/java/com/lambdatest/TestNGTodo1.java +++ b/src/test/java/com/lambdatest/TestNGTodo1.java @@ -20,9 +20,8 @@ public class TestNGTodo1 { @BeforeMethod public void setup(Method m, ITestContext ctx) throws MalformedURLException { - String username = "deepanshulambdatest"; - String authkey = "f8xr8eV7hpJJixO6sbVmPazAH4C8VoAUhEANPjikayLTXNlJKs"; - ; + String username = System.getenv("LT_USERNAME") == null ? "Your LT Username" : System.getenv("LT_USERNAME"); + String authkey = System.getenv("LT_ACCESS_KEY") == null ? "Your LT AccessKey" : System.getenv("LT_ACCESS_KEY"); String hub = "@hub.lambdatest.com/wd/hub"; DesiredCapabilities caps = new DesiredCapabilities(); From dfdde32fa46f2645f64a697c04e7063012806e64 Mon Sep 17 00:00:00 2001 From: deepanshusri <103935065+deepanshusri@users.noreply.github.com> Date: Mon, 12 Feb 2024 13:18:59 +0530 Subject: [PATCH 15/18] Update single.xml --- single.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/single.xml b/single.xml index 38a023f..b90b198 100644 --- a/single.xml +++ b/single.xml @@ -3,7 +3,7 @@ - + From abb2924658ee1efd3939a560128e7062f0557957 Mon Sep 17 00:00:00 2001 From: deepanshusri <103935065+deepanshusri@users.noreply.github.com> Date: Mon, 12 Feb 2024 16:04:28 +0530 Subject: [PATCH 16/18] Create visualui.java --- src/test/java/com/lambdatest/visualui.java | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/test/java/com/lambdatest/visualui.java diff --git a/src/test/java/com/lambdatest/visualui.java b/src/test/java/com/lambdatest/visualui.java new file mode 100644 index 0000000..5eaf738 --- /dev/null +++ b/src/test/java/com/lambdatest/visualui.java @@ -0,0 +1,74 @@ +package com.lambdatest; + +import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URL; + +import org.openqa.selenium.By; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebDriver; +import org.testng.Assert; +import org.testng.ITestContext; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class visualui { + + private RemoteWebDriver driver; + private String Status = "failed"; + + @BeforeMethod + public void setup(Method m, ITestContext ctx) throws MalformedURLException { + String username = System.getenv("LT_USERNAME") == null ? "Your LT Username" : System.getenv("LT_USERNAME"); + String authkey = System.getenv("LT_ACCESS_KEY") == null ? "Your LT AccessKey" : System.getenv("LT_ACCESS_KEY"); + String hub = "@hub.lambdatest.com/wd/hub"; + + DesiredCapabilities caps = new DesiredCapabilities(); + caps.setCapability("platform", "MacOS Catalina"); + caps.setCapability("browserName", "Chrome"); + caps.setCapability("version", "121"); + caps.setCapability("build", "TestNG With Java + Visual UI"); + caps.setCapability("name", m.getName() + " - " + this.getClass().getName()); + caps.setCapability("plugin", "git-testng"); + caps.setCapability("visual",true); + caps.setCapability("smartUI.project","Feb_12"); + caps.setCapability("smartUI.build","build 1"); + + driver = new RemoteWebDriver(new URL("https://" + username + ":" + authkey + hub), caps); + + } + + @Test + public void basicTest() throws InterruptedException { + String spanText; + System.out.println("Loading Url"); + + + driver.get("https://www.lambdatest.com/"); + Thread.sleep(5000); + driver.executeScript("smartui.takeScreenshot=pic1"); + Thread.sleep(1000); + + driver.get("https://www.lambdatest.com/support/docs/"); + Thread.sleep(5000); + driver.executeScript("smartui.takeScreenshot=pic2"); + Thread.sleep(1000); + + driver.get("https://www.lambdatest.com/pricing"); + Thread.sleep(5000); + driver.executeScript("smartui.takeScreenshot=pic3"); + Thread.sleep(1000); + + Status = "passed"; + Thread.sleep(800); + System.out.println("TestFinished"); + } + + @AfterMethod + public void tearDown() { + driver.executeScript("lambda-status=" + Status); + driver.quit(); + } + +} From dca35f520dbd86d291d19161745495dfeeb2d2e7 Mon Sep 17 00:00:00 2001 From: deepanshusri <103935065+deepanshusri@users.noreply.github.com> Date: Fri, 20 Sep 2024 00:26:06 +0530 Subject: [PATCH 17/18] Update TestNGTodo1.java --- src/test/java/com/lambdatest/TestNGTodo1.java | 315 ++++++++++++++---- 1 file changed, 246 insertions(+), 69 deletions(-) diff --git a/src/test/java/com/lambdatest/TestNGTodo1.java b/src/test/java/com/lambdatest/TestNGTodo1.java index fd7cebc..f8fc989 100644 --- a/src/test/java/com/lambdatest/TestNGTodo1.java +++ b/src/test/java/com/lambdatest/TestNGTodo1.java @@ -1,13 +1,24 @@ package com.lambdatest; -import java.lang.reflect.Method; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.math.BigInteger; +import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; +import java.time.LocalDateTime; +import java.util.HashMap; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; -import org.openqa.selenium.By; +import org.json.JSONArray; +import org.json.JSONObject; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; -import org.testng.Assert; +import org.openqa.selenium.remote.SessionId; import org.testng.ITestContext; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; @@ -16,95 +27,261 @@ public class TestNGTodo1 { private RemoteWebDriver driver; - private String Status = "failed"; + private String testStatus; @BeforeMethod public void setup(Method m, ITestContext ctx) throws MalformedURLException { - String username = System.getenv("LT_USERNAME") == null ? "Your LT Username" : System.getenv("LT_USERNAME"); - String authkey = System.getenv("LT_ACCESS_KEY") == null ? "Your LT AccessKey" : System.getenv("LT_ACCESS_KEY"); + String username = "deepanshulambdatest"; + String accessKey = "SMKwpdntRhBpUbdLrUqk0tU0TjAZquV9kz0YxnOWUo56EaqtQw"; String hub = "@hub.lambdatest.com/wd/hub"; - DesiredCapabilities caps = new DesiredCapabilities(); - caps.setCapability("platform", "MacOS Catalina"); - caps.setCapability("browserName", "Safari"); - caps.setCapability("version", "latest"); - caps.setCapability("build", "TestNG With Java"); - caps.setCapability("name", m.getName() + " - " + this.getClass().getName()); - caps.setCapability("plugin", "git-testng"); - caps.setCapability("tunnel", true); - - - String[] Tags = new String[] { "Feature", "Falcon", "Severe" }; - caps.setCapability("tags", Tags); - - driver = new RemoteWebDriver(new URL("https://" + username + ":" + authkey + hub), caps); - + DesiredCapabilities capabilities = new DesiredCapabilities(); + HashMap ltOptions = new HashMap<>(); + ltOptions.put("platform", "windows 11"); + ltOptions.put("browserName", "chrome"); + ltOptions.put("version", "125"); + ltOptions.put("build", "Qmetry test case build"); + ltOptions.put("console", true); + ltOptions.put("visual", true); + ltOptions.put("network", true); + ltOptions.put("name", "SCRUM-TC-"); + ltOptions.put("w3c", true); + capabilities.setCapability("lt:options", ltOptions); + driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + hub), capabilities); } @Test - public void basicTest() throws InterruptedException { - String spanText; - System.out.println("Loading Url"); - - driver.get("https://lambdatest.github.io/sample-todo-app/"); - - System.out.println("Checking Box"); - driver.findElement(By.name("li1")).click(); - - System.out.println("Checking Another Box"); - driver.findElement(By.name("li2")).click(); - - System.out.println("Checking Box"); - driver.findElement(By.name("li3")).click(); - - System.out.println("Checking Another Box"); - driver.findElement(By.name("li4")).click(); - - driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 6"); - driver.findElement(By.id("addbutton")).click(); - - driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 7"); - driver.findElement(By.id("addbutton")).click(); + public void basicTest() { + driver.get("https://lambdatest.com/"); + testStatus = "passed"; + } - driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 8"); - driver.findElement(By.id("addbutton")).click(); + private String getGETApiResponse(String apiUrl, String requestPropertyKey, String requestPropertyValue) throws IOException { + URL url = new URL(apiUrl); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("accept", "application/json"); + connection.setRequestProperty(requestPropertyKey, requestPropertyValue); + + try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { + StringBuilder response = new StringBuilder(); + String inputLine; + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + return response.toString(); + } + } - System.out.println("Checking Another Box"); - driver.findElement(By.name("li1")).click(); + private String getPOSTApiResponse(String apiUrl, String requestBody) throws IOException { + URL url = new URL(apiUrl); + String apiKey = "cd9a7315357f0e8f6866ba50515928617182c4d8f58fec0b1397c8534c93537f73bf8fad9d0be32f4f6d07d26502f6949780e00365547ccfc7dfc56b33d3382d616a1443aa0cc38531566209d5c33d75"; + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Content-Type", "application/json"); + connection.setRequestProperty("apiKey", apiKey); + connection.setDoOutput(true); + + try (OutputStream os = connection.getOutputStream()) { + byte[] input = requestBody.getBytes("utf-8"); + os.write(input, 0, input.length); + } + + int responseCode = connection.getResponseCode(); + if (responseCode >= HttpURLConnection.HTTP_BAD_REQUEST) { + try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getErrorStream()))) { + StringBuilder errorResponse = new StringBuilder(); + String inputLine; + while ((inputLine = in.readLine()) != null) { + errorResponse.append(inputLine); + } + throw new IOException("Error: " + errorResponse.toString()); + } + } + + try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { + StringBuilder response = new StringBuilder(); + String inputLine; + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + return response.toString(); + } + } - System.out.println("Checking Another Box"); - driver.findElement(By.name("li3")).click(); + private void getPUTApiResponse(String apiUrl, BigInteger dynamicId) throws IOException { + URL url = new URL(apiUrl); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - System.out.println("Checking Another Box"); - driver.findElement(By.name("li7")).click(); + JSONObject jsonBody = new JSONObject(); + jsonBody.put("executionResultId", dynamicId); + String requestBody = jsonBody.toString(); - System.out.println("Checking Another Box"); - driver.findElement(By.name("li8")).click(); - Thread.sleep(300); + String apiKey = "cd9a7315357f0e8f6866ba50515928617182c4d8f58fec0b1397c8534c93537f73bf8fad9d0be32f4f6d07d26502f6949780e00365547ccfc7dfc56b33d3382d616a1443aa0cc38531566209d5c33d75"; - System.out.println("Entering Text"); - driver.findElement(By.id("sampletodotext")).sendKeys("Get Taste of Lambda and Stick to It"); + connection.setRequestMethod("PUT"); + connection.setRequestProperty("Content-Type", "application/json"); + connection.setRequestProperty("apiKey", apiKey); + connection.setDoOutput(true); - driver.findElement(By.id("addbutton")).click(); + try (OutputStream os = connection.getOutputStream()) { + byte[] input = requestBody.getBytes("utf-8"); + os.write(input, 0, input.length); + } - System.out.println("Checking Another Box"); - driver.findElement(By.name("li9")).click(); + int responseCode = connection.getResponseCode(); + } - // Let's also assert that the todo we added is present in the list. + private String getAddExecutionResultResponse(String apiUrl, String userTestResultStatus) throws IOException { + URL url = new URL(apiUrl); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + + JSONObject jsonBody = new JSONObject(); + jsonBody.put("color", userTestResultStatus.equals("passed") ? "#BAB86C" : "#800000"); + jsonBody.put("name", userTestResultStatus); + jsonBody.put("description", "Test result updated according to the USER's test case result"); + String requestBody = jsonBody.toString(); + + String apiKey = "cd9a7315357f0e8f6866ba50515928617182c4d8f58fec0b1397c8534c93537f73bf8fad9d0be32f4f6d07d26502f6949780e00365547ccfc7dfc56b33d3382d616a1443aa0cc38531566209d5c33d75"; + connection.setRequestMethod("POST"); + connection.setRequestProperty("Content-Type", "application/json"); + connection.setRequestProperty("apiKey", apiKey); + connection.setDoOutput(true); + + try (OutputStream os = connection.getOutputStream()) { + byte[] input = requestBody.getBytes("utf-8"); + os.write(input, 0, input.length); + } + + int responseCode = connection.getResponseCode(); + + BufferedReader in; + if (responseCode >= HttpURLConnection.HTTP_BAD_REQUEST) { + in = new BufferedReader(new InputStreamReader(connection.getErrorStream())); + } else { + in = new BufferedReader(new InputStreamReader(connection.getInputStream())); + } + + StringBuilder response = new StringBuilder(); + String inputLine; + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + + return response.toString(); + } - spanText = driver.findElementByXPath("/html/body/div/div/div/ul/li[9]/span").getText(); - Assert.assertEquals("Get Taste of Lambda and Stick to It", spanText); - Status = "passed"; - Thread.sleep(150); + private Map getStatusIndFromJsonResponse(String jsonResponse) { + JSONObject jsonObject = new JSONObject(jsonResponse); + JSONObject dataObject = jsonObject.getJSONObject("data"); + String testName = dataObject.optString("name", "unknown"); + String status = dataObject.optString("status_ind", "unknown"); + // Create a map to hold the results + Map resultMap = new HashMap<>(); + resultMap.put("testName", testName); + resultMap.put("status", status); + + return resultMap; // Return the map + } - System.out.println("TestFinished"); + private BigInteger getExecutionResultUsersStatus(String jsonResponse) { + JSONObject jsonObject = new JSONObject(jsonResponse); + return jsonObject.optBigInteger("id", BigInteger.valueOf(0)); + } + private JSONArray getSearchTestCycleResponse(String jsonResponse) { + JSONObject jsonObject = new JSONObject(jsonResponse); + return jsonObject.getJSONArray("data"); } @AfterMethod public void tearDown() { - driver.executeScript("lambda-status=" + Status); - driver.quit(); + try { + if (driver != null) { + driver.executeScript("lambda-status=" + testStatus); + SessionId session = driver.getSessionId(); + String sessionApiUrl = "https://api.lambdatest.com/automation/api/v1/sessions/" + session; + String authKey = "Basic ZGVlcGFuc2h1bGFtYmRhdGVzdDpTTUt3cGRudFJoQnBVYmRMclVxazB0VTBUakFacXVWOWt6MFl4bk9XVW81NkVhcXRRdw=="; + String response = getGETApiResponse(sessionApiUrl, "Authorization", authKey); + Map result = getStatusIndFromJsonResponse(response); + String userTestResultStatus = result.get("status"); + String userTestResultName = result.get("testName"); + + // POST API for getting test cycle + String searchTestCycleApiUrl = "https://qtmcloud.qmetry.com/rest/api/latest/testcycles/search/"; + String searchTestCycleResponse = getPOSTApiResponse(searchTestCycleApiUrl, "{\"filter\":{\"projectId\":10000}}"); + JSONArray searchTestCycleResult = getSearchTestCycleResponse(searchTestCycleResponse); + String testCycleId = ""; + for (int i = 0; i < searchTestCycleResult.length(); i++) { + JSONObject obj = searchTestCycleResult.getJSONObject(i); + String key = obj.getString("key"); + if ("SCRUM-TR-9".equals(key)) { + String id = obj.getString("id"); + testCycleId = id; + break; + } + } + + // POST API for get linked test cases of test cycle + String getLinkedTestCasesApiUrl = "https://qtmcloud.qmetry.com/rest/api/latest/testcycles/" + testCycleId + "/testcases/search/"; + String linkedTestCasesResponse = getPOSTApiResponse(getLinkedTestCasesApiUrl, "{\n" + + " \"filter\": {\n" + + " \"status\": [\n" + + " \"In Progress\",\n" + + " \"To Do\",\n" + + " \"Passed\",\n" + + " \"Failed\",\n" + + " \"Blocked\",\n" + + " \"Not Executed\"\n" + + " ]\n" + + " }\n" + + "}"); + + JSONArray linkedTestCasesResult = getSearchTestCycleResponse(linkedTestCasesResponse); + BigInteger testCaseExecutionId = BigInteger.valueOf(0); + for (int i = 0; i < linkedTestCasesResult.length(); i++) { + JSONObject obj = linkedTestCasesResult.getJSONObject(i); + String key = obj.getString("key"); + if (userTestResultName.equals(key)) { + BigInteger id = BigInteger.valueOf(obj.getLong("testCaseExecutionId")); + System.out.println("----------LT id-----------" + id); + testCaseExecutionId = id; + break; + } + } + // JSONObject linkedTestCaseResponseObj = linkedTestCasesResult.getJSONObject(0); + // BigInteger testCaseExecutionId = linkedTestCaseResponseObj.getBigInteger("testCaseExecutionId"); + + // GET execution result + String getExecutionResultApiUrl = "https://qtmcloud.qmetry.com/rest/api/latest/projects/10000/execution-results"; + String apiKey = "cd9a7315357f0e8f6866ba50515928617182c4d8f58fec0b1397c8534c93537f73bf8fad9d0be32f4f6d07d26502f6949780e00365547ccfc7dfc56b33d3382d616a1443aa0cc38531566209d5c33d75"; + String getExecutionResultResponse = getGETApiResponse(getExecutionResultApiUrl, "apiKey", apiKey); + JSONArray jsonArray = new JSONArray(getExecutionResultResponse); + BigInteger executionResultId = BigInteger.valueOf(0); + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject executionResultResponseObj = jsonArray.getJSONObject(i); // get the individual obj + String name = executionResultResponseObj.getString("name"); + if (userTestResultStatus.equals(name)) { + executionResultId = executionResultResponseObj.getBigInteger("id"); + break; + } + } + if (executionResultId.equals(BigInteger.valueOf(0))) { + String addExecutionResultApiUrl = "https://qtmcloud.qmetry.com/rest/api/latest/projects/10000/execution-results"; + String addExecutionResultResponse = getAddExecutionResultResponse(addExecutionResultApiUrl, userTestResultStatus); + executionResultId = getExecutionResultUsersStatus(addExecutionResultResponse); + } + + String updateTestCaseExecutionApiUrl = "https://qtmcloud.qmetry.com/rest/api/latest/testcycles/" + testCycleId + "/testcase-executions/" + testCaseExecutionId; + getPUTApiResponse(updateTestCaseExecutionApiUrl, executionResultId); + } + } catch (Exception e) { + System.out.println("----------EXCEPTIONS-----------" + e); + } finally { + if (driver != null) { + driver.quit(); // Ensure driver quits + } + } } - } From ea539616dcef6efa513878df96ae3a1a5d666200 Mon Sep 17 00:00:00 2001 From: deepanshusri <103935065+deepanshusri@users.noreply.github.com> Date: Fri, 20 Sep 2024 00:26:30 +0530 Subject: [PATCH 18/18] Update pom.xml --- pom.xml | 66 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index 2f4b6f9..a902d9a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,62 +1,80 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0%20http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 Java-TestNG-Selenium Java-TestNG-Selenium 0.0.1-SNAPSHOT + - Java-TestNG-Selenium/src + src/test/java + src/test/java - Java-TestNG-Selenium/src - - **/*.java - + src/main/resources maven-compiler-plugin - 3.7.0 + 3.10.1 - 10 + 11 org.apache.maven.plugins maven-surefire-plugin - 2.19.1 - - - - test - - - + 3.0.0-M5 - ${suite} - + org.seleniumhq.selenium selenium-java - 3.13.0 + 4.24.0 - org.testng testng - 6.14.3 + 7.7.0 + + org.apache.httpcomponents + httpclient + 4.5.14 + + + io.appium + java-client + 9.3.0 + + + org.json + json + 20210307 + + - + + + org.slf4j + slf4j-api + 1.7.30 + - \ No newline at end of file + + + ch.qos.logback + logback-classic + 1.2.3 + + +