-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathTestNGSmartUI.java
More file actions
91 lines (77 loc) · 2.91 KB
/
TestNGSmartUI.java
File metadata and controls
91 lines (77 loc) · 2.91 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
package com.lambdatest;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
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 TestNGSmartUI {
private RemoteWebDriver driver;
private String Status = "failed";
private String githubURL = System.getenv("GITHUB_URL");
@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", "Windows 10");
caps.setCapability("browserName", "chrome");
caps.setCapability("version", "latest");
caps.setCapability("build", "TestNG With Java");
caps.setCapability("name", m.getName() + " - " + this.getClass().getName());
caps.setCapability("plugin", "git-testng");
caps.setCapability("smartUI.project", "testng-smartui-web-project");
if(System.getenv("BUILD_NAME")!=null && System.getenv("BUILD_NAME")!=""){
caps.setCapability("smartUI.build",System.getenv("BUILD_NAME"));
}
caps.setCapability("selenium_version", "4.8.0");
if (githubURL != null) {
Map<String, String> github = new HashMap<String, String>();
github.put("url", githubURL);
caps.setCapability("github", github);
}
System.out.println(caps);
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);
System.out.println("Taking FullPage Screenshot");
driver.executeScript("smartui.takeFullPageScreenshot=home-page");
Thread.sleep(1000);
driver.get("https://www.lambdatest.com/pricing");
Thread.sleep(5000);
System.out.println("Taking Pricing Page Screenshot");
driver.executeScript("smartui.takeScreenshot=pricing-page");
Thread.sleep(1000);
driver.get("https://www.lambdatest.com/support/docs/");
Thread.sleep(5000);
System.out.println("Taking Docs Page Screenshot");
driver.executeScript("smartui.takeScreenshot=docs");
Status = "passed";
System.out.println("TestFinished");
}
@AfterMethod
public void tearDown() {
driver.executeScript("lambda-status=" + Status);
driver.quit();
}
}