Skip to content

Commit 0b0d954

Browse files
authored
Merge pull request #10 from shreyansh-chandel/Add-sync-true-sample
Added sync true sample
2 parents 418bdbc + 5d3d6c3 commit 0b0d954

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,19 @@
6565
<dependency>
6666
<groupId>io.github.lambdatest</groupId>
6767
<artifactId>lambdatest-java-sdk</artifactId>
68-
<version>1.0.7</version>
68+
<version>1.0.21</version>
6969
</dependency>
7070
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
7171
<dependency>
7272
<groupId>io.github.bonigarcia</groupId>
7373
<artifactId>webdrivermanager</artifactId>
7474
<version>5.6.3</version>
7575
</dependency>
76+
<dependency>
77+
<groupId>org.json</groupId>
78+
<artifactId>json</artifactId>
79+
<version>20250517</version>
80+
</dependency>
7681

7782
</dependencies>
7883

sdk-cloud-sync.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
3+
<suite thread-count="1" parallel="tests" name="Suite">
4+
<test thread-count="1" parallel="classes" name="Test">
5+
<classes>
6+
<class name="com.lambdatest.sdk.SmartUISDKCloudSync"/>
7+
</classes>
8+
</test> <!-- Test -->
9+
</suite> <!-- Suite -->
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.lambdatest.sdk;
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.SmartUISnapshot;
17+
import org.json.JSONObject;
18+
import org.testng.Assert;
19+
20+
public class SmartUISDKCloudSync {
21+
22+
private RemoteWebDriver driver;
23+
private String Status = "failed";
24+
private String githubURL = System.getenv("GITHUB_URL");
25+
26+
@BeforeMethod
27+
public void setup(Method m, ITestContext ctx) throws MalformedURLException {
28+
String username = System.getenv("LT_USERNAME") == null ? "Your LT Username" : System.getenv("LT_USERNAME");
29+
String authkey = System.getenv("LT_ACCESS_KEY") == null ? "Your LT AccessKey" : System.getenv("LT_ACCESS_KEY");
30+
String hub = "@hub.lambdatest.com/wd/hub";
31+
32+
DesiredCapabilities caps = new DesiredCapabilities();
33+
caps.setCapability("platform", "Catalina");
34+
caps.setCapability("browserName", "chrome");
35+
caps.setCapability("version", "latest");
36+
caps.setCapability("build", "TestNG With Java");
37+
caps.setCapability("name", m.getName() + " - " + this.getClass().getName());
38+
39+
if (githubURL != null) {
40+
Map<String, String> github = new HashMap<String, String>();
41+
github.put("url",githubURL);
42+
caps.setCapability("github", github);
43+
}
44+
System.out.println(caps);
45+
driver = new RemoteWebDriver(new URL("https://" + username + ":" + authkey + hub), caps);
46+
47+
}
48+
49+
@Test
50+
public void basicTest() throws Exception {
51+
System.out.println("Loading Url");
52+
driver.get("https://www.lambdatest.com");
53+
Thread.sleep(1000);
54+
HashMap<String ,Object> config = new HashMap<>();
55+
config.put("sync",true);
56+
JSONObject response = SmartUISnapshot.smartuiSnapshot(driver, "homepage",config);
57+
System.out.println(response);
58+
Assert.assertEquals(response.get("snapshotName"),"homepage");
59+
Assert.assertEquals(response.get("error"),"");
60+
Assert.assertEquals(response.getJSONArray("screenshots").length(),14);
61+
System.out.println("Test Finished");
62+
}
63+
64+
@AfterMethod
65+
public void tearDown() {
66+
driver.executeScript("lambda-status=" + Status);
67+
driver.quit();
68+
}
69+
70+
}

0 commit comments

Comments
 (0)