-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualui.java
More file actions
94 lines (66 loc) · 3.41 KB
/
visualui.java
File metadata and controls
94 lines (66 loc) · 3.41 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
package com.lambdatest;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Hashtable;
public class visualui {
RemoteWebDriver driver = null;
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 = "LT_username";
String access_key = "LT_accesskey";
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("build", "VisualUI");
capabilities.setCapability("name", "Visual Ui Testing");
capabilities.setCapability("browserName", "chrome");
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","10689a4");
capabilities.setCapability("smartUI.options",sm);
//multiple baseline images for your project
capabilities.setCapability("smartUI.build","chrome 1");
capabilities.setCapability("selenium_version", "4.0.0");
driver = new RemoteWebDriver(new URL("http://" + username + ":" + access_key + "@hub.lambdatest.com/wd/hub"), capabilities);
@Test
public void basicTest() throws InterruptedException {
driver.get("https://www.lambdatest.com/");
Thread.sleep(5000);
driver.executeScript("smartui.takeFullPageScreenshot=pic1"); //takeFullPageScreenshot command will take the full page screenshot of the URL and supported only with selenium version 4.0 and above.
Thread.sleep(1000);
driver.get("https://www.lambdatest.com/pricing");
Thread.sleep(5000);
driver.executeScript("smartui.takeScreenshot=pic2");
Thread.sleep(1000);
driver.get("https://www.lambdatest.com/support/docs/");
Thread.sleep(5000);
driver.executeScript("smartui.takeScreenshot=pic3");
Thread.sleep(1000);
driver.executeScript("lambda-status=passed");
driver.quit();
Status = "passed";
Thread.sleep(800);
System.out.println("TestFinished");
}
@AfterMethod
public void tearDown() {
driver.executeScript("lambda-status=" + Status);
driver.quit();
}
}