-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathTestNGTodo1.java
More file actions
110 lines (84 loc) · 4.65 KB
/
TestNGTodo1.java
File metadata and controls
110 lines (84 loc) · 4.65 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package com.lambdatest;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.safari.SafariOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.ITestContext;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class TestNGTodo1 {
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";
// ✅ Use LambdaTest W3C-compliant structure (LT:Options)
MutableCapabilities ltOptions = new MutableCapabilities();
ltOptions.setCapability("build", "TestNG With Java");
ltOptions.setCapability("name", m.getName() + " - " + this.getClass().getName());
ltOptions.setCapability("platformName", "macOS Sonoma"); // modern macOS
ltOptions.setCapability("plugin", "git-testng");
ltOptions.setCapability("tags", new String[] { "Feature", "Falcon", "Severe" });
/*
Enable Smart UI Project (optional)
ltOptions.setCapability("smartUI.project", "<Project Name>");
*/
// ✅ Safari browser setup (works with Selenium 4.x)
SafariOptions browserOptions = new SafariOptions();
browserOptions.setCapability("browserVersion", "latest");
browserOptions.setCapability("LT:Options", ltOptions);
driver = new RemoteWebDriver(new URL("https://" + username + ":" + authkey + hub), browserOptions);
}
@Test
public void basicTest() throws InterruptedException {
System.out.println("Loading Url");
driver.executeScript("lambdatest_executor: {\"action\": \"stepcontext\", \"arguments\": {\"data\": \"Opening WebApp\", \"level\": \"info\"}}");
driver.get("https://lambdatest.github.io/sample-todo-app/");
driver.executeScript("lambdatest_executor: {\"action\": \"stepcontext\", \"arguments\": {\"data\": \"Checking List Items\", \"level\": \"info\"}}");
System.out.println("Checking Boxes...");
driver.findElement(By.name("li1")).click();
driver.findElement(By.name("li2")).click();
driver.findElement(By.name("li3")).click();
driver.findElement(By.name("li4")).click();
driver.executeScript("lambdatest_executor: {\"action\": \"stepcontext\", \"arguments\": {\"data\": \"Adding Items\", \"level\": \"info\"}}");
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();
driver.executeScript("lambdatest_executor: {\"action\": \"stepcontext\", \"arguments\": {\"data\": \"Checking More Items\", \"level\": \"info\"}}");
driver.findElement(By.name("li1")).click();
driver.findElement(By.name("li3")).click();
driver.findElement(By.name("li7")).click();
driver.findElement(By.name("li8")).click();
Thread.sleep(300);
driver.executeScript("lambdatest_executor: {\"action\": \"stepcontext\", \"arguments\": {\"data\": \"Adding and Verify List Items\", \"level\": \"info\"}}");
driver.findElement(By.id("sampletodotext")).sendKeys("Get Taste of Lambda and Stick to It");
driver.findElement(By.id("addbutton")).click();
driver.findElement(By.name("li9")).click();
String spanText = driver.findElement(By.xpath("//li[9]/span")).getText();
Assert.assertEquals(spanText.trim(), "Get Taste of Lambda and Stick to It");
Status = "passed";
Thread.sleep(150);
System.out.println("Test Finished");
}
@AfterMethod
public void tearDown() {
try {
driver.executeScript("lambdatest_executor: {\"action\": \"stepcontext\", \"arguments\": {\"data\": \"Adding Test Result and Closing Browser\", \"level\": \"info\"}}");
driver.executeScript("lambda-status=" + Status);
} finally {
if (driver != null) {
driver.quit();
}
}
}
}