From 99876c733211de5e3b7f19d38f323d2fe621e842 Mon Sep 17 00:00:00 2001 From: Mukesh Rana <mukeshr@lambdatest.com> 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 @@ +<configuration> + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> + </encoder> + </appender> + + <root level="debug"> + <appender-ref ref="STDOUT"/> + </root> + + <!-- Rolling file appender to write logs to file as well --> + <property name="LOG_FILE" value="LogFile"/> + <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${LOG_FILE}.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + <!-- daily rollover --> + <fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.gz</fileNamePattern> + <!-- keep 30 days' worth of history capped at 3GB total size --> + <maxHistory>30</maxHistory> + <totalSizeCap>3GB</totalSizeCap> + </rollingPolicy> + <encoder> + <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern> + </encoder> + </appender> + + <root level="info"> + <appender-ref ref="FILE"/> + </root> + + <!-- Adds report portal appender to logback and allows it to all the logs to the test method --> + <appender name="ReportPortalAppender" class="com.epam.reportportal.logback.appender.ReportPortalAppender"> + <encoder> + <pattern>%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n</pattern> + </encoder> + </appender> + <root> + <appender-ref ref="ReportPortalAppender"/> + </root> +</configuration> \ 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 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite thread-count="1" parallel="tests" name="Suite"> - <test thread-count="1" parallel="classes" name="Test"> - <classes> - <class name="com.lambdatest.TestNGTodoMobile"/> - </classes> - </test> <!-- Test --> + <test thread-count="1" parallel="classes" name="Test"> + <classes> + <class name="com.lambdatest.TestNGTodoMobile"/> + </classes> + </test> <!-- Test --> </suite> <!-- Suite --> \ 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 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite thread-count="20" parallel="tests" name="Suite"> - <test thread-count="20" parallel="classes" name="Test"> - <classes> - <class name="com.lambdatest.TestNGTodo1"/> - <class name="com.lambdatest.TestNGTodo2"/> - <class name="com.lambdatest.TestNGTodo3"/> - </classes> - </test> <!-- Test --> + <test thread-count="20" parallel="classes" name="Test"> + <classes> + <class name="com.lambdatest.TestNGTodo1"/> + <class name="com.lambdatest.TestNGTodo2"/> + <class name="com.lambdatest.TestNGTodo3"/> + </classes> + </test> <!-- Test --> </suite> <!-- Suite --> \ 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 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>Java-TestNG-Selenium</groupId> - <artifactId>Java-TestNG-Selenium</artifactId> - <version>0.0.1-SNAPSHOT</version> - <build> - <sourceDirectory>Java-TestNG-Selenium/src</sourceDirectory> - <resources> - <resource> - <directory>Java-TestNG-Selenium/src</directory> - <excludes> - <exclude>**/*.java</exclude> - </excludes> - </resource> - </resources> - <plugins> - <plugin> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.7.0</version> - <configuration> - <release>10</release> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <version>2.19.1</version> - <executions> - <execution> - <goals> - <goal>test</goal> - </goals> - </execution> - </executions> - <configuration> - <suiteXmlFiles> - <!--suppress UnresolvedMavenProperty --> - <suiteXmlFile>${suite}</suiteXmlFile> - </suiteXmlFiles> - </configuration> - </plugin> - </plugins> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>Java-TestNG-Selenium</groupId> + <artifactId>Java-TestNG-Selenium</artifactId> + <version>0.0.1-SNAPSHOT</version> + <build> + <sourceDirectory>Java-TestNG-Selenium/src</sourceDirectory> + <resources> + <resource> + <directory>Java-TestNG-Selenium/src</directory> + <excludes> + <exclude>**/*.java</exclude> + </excludes> + </resource> + </resources> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.7.0</version> + <configuration> + <release>10</release> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.19.1</version> + <executions> + <execution> + <goals> + <goal>test</goal> + </goals> + </execution> + </executions> + <configuration> + <suiteXmlFiles> + <!--suppress UnresolvedMavenProperty --> + <suiteXmlFile>${suite}</suiteXmlFile> + </suiteXmlFiles> + </configuration> + </plugin> + </plugins> - </build> - <dependencies> - <dependency> - <groupId>org.seleniumhq.selenium</groupId> - <artifactId>selenium-java</artifactId> - <version>3.13.0</version> - </dependency> - <!-- https://mvnrepository.com/artifact/org.testng/testng --> - <dependency> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - <version>7.7.0</version> - </dependency> + </build> + <dependencies> + <dependency> + <groupId>org.seleniumhq.selenium</groupId> + <artifactId>selenium-java</artifactId> + <version>3.13.0</version> + </dependency> + <!-- https://mvnrepository.com/artifact/org.testng/testng --> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <version>7.8.0</version> + </dependency> - </dependencies> + <dependency> + <groupId>com.epam.reportportal</groupId> + <artifactId>agent-java-testng</artifactId> + <version>5.0.8</version> + </dependency> + + <!-- https://mvnrepository.com/artifact/com.epam.reportportal/logger-java-logback --> + <dependency> + <groupId>com.epam.reportportal</groupId> + <artifactId>logger-java-logback</artifactId> + <version>4.0.5</version> + </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + <version>2.16.0</version> + </dependency> + </dependencies> </project> \ 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 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite thread-count="1" parallel="tests" name="Suite"> - <test thread-count="1" parallel="classes" name="Test"> - <classes> - <class name="com.lambdatest.TestNGTodo2"/> - </classes> - </test> <!-- Test --> + <test thread-count="1" parallel="classes" name="Test"> + <classes> + <class name="com.lambdatest.TestNGTodo2"/> + </classes> + </test> <!-- Test --> </suite> <!-- Suite --> 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", "<Project Name>"); */ - 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