- Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathJUnitConcurrentTodo.java
105 lines (94 loc) · 4.24 KB
/
JUnitConcurrentTodo.java
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
packagecom.lambdatest;
importorg.openqa.selenium.By;
importorg.openqa.selenium.chrome.ChromeOptions;
importorg.openqa.selenium.remote.DesiredCapabilities;
importorg.openqa.selenium.remote.RemoteWebDriver;
importorg.junit.After;
importorg.junit.Before;
importorg.junit.Test;
importorg.junit.runner.RunWith;
importorg.junit.runners.Parameterized;
importjava.net.MalformedURLException;
importjava.net.URL;
importjava.util.HashMap;
importjava.util.LinkedList;
importjava.util.Map;
@RunWith(Parallelized.class)
publicclassJUnitConcurrentTodo {
Stringusername = System.getenv("LT_USERNAME") == null ? "Your LT Username" : System.getenv("LT_USERNAME");
StringaccessKey = System.getenv("LT_ACCESS_KEY") == null ? "Your LT AccessKey" : System.getenv("LT_ACCESS_KEY");
publicStringgridURL = "@hub.lambdatest.com/wd/hub";
publicStringplatform;
publicStringbrowserName;
publicStringbrowserVersion;
publicRemoteWebDriverdriver = null;
publicStringstatus = "failed";
@Parameterized.Parameters
publicstaticLinkedList<String[]> getEnvironments() throwsException {
LinkedList<String[]> env = newLinkedList<String[]>();
env.add(newString[]{"Windows 10", "chrome", "latest"});
env.add(newString[]{"Windows 10","firefox","latest"});
env.add(newString[]{"Windows 10","edge","latest"});
returnenv;
}
publicJUnitConcurrentTodo(Stringplatform, StringbrowserName, StringbrowserVersion) {
this.platform = platform;
this.browserName = browserName;
this.browserVersion = browserVersion;
}
@Before
publicvoidsetUp() throwsException {
ChromeOptionsbrowserOptions = newChromeOptions();
browserOptions.setCapability("platformName", platform);
browserOptions.setCapability("browserName", browserName);
browserOptions.setCapability("browserVersion", browserVersion);
Map<String, Object> ltOptions = newHashMap<>();
ltOptions.put("build", "JUnitParallelSampleApp");
ltOptions.put("name", "JUnitParallelSampleTest");
ltOptions.put("selenium_version", "4.0.0");
// ltOptions.put("project", ""); //Enter Project name here
ltOptions.put("smartUI.project", ""); //Enter smartUI Project name here
ltOptions.put("w3c", true);
ltOptions.put("plugin", "junit-junit");
// ltOptions.put("visual", true); // To enable step by step screenshot
// ltOptions.put("network", true); // To enable network logs
// ltOptions.put("video", true); // To enable video recording
// ltOptions.put("console", true); // To capture console logs
browserOptions.setCapability("LT:Options", ltOptions);
try {
driver = newRemoteWebDriver(newURL("https://" + username + ":" + accessKey + gridURL), browserOptions);
} catch (MalformedURLExceptione) {
System.out.println("Invalid grid URL");
} catch (Exceptione) {
System.out.println(e.getMessage());
}
}
@Test
publicvoidtestParallel() throwsException {
try {
//Change it to production page
driver.get("https://lambdatest.github.io/sample-todo-app/");
// Add Webhook here for Screenshot
//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.
StringenteredText = driver.findElementByXPath("/html/body/div/div/div/ul/li[6]/span").getText();
if (enteredText.equals("Yey, Let's add it to list")) {
status = "passed";
}
} catch (Exceptione) {
System.out.println(e.getMessage());
}
}
@After
publicvoidtearDown() throwsException {
if (driver != null) {
driver.executeScript("lambda-status=" + status);
driver.quit();
}
}
}