|
| 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