From daf1d1acea2b0defa7586a07c0f1220856b663ce Mon Sep 17 00:00:00 2001 From: shreyanshc Date: Fri, 27 Jun 2025 13:18:23 +0530 Subject: [PATCH 1/2] Added smartui sample --- pom.xml | 17 +++++ src/test/java/com/lambdatest/SmartUI.java | 86 +++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 src/test/java/com/lambdatest/SmartUI.java diff --git a/pom.xml b/pom.xml index 275cbfd..befc8ec 100644 --- a/pom.xml +++ b/pom.xml @@ -105,6 +105,23 @@ + + smartui + + + + org.apache.maven.plugins + maven-surefire-plugin + + + com/lambdatest/SmartUI.java + + + + + + + \ No newline at end of file diff --git a/src/test/java/com/lambdatest/SmartUI.java b/src/test/java/com/lambdatest/SmartUI.java new file mode 100644 index 0000000..5ca59f5 --- /dev/null +++ b/src/test/java/com/lambdatest/SmartUI.java @@ -0,0 +1,86 @@ +package com.lambdatest; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebDriver; +import org.openqa.selenium.By; +import org.openqa.selenium.chrome.ChromeOptions; +import java.net.MalformedURLException; +import org.openqa.selenium.JavascriptExecutor; +import java.net.URL; +import java.util.*; +import java.util.HashMap; +import java.util.Map; + +public class SmartUI { + String username = System.getenv("LT_USERNAME") == null ? "Your LT Username" : System.getenv("LT_USERNAME"); + String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "Your LT AccessKey" : System.getenv("LT_ACCESS_KEY"); + public static RemoteWebDriver driver = null; + + public String gridURL = "@hub.lambdatest.com/wd/hub"; + public String status = "failed"; + + @Before + public void setUp() throws Exception { + ChromeOptions browserOptions = new ChromeOptions(); + browserOptions.setCapability("platformName", "Windows 10"); + browserOptions.setCapability("browserVersion", "latest"); + + Map ltOptions = new HashMap<>(); + ltOptions.put("build", "JUnitSampleTestApp"); + ltOptions.put("name", "JUnitSampleTest"); + ltOptions.put("selenium_version", "4.0.0"); + ltOptions.put("project", "SmartUI-Junit-Selenium"); //Enter Project name here + ltOptions.put("smartUI.project", "Junit-Selenium"); //Enter smartUI Project name here + ltOptions.put("w3c", true); + ltOptions.put("plugin", "junit-junit"); + browserOptions.setCapability("LT:Options", ltOptions); + + try { + driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + gridURL), browserOptions); + } catch (MalformedURLException e) { + System.out.println("Invalid grid URL"); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } + + @Test + public void testSimple() throws Exception { + try { + driver.get("https://lambdatest.github.io/sample-todo-app/"); + + //Let's mark done first two items in the list. + driver.findElement(By.name("li1")).click(); + driver.findElement(By.name("li2")).click(); + + // Let's add an item in the list. + driver.findElement(By.id("sampletodotext")).sendKeys("Yey, Let's add it to list"); + driver.findElement(By.id("addbutton")).click(); + + // Let's check that the item we added is added in the list. + String enteredText = driver.findElementByXPath("/html/body/div/div/div/ul/li[6]/span").getText(); + if (enteredText.equals("Yey, Let's add it to list")) { + status = "passed"; + } + + // Webhook for Screenshot + Map config = new HashMap<>(); + config.put("screenshotName","todo-list"); //Add your snapshot name here for SmartUI + ((JavascriptExecutor)driver).executeScript("smartui.takeScreenshot", config); //Hook for capturing snapshot on SmartUI + + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } + @After + public void tearDown() throws Exception { + if (driver != null) { + driver.executeScript("lambda-status=" + status); + driver.quit(); + } + } +} + From 341003b23dc644c682abd37a16f66ed3fdc2c9ca Mon Sep 17 00:00:00 2001 From: shreyanshc Date: Fri, 27 Jun 2025 14:41:17 +0530 Subject: [PATCH 2/2] Added smartui sample --- src/test/java/com/lambdatest/SmartUI.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/test/java/com/lambdatest/SmartUI.java b/src/test/java/com/lambdatest/SmartUI.java index 5ca59f5..6e87dc2 100644 --- a/src/test/java/com/lambdatest/SmartUI.java +++ b/src/test/java/com/lambdatest/SmartUI.java @@ -25,13 +25,10 @@ public class SmartUI { @Before public void setUp() throws Exception { ChromeOptions browserOptions = new ChromeOptions(); - browserOptions.setCapability("platformName", "Windows 10"); - browserOptions.setCapability("browserVersion", "latest"); Map ltOptions = new HashMap<>(); ltOptions.put("build", "JUnitSampleTestApp"); ltOptions.put("name", "JUnitSampleTest"); - ltOptions.put("selenium_version", "4.0.0"); ltOptions.put("project", "SmartUI-Junit-Selenium"); //Enter Project name here ltOptions.put("smartUI.project", "Junit-Selenium"); //Enter smartUI Project name here ltOptions.put("w3c", true);