-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathSmartUI.java
More file actions
86 lines (73 loc) · 3.31 KB
/
Copy pathSmartUI.java
File metadata and controls
86 lines (73 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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();
Map<String, Object> ltOptions = new HashMap<>();
ltOptions.put("build", "JUnitSampleTestApp");
ltOptions.put("name", "JUnitSampleTest");
ltOptions.put("project", "SmartUI-Junit-Selenium"); //Enter Project name here
ltOptions.put("smartUI.project", "Junit-Selenium"); //Enter smartUI Project name here
if(System.getenv("BUILD_NAME")!=null && System.getenv("BUILD_NAME")!=""){
ltOptions.put("smartUI.build",System.getenv("BUILD_NAME"));
}
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<String,Object> 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();
}
}
}