forked from LambdaTest/java-testng-selenium
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvisualui.java
74 lines (58 loc) · 2.46 KB
/
visualui.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
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.remote.DesiredCapabilities;
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 visualui {
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";
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("platform", "MacOS Catalina");
caps.setCapability("browserName", "Chrome");
caps.setCapability("version", "121");
caps.setCapability("build", "TestNG With Java + Visual UI");
caps.setCapability("name", m.getName() + " - " + this.getClass().getName());
caps.setCapability("plugin", "git-testng");
caps.setCapability("visual",true);
caps.setCapability("smartUI.project","Feb_12");
caps.setCapability("smartUI.build","build 1");
driver = new RemoteWebDriver(new URL("https://" + username + ":" + authkey + hub), caps);
}
@Test
public void basicTest() throws InterruptedException {
String spanText;
System.out.println("Loading Url");
driver.get("https://www.lambdatest.com");
Thread.sleep(5000);
driver.executeScript("smartui.takeScreenshot=pic1");
Thread.sleep(1000);
driver.get("https://www.lambdatest.com/support/docs/");
Thread.sleep(5000);
driver.executeScript("smartui.takeScreenshot=pic2");
Thread.sleep(1000);
driver.get("https://www.lambdatest.com/pricing");
Thread.sleep(5000);
driver.executeScript("smartui.takeScreenshot=pic3");
Thread.sleep(1000);
Status = "passed";
Thread.sleep(800);
System.out.println("TestFinished");
}
@AfterMethod
public void tearDown() {
driver.executeScript("lambda-status=" + Status);
driver.quit();
}
}