Skip to content

Commit daf1d1a

Browse files
Added smartui sample
1 parent 944f029 commit daf1d1a

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,23 @@
105105
</build>
106106
</profile>
107107

108+
<profile>
109+
<id>smartui</id>
110+
<build>
111+
<plugins>
112+
<plugin>
113+
<groupId>org.apache.maven.plugins</groupId>
114+
<artifactId>maven-surefire-plugin</artifactId>
115+
<configuration>
116+
<includes>
117+
<include>com/lambdatest/SmartUI.java</include>
118+
</includes>
119+
</configuration>
120+
</plugin>
121+
</plugins>
122+
</build>
123+
</profile>
124+
108125
</profiles>
109126

110127
</project>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.lambdatest;
2+
3+
import org.junit.After;
4+
import org.junit.Before;
5+
import org.junit.Test;
6+
import org.openqa.selenium.remote.DesiredCapabilities;
7+
import org.openqa.selenium.remote.RemoteWebDriver;
8+
import org.openqa.selenium.By;
9+
import org.openqa.selenium.chrome.ChromeOptions;
10+
import java.net.MalformedURLException;
11+
import org.openqa.selenium.JavascriptExecutor;
12+
import java.net.URL;
13+
import java.util.*;
14+
import java.util.HashMap;
15+
import java.util.Map;
16+
17+
public class SmartUI {
18+
String username = System.getenv("LT_USERNAME") == null ? "Your LT Username" : System.getenv("LT_USERNAME");
19+
String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "Your LT AccessKey" : System.getenv("LT_ACCESS_KEY");
20+
public static RemoteWebDriver driver = null;
21+
22+
public String gridURL = "@hub.lambdatest.com/wd/hub";
23+
public String status = "failed";
24+
25+
@Before
26+
public void setUp() throws Exception {
27+
ChromeOptions browserOptions = new ChromeOptions();
28+
browserOptions.setCapability("platformName", "Windows 10");
29+
browserOptions.setCapability("browserVersion", "latest");
30+
31+
Map<String, Object> ltOptions = new HashMap<>();
32+
ltOptions.put("build", "JUnitSampleTestApp");
33+
ltOptions.put("name", "JUnitSampleTest");
34+
ltOptions.put("selenium_version", "4.0.0");
35+
ltOptions.put("project", "SmartUI-Junit-Selenium"); //Enter Project name here
36+
ltOptions.put("smartUI.project", "Junit-Selenium"); //Enter smartUI Project name here
37+
ltOptions.put("w3c", true);
38+
ltOptions.put("plugin", "junit-junit");
39+
browserOptions.setCapability("LT:Options", ltOptions);
40+
41+
try {
42+
driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + gridURL), browserOptions);
43+
} catch (MalformedURLException e) {
44+
System.out.println("Invalid grid URL");
45+
} catch (Exception e) {
46+
System.out.println(e.getMessage());
47+
}
48+
}
49+
50+
@Test
51+
public void testSimple() throws Exception {
52+
try {
53+
driver.get("https://lambdatest.github.io/sample-todo-app/");
54+
55+
//Let's mark done first two items in the list.
56+
driver.findElement(By.name("li1")).click();
57+
driver.findElement(By.name("li2")).click();
58+
59+
// Let's add an item in the list.
60+
driver.findElement(By.id("sampletodotext")).sendKeys("Yey, Let's add it to list");
61+
driver.findElement(By.id("addbutton")).click();
62+
63+
// Let's check that the item we added is added in the list.
64+
String enteredText = driver.findElementByXPath("/html/body/div/div/div/ul/li[6]/span").getText();
65+
if (enteredText.equals("Yey, Let's add it to list")) {
66+
status = "passed";
67+
}
68+
69+
// Webhook for Screenshot
70+
Map<String,Object> config = new HashMap<>();
71+
config.put("screenshotName","todo-list"); //Add your snapshot name here for SmartUI
72+
((JavascriptExecutor)driver).executeScript("smartui.takeScreenshot", config); //Hook for capturing snapshot on SmartUI
73+
74+
} catch (Exception e) {
75+
System.out.println(e.getMessage());
76+
}
77+
}
78+
@After
79+
public void tearDown() throws Exception {
80+
if (driver != null) {
81+
driver.executeScript("lambda-status=" + status);
82+
driver.quit();
83+
}
84+
}
85+
}
86+

0 commit comments

Comments
 (0)