-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualui2.java
More file actions
97 lines (71 loc) · 3.24 KB
/
visualui2.java
File metadata and controls
97 lines (71 loc) · 3.24 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
92
93
94
95
96
97
package com.lambdatest;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.NoSuchAlgorithmException;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.Hashtable;
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;
import org.openqa.selenium.Alert;
public class visualui2 {
private RemoteWebDriver driver;
private String Status = "failed";
@BeforeMethod
public void setup(Method m, ITestContext ctx) throws MalformedURLException, NoSuchAlgorithmException {
Hashtable<String, Integer> errorColor= new Hashtable<>();
errorColor.put("red",255);
errorColor.put("green",0);
errorColor.put("blue",0);
HashMap<String,Object> output= new HashMap<String, Object>();
output.put("errorColor",errorColor);//Output Difference error color
output.put("transparency",0.1);// Set transparency of Output
output.put("largeImageThreshold",1200);// the granularity to which the comparison happens(the scale or level of detail in a set of data.)Range-100-1200
HashMap<String, Object> sm=new HashMap<String, Object>();
sm.put("output",output);
sm.put("scaleToSameSize",true);//scale to same size, when baseline image and comparision image is of different size, use true
String username = "your_LT_username";
String access_key = "your_LT_access_key";
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("build", "VisualUI"+ LocalDate.now());
capabilities.setCapability("name", "Visual Ui Testing");
capabilities.setCapability("browserName", "firefox");
capabilities.setCapability("platformName", "Windows 11");
capabilities.setCapability("browserVersion", "114.0");
capabilities.setCapability("visual",true);
capabilities.setCapability("smartUI.project","your_project_name");
capabilities.setCapability("smartUI.build","your_build_name");
driver = new RemoteWebDriver(new URL("http://" + username + ":" + access_key + "@hub.lambdatest.com/wd/hub"), capabilities);
}
@Test
public void basicTest() throws InterruptedException {
String spanText;
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();
}
}