From 99876c733211de5e3b7f19d38f323d2fe621e842 Mon Sep 17 00:00:00 2001 From: Mukesh Rana Date: Wed, 9 Aug 2023 20:26:15 +0530 Subject: [PATCH] Adding ReportPortal integration --- .gitignore | 1 + logback.xml | 41 ++++ mobile.xml | 10 +- parallel.xml | 14 +- pom.xml | 132 +++++++----- single.xml | 10 +- src/test/java/com/lambdatest/TestNGTodo1.java | 149 +++++++------ src/test/java/com/lambdatest/TestNGTodo2.java | 150 +++++++------ src/test/java/com/lambdatest/TestNGTodo3.java | 195 +++++++++-------- .../java/com/lambdatest/TestNGTodoMobile.java | 197 ++++++++++-------- src/test/resources/reportportal.properties | 4 + 11 files changed, 517 insertions(+), 386 deletions(-) create mode 100644 logback.xml create mode 100644 src/test/resources/reportportal.properties diff --git a/.gitignore b/.gitignore index f70e4d3..b66d425 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .project .settings .theia +.idea \ No newline at end of file diff --git a/logback.xml b/logback.xml new file mode 100644 index 0000000..756ff2b --- /dev/null +++ b/logback.xml @@ -0,0 +1,41 @@ + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + ${LOG_FILE}.log + + + ${LOG_FILE}.%d{yyyy-MM-dd}.gz + + 30 + 3GB + + + %-4relative [%thread] %-5level %logger{35} - %msg%n + + + + + + + + + + + %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n + + + + + + \ No newline at end of file diff --git a/mobile.xml b/mobile.xml index 18239ab..2f55c2c 100644 --- a/mobile.xml +++ b/mobile.xml @@ -1,9 +1,9 @@ - - - - - + + + + + \ No newline at end of file diff --git a/parallel.xml b/parallel.xml index 21cddc0..cb838c7 100644 --- a/parallel.xml +++ b/parallel.xml @@ -1,11 +1,11 @@ - - - - - - - + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 828b8f8..32aa33f 100644 --- a/pom.xml +++ b/pom.xml @@ -1,62 +1,80 @@ - 4.0.0 - Java-TestNG-Selenium - Java-TestNG-Selenium - 0.0.1-SNAPSHOT - - Java-TestNG-Selenium/src - - - Java-TestNG-Selenium/src - - **/*.java - - - - - - maven-compiler-plugin - 3.7.0 - - 10 - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.19.1 - - - - test - - - - - - - ${suite} - - - - + 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 + + + Java-TestNG-Selenium/src + + **/*.java + + + + + + maven-compiler-plugin + 3.7.0 + + 10 + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.19.1 + + + + test + + + + + + + ${suite} + + + + - - - - org.seleniumhq.selenium - selenium-java - 3.13.0 - - - - org.testng - testng - 7.7.0 - + + + + org.seleniumhq.selenium + selenium-java + 3.13.0 + + + + org.testng + testng + 7.8.0 + - + + com.epam.reportportal + agent-java-testng + 5.0.8 + + + + + com.epam.reportportal + logger-java-logback + 4.0.5 + + + + org.apache.logging.log4j + log4j-slf4j-impl + 2.16.0 + + \ No newline at end of file diff --git a/single.xml b/single.xml index 38a023f..14b4ebd 100644 --- a/single.xml +++ b/single.xml @@ -1,9 +1,9 @@ - - - - - + + + + + diff --git a/src/test/java/com/lambdatest/TestNGTodo1.java b/src/test/java/com/lambdatest/TestNGTodo1.java index 62577d1..cb8c1be 100644 --- a/src/test/java/com/lambdatest/TestNGTodo1.java +++ b/src/test/java/com/lambdatest/TestNGTodo1.java @@ -4,106 +4,123 @@ import java.net.MalformedURLException; import java.net.URL; +import com.epam.reportportal.testng.ReportPortalTestNGListener; import org.openqa.selenium.By; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testng.Assert; import org.testng.ITestContext; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Listeners; import org.testng.annotations.Test; -public class TestNGTodo1 { +@Listeners({ ReportPortalTestNGListener.class }) public class TestNGTodo1 { - private RemoteWebDriver driver; - private String Status = "failed"; + private RemoteWebDriver driver; + private String Status = "failed"; + private static final Logger ltLogger = LoggerFactory.getLogger(TestNGTodo1.class); - @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"; + @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"; + ltLogger.info("Creating Driver"); + 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"); - 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"); + String[] Tags = new String[] { "Feature", "Falcon", "Severe" }; + caps.setCapability("tags", Tags); - String[] Tags = new String[] { "Feature", "Falcon", "Severe" }; - caps.setCapability("tags", Tags); + driver = new RemoteWebDriver(new URL("https://" + username + ":" + authkey + hub), caps); - driver = new RemoteWebDriver(new URL("https://" + username + ":" + authkey + hub), caps); + } - } + @Test + public void basicTest() throws InterruptedException { + String spanText; + ltLogger.info("Loading Url"); + System.out.println("Loading Url"); - @Test - public void basicTest() throws InterruptedException { - String spanText; - System.out.println("Loading Url"); + driver.get("https://lambdatest.github.io/sample-todo-app/"); - driver.get("https://lambdatest.github.io/sample-todo-app/"); + ltLogger.info("Checking Box"); + System.out.println("Checking Box"); + driver.findElement(By.name("li1")).click(); - System.out.println("Checking Box"); - driver.findElement(By.name("li1")).click(); + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li2")).click(); - System.out.println("Checking Another Box"); - driver.findElement(By.name("li2")).click(); + ltLogger.info("Checking Box"); + System.out.println("Checking Box"); + driver.findElement(By.name("li3")).click(); - System.out.println("Checking Box"); - driver.findElement(By.name("li3")).click(); + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li4")).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 6"); - driver.findElement(By.id("addbutton")).click(); + driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 7"); + driver.findElement(By.id("addbutton")).click(); - driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 7"); - driver.findElement(By.id("addbutton")).click(); + driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 8"); + driver.findElement(By.id("addbutton")).click(); - driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 8"); - driver.findElement(By.id("addbutton")).click(); + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li1")).click(); - System.out.println("Checking Another Box"); - driver.findElement(By.name("li1")).click(); + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li3")).click(); - System.out.println("Checking Another Box"); - driver.findElement(By.name("li3")).click(); + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li7")).click(); - System.out.println("Checking Another Box"); - driver.findElement(By.name("li7")).click(); + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li8")).click(); + Thread.sleep(300); - System.out.println("Checking Another Box"); - driver.findElement(By.name("li8")).click(); - Thread.sleep(300); + ltLogger.info("Entering Text"); + System.out.println("Entering Text"); + driver.findElement(By.id("sampletodotext")).sendKeys("Get Taste of Lambda and Stick to It"); - System.out.println("Entering Text"); - driver.findElement(By.id("sampletodotext")).sendKeys("Get Taste of Lambda and Stick to It"); + driver.findElement(By.id("addbutton")).click(); - driver.findElement(By.id("addbutton")).click(); + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li9")).click(); - System.out.println("Checking Another Box"); - driver.findElement(By.name("li9")).click(); + // Let's also assert that the todo we added is present in the list. - // Let's also assert that the todo we added is present in the list. + 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); - 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); + ltLogger.info("TestFinished"); + System.out.println("TestFinished"); - System.out.println("TestFinished"); + } - } - - @AfterMethod - public void tearDown() { - driver.executeScript("lambda-status=" + Status); - driver.quit(); - } + @AfterMethod + public void tearDown() { + driver.executeScript("lambda-status=" + Status); + driver.quit(); + } } \ No newline at end of file diff --git a/src/test/java/com/lambdatest/TestNGTodo2.java b/src/test/java/com/lambdatest/TestNGTodo2.java index 3530993..b0f2e74 100644 --- a/src/test/java/com/lambdatest/TestNGTodo2.java +++ b/src/test/java/com/lambdatest/TestNGTodo2.java @@ -4,26 +4,31 @@ import java.net.MalformedURLException; import java.net.URL; +import com.epam.reportportal.testng.ReportPortalTestNGListener; import org.openqa.selenium.By; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testng.Assert; import org.testng.ITestContext; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Listeners; import org.testng.annotations.Test; -public class TestNGTodo2 { +@Listeners({ ReportPortalTestNGListener.class }) public class TestNGTodo2 { - private RemoteWebDriver driver; - private String Status = "failed"; + 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"); - ; - + private static final Logger ltLogger = LoggerFactory.getLogger(TestNGTodo2.class); + + @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"); + ; /* Steps to run Smart UI project (https://beta-smartui.lambdatest.com/) Step - 1 : Change the hub URL to @beta-smartui-hub.lambdatest.com/wd/hub @@ -32,90 +37,101 @@ Steps to run Smart UI project (https://beta-smartui.lambdatest.com/) Note: for additional capabilities navigate to https://www.lambdatest.com/support/docs/test-settings-options/ */ - String hub = "@hub.lambdatest.com/wd/hub"; - - DesiredCapabilities caps = new DesiredCapabilities(); - caps.setCapability("platform", "Windows 10"); - caps.setCapability("browserName", "chrome"); - caps.setCapability("version", "latest"); - caps.setCapability("build", "TestNG With Java"); - caps.setCapability("name", m.getName() + this.getClass().getName()); - caps.setCapability("plugin", "git-testng"); + String hub = "@hub.lambdatest.com/wd/hub"; + ltLogger.info("Creating Driver"); + DesiredCapabilities caps = new DesiredCapabilities(); + caps.setCapability("platform", "Windows 10"); + caps.setCapability("browserName", "chrome"); + caps.setCapability("version", "latest"); + caps.setCapability("build", "TestNG With Java"); + caps.setCapability("name", m.getName() + this.getClass().getName()); + caps.setCapability("plugin", "git-testng"); /* Enable Smart UI Project caps.setCapability("smartUI.project", ""); */ - String[] Tags = new String[] { "Feature", "Magicleap", "Severe" }; - caps.setCapability("tags", Tags); - - driver = new RemoteWebDriver(new URL("https://" + username + ":" + authkey + hub), caps); - } + String[] Tags = new String[] { "Feature", "Magicleap", "Severe" }; + caps.setCapability("tags", Tags); - @Test - public void basicTest() throws InterruptedException { - String spanText; - System.out.println("Loading Url"); + driver = new RemoteWebDriver(new URL("https://" + username + ":" + authkey + hub), caps); + } - driver.get("https://lambdatest.github.io/sample-todo-app/"); + @Test + public void basicTest() throws InterruptedException { + String spanText; + ltLogger.info("Loading Url"); + System.out.println("Loading Url"); - System.out.println("Checking Box"); - driver.findElement(By.name("li1")).click(); + driver.get("https://lambdatest.github.io/sample-todo-app/"); - System.out.println("Checking Another Box"); - driver.findElement(By.name("li2")).click(); + ltLogger.info("Checking Box"); + System.out.println("Checking Box"); + driver.findElement(By.name("li1")).click(); - System.out.println("Checking Box"); - driver.findElement(By.name("li3")).click(); + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li2")).click(); - System.out.println("Checking Another Box"); - driver.findElement(By.name("li4")).click(); + ltLogger.info("Checking Box"); + System.out.println("Checking Box"); + driver.findElement(By.name("li3")).click(); - driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 6"); - driver.findElement(By.id("addbutton")).click(); + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li4")).click(); - driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 7"); - driver.findElement(By.id("addbutton")).click(); + driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 6"); + driver.findElement(By.id("addbutton")).click(); - driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 8"); - driver.findElement(By.id("addbutton")).click(); + driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 7"); + driver.findElement(By.id("addbutton")).click(); - System.out.println("Checking Another Box"); - driver.findElement(By.name("li1")).click(); + driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 8"); + driver.findElement(By.id("addbutton")).click(); - System.out.println("Checking Another Box"); - driver.findElement(By.name("li3")).click(); + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li1")).click(); - System.out.println("Checking Another Box"); - driver.findElement(By.name("li7")).click(); + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li3")).click(); - System.out.println("Checking Another Box"); - driver.findElement(By.name("li8")).click(); + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li7")).click(); - System.out.println("Entering Text"); - driver.findElement(By.id("sampletodotext")).sendKeys("Get Taste of Lambda and Stick to It"); + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li8")).click(); - driver.findElement(By.id("addbutton")).click(); + ltLogger.info("Entering Text"); + System.out.println("Entering Text"); + driver.findElement(By.id("sampletodotext")).sendKeys("Get Taste of Lambda and Stick to It"); - System.out.println("Checking Another Box"); - driver.findElement(By.name("li9")).click(); + driver.findElement(By.id("addbutton")).click(); - // Let's also assert that the todo we added is present in the list. + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li9")).click(); - 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); + // Let's also assert that the todo we added is present in the list. - System.out.println("TestFinished"); + 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); - } + ltLogger.info("TestFinished"); + System.out.println("TestFinished"); - @AfterMethod - public void tearDown() { - driver.executeScript("lambda-status=" + Status); - driver.quit(); - } + } + @AfterMethod + public void tearDown() { + driver.executeScript("lambda-status=" + Status); + driver.quit(); + } } \ No newline at end of file diff --git a/src/test/java/com/lambdatest/TestNGTodo3.java b/src/test/java/com/lambdatest/TestNGTodo3.java index 632320c..2e39dcc 100644 --- a/src/test/java/com/lambdatest/TestNGTodo3.java +++ b/src/test/java/com/lambdatest/TestNGTodo3.java @@ -4,104 +4,121 @@ import java.net.MalformedURLException; import java.net.URL; +import com.epam.reportportal.testng.ReportPortalTestNGListener; import org.openqa.selenium.By; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testng.Assert; import org.testng.ITestContext; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Listeners; import org.testng.annotations.Test; -public class TestNGTodo3 { +@Listeners({ ReportPortalTestNGListener.class }) public class TestNGTodo3 { - 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", "latest"); - caps.setCapability("build", "TestNG With Java"); - caps.setCapability("name", m.getName() + this.getClass().getName()); - caps.setCapability("plugin", "git-testng"); - - String[] Tags = new String[] { "Feature", "Tag", "Moderate" }; - caps.setCapability("tags", Tags); - - driver = new RemoteWebDriver(new URL("https://" + username + ":" + authkey + hub), caps); - } - - @Test - public void basicTest() throws InterruptedException { - String spanText; - System.out.println("Loading Url"); - Thread.sleep(100); - 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(); - - driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 8"); - driver.findElement(By.id("addbutton")).click(); - - System.out.println("Checking Another Box"); - driver.findElement(By.name("li1")).click(); - - System.out.println("Checking Another Box"); - driver.findElement(By.name("li3")).click(); - - System.out.println("Checking Another Box"); - driver.findElement(By.name("li7")).click(); - - System.out.println("Checking Another Box"); - driver.findElement(By.name("li8")).click(); - - System.out.println("Entering Text"); - driver.findElement(By.id("sampletodotext")).sendKeys("Get Taste of Lambda and Stick to It"); - - driver.findElement(By.id("addbutton")).click(); - - System.out.println("Checking Another Box"); - driver.findElement(By.name("li9")).click(); - - // Let's also assert that the todo we added is present in the list. - - 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(800); - - System.out.println("TestFinished"); - - } - - @AfterMethod - public void tearDown() { - driver.executeScript("lambda-status=" + Status); - driver.quit(); - } + private RemoteWebDriver driver; + private String Status = "failed"; + private static final Logger ltLogger = LoggerFactory.getLogger(TestNGTodo3.class); + + @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"; + ltLogger.info("Creating Driver"); + DesiredCapabilities caps = new DesiredCapabilities(); + caps.setCapability("platform", "MacOS Catalina"); + caps.setCapability("browserName", "Chrome"); + caps.setCapability("version", "latest"); + caps.setCapability("build", "TestNG With Java"); + caps.setCapability("name", m.getName() + this.getClass().getName()); + caps.setCapability("plugin", "git-testng"); + + String[] Tags = new String[] { "Feature", "Tag", "Moderate" }; + caps.setCapability("tags", Tags); + + driver = new RemoteWebDriver(new URL("https://" + username + ":" + authkey + hub), caps); + } + + @Test + public void basicTest() throws InterruptedException { + String spanText; + ltLogger.info("Loading Url"); + System.out.println("Loading Url"); + Thread.sleep(100); + driver.get("https://lambdatest.github.io/sample-todo-app/"); + + ltLogger.info("Checking Box"); + System.out.println("Checking Box"); + driver.findElement(By.name("li1")).click(); + + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li2")).click(); + + ltLogger.info("Checking Box"); + System.out.println("Checking Box"); + driver.findElement(By.name("li3")).click(); + + ltLogger.info("Checking Another Box"); + 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(); + + driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 8"); + driver.findElement(By.id("addbutton")).click(); + + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li1")).click(); + + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li3")).click(); + + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li7")).click(); + + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li8")).click(); + + ltLogger.info("Entering Text"); + System.out.println("Entering Text"); + driver.findElement(By.id("sampletodotext")).sendKeys("Get Taste of Lambda and Stick to It"); + + driver.findElement(By.id("addbutton")).click(); + + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li9")).click(); + + // Let's also assert that the todo we added is present in the list. + + 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(800); + + ltLogger.info("TestFinished"); + System.out.println("TestFinished"); + + } + + @AfterMethod + public void tearDown() { + driver.executeScript("lambda-status=" + Status); + driver.quit(); + } } \ No newline at end of file diff --git a/src/test/java/com/lambdatest/TestNGTodoMobile.java b/src/test/java/com/lambdatest/TestNGTodoMobile.java index a81bd4c..975f367 100644 --- a/src/test/java/com/lambdatest/TestNGTodoMobile.java +++ b/src/test/java/com/lambdatest/TestNGTodoMobile.java @@ -4,105 +4,122 @@ import java.net.MalformedURLException; import java.net.URL; +import com.epam.reportportal.testng.ReportPortalTestNGListener; import org.openqa.selenium.By; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testng.Assert; import org.testng.ITestContext; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Listeners; import org.testng.annotations.Test; -public class TestNGTodoMobile { +@Listeners({ ReportPortalTestNGListener.class }) public class TestNGTodoMobile { - 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 = "@mobile-hub.lambdatest.com/wd/hub"; - - DesiredCapabilities caps = new DesiredCapabilities(); - caps.setCapability("platformName", "android"); - caps.setCapability("deviceName", "Pixel 4a"); - caps.setCapability("platformVersion", "11"); - caps.setCapability("isRealMobile", true); - caps.setCapability("build", "TestNG With Java"); - caps.setCapability("name", m.getName() + this.getClass().getName()); - caps.setCapability("plugin", "git-testng"); - - String[] Tags = new String[] { "Feature", "Tag", "Moderate" }; - caps.setCapability("tags", Tags); - - driver = new RemoteWebDriver(new URL("https://" + username + ":" + authkey + hub), caps); - } - - @Test - public void basicTest() throws InterruptedException { - String spanText; - System.out.println("Loading Url"); - Thread.sleep(100); - 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(); - - driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 8"); - driver.findElement(By.id("addbutton")).click(); - - System.out.println("Checking Another Box"); - driver.findElement(By.name("li1")).click(); - - System.out.println("Checking Another Box"); - driver.findElement(By.name("li3")).click(); - - System.out.println("Checking Another Box"); - driver.findElement(By.name("li7")).click(); - - System.out.println("Checking Another Box"); - driver.findElement(By.name("li8")).click(); - - System.out.println("Entering Text"); - driver.findElement(By.id("sampletodotext")).sendKeys("Get Taste of Lambda and Stick to It"); - - driver.findElement(By.id("addbutton")).click(); - - System.out.println("Checking Another Box"); - driver.findElement(By.name("li9")).click(); - - // Let's also assert that the todo we added is present in the list. - - 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(800); - - System.out.println("TestFinished"); - - } - - @AfterMethod - public void tearDown() { - driver.executeScript("lambda-status=" + Status); - driver.quit(); - } + private RemoteWebDriver driver; + private String Status = "failed"; + private static final Logger ltLogger = LoggerFactory.getLogger(TestNGTodoMobile.class); + + @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 = "@mobile-hub.lambdatest.com/wd/hub"; + ltLogger.info("Creating Driver"); + DesiredCapabilities caps = new DesiredCapabilities(); + caps.setCapability("platformName", "android"); + caps.setCapability("deviceName", "Pixel 4a"); + caps.setCapability("platformVersion", "11"); + caps.setCapability("isRealMobile", true); + caps.setCapability("build", "TestNG With Java"); + caps.setCapability("name", m.getName() + this.getClass().getName()); + caps.setCapability("plugin", "git-testng"); + + String[] Tags = new String[] { "Feature", "Tag", "Moderate" }; + caps.setCapability("tags", Tags); + + driver = new RemoteWebDriver(new URL("https://" + username + ":" + authkey + hub), caps); + } + + @Test + public void basicTest() throws InterruptedException { + String spanText; + ltLogger.info("Loading Url"); + System.out.println("Loading Url"); + Thread.sleep(100); + driver.get("https://lambdatest.github.io/sample-todo-app/"); + + ltLogger.info("Checking Box"); + System.out.println("Checking Box"); + driver.findElement(By.name("li1")).click(); + + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li2")).click(); + + ltLogger.info("Checking Box"); + System.out.println("Checking Box"); + driver.findElement(By.name("li3")).click(); + + ltLogger.info("Checking Another Box"); + 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(); + + driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 8"); + driver.findElement(By.id("addbutton")).click(); + + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li1")).click(); + + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li3")).click(); + + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li7")).click(); + + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li8")).click(); + + ltLogger.info("Entering Text"); + System.out.println("Entering Text"); + driver.findElement(By.id("sampletodotext")).sendKeys("Get Taste of Lambda and Stick to It"); + + driver.findElement(By.id("addbutton")).click(); + + ltLogger.info("Checking Another Box"); + System.out.println("Checking Another Box"); + driver.findElement(By.name("li9")).click(); + + // Let's also assert that the todo we added is present in the list. + + 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(800); + + ltLogger.info("TestFinished"); + System.out.println("TestFinished"); + + } + + @AfterMethod + public void tearDown() { + driver.executeScript("lambda-status=" + Status); + driver.quit(); + } } \ No newline at end of file diff --git a/src/test/resources/reportportal.properties b/src/test/resources/reportportal.properties new file mode 100644 index 0000000..3a4278b --- /dev/null +++ b/src/test/resources/reportportal.properties @@ -0,0 +1,4 @@ +rp.endpoint = https://reportportal.example.com +rp.uuid = YOUR_UUID +rp.launch = LAUNCH_NAME +rp.project = YOUR_PROJECT_NAME_ON_RP \ No newline at end of file