Skip to content

Commit 4d8e6cb

Browse files
authored
Create JavaSmartUISDK
SmartUI SDK Java Sample file
1 parent bf50dc3 commit 4d8e6cb

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.lambdatest;
2+
3+
import java.lang.reflect.Method;
4+
import java.net.MalformedURLException;
5+
import java.net.URL;
6+
import java.util.*;
7+
8+
import org.openqa.selenium.By;
9+
import org.openqa.selenium.remote.DesiredCapabilities;
10+
import org.openqa.selenium.remote.RemoteWebDriver;
11+
import org.testng.Assert;
12+
import org.testng.ITestContext;
13+
import org.testng.annotations.AfterMethod;
14+
import org.testng.annotations.BeforeMethod;
15+
import org.testng.annotations.Test;
16+
import io.github.lambdatest.*;
17+
18+
public class JavaSmartUISDK {
19+
20+
private RemoteWebDriver driver;
21+
private String Status = "failed";
22+
private String githubURL = System.getenv("GITHUB_URL");
23+
24+
25+
@BeforeMethod
26+
public void setup(Method m, ITestContext ctx) throws MalformedURLException {
27+
String username = System.getenv("LT_USERNAME") == null ? "Your LT Username" : System.getenv("LT_USERNAME");
28+
String authkey = System.getenv("LT_ACCESS_KEY") == null ? "Your LT AccessKey" : System.getenv("LT_ACCESS_KEY");
29+
String hub = "@hub.lambdatest.com/wd/hub";
30+
31+
DesiredCapabilities caps = new DesiredCapabilities();
32+
caps.setCapability("platform", "Catalina");
33+
caps.setCapability("browserName", "chrome");
34+
caps.setCapability("version", "latest");
35+
caps.setCapability("build", "TestNG With Java");
36+
caps.setCapability("name", m.getName() + " - " + this.getClass().getName());
37+
caps.setCapability("plugin", "git-testng");
38+
// caps.setCapability("smartUI.project","testng-smartui-project");
39+
caps.setCapability("selenium_version", "4.8.0");
40+
41+
if (githubURL != null) {
42+
Map<String, String> github = new HashMap<String, String>();
43+
github.put("url",githubURL);
44+
caps.setCapability("github", github);
45+
}
46+
System.out.println(caps);
47+
driver = new RemoteWebDriver(new URL("https://" + username + ":" + authkey + hub), caps);
48+
49+
}
50+
51+
@Test
52+
public void basicTest() throws Exception {
53+
String spanText;
54+
System.out.println("Loading Url");
55+
56+
57+
driver.get("https://in.pinterest.com/");
58+
59+
SmartUISnapshot.smartuiSnapshot(driver, "homepage");
60+
61+
Thread.sleep(5000);
62+
63+
Thread.sleep(1000);
64+
65+
driver.get("https://www.lambdatest.com/pricing");
66+
Thread.sleep(5000);
67+
68+
69+
Thread.sleep(1000);
70+
71+
driver.get("https://www.lambdatest.com/support/docs/");
72+
Thread.sleep(5000);
73+
Thread.sleep(1000);
74+
75+
76+
System.out.println("TestFinished");
77+
78+
}
79+
80+
@AfterMethod
81+
public void tearDown() {
82+
driver.executeScript("lambda-status=" + Status);
83+
driver.quit();
84+
}
85+
86+
}

0 commit comments

Comments
 (0)