forked from saucelabs-training/demo-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleVisualE2ETest.java
55 lines (44 loc) · 2.15 KB
/
SimpleVisualE2ETest.java
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
package com.saucedemo;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
import java.util.Map;
import static org.junit.Assert.assertEquals;
public class SimpleVisualE2ETest {
protected WebDriver webDriver;
public String sauceUsername = System.getenv("SAUCE_USERNAME");
public String sauceAccessKey = System.getenv("SAUCE_ACCESS_KEY");
public String screenerApiKey = System.getenv("SCREENER_API_KEY");
@Before
public void setUp() throws Exception {
MutableCapabilities capabilities = new MutableCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "chrome");
capabilities.setCapability(CapabilityType.BROWSER_VERSION, "latest");
capabilities.setCapability(CapabilityType.PLATFORM_NAME, "Windows 10");
MutableCapabilities sauceOptions = new MutableCapabilities();
sauceOptions.setCapability("username", sauceUsername);
sauceOptions.setCapability("accesskey", sauceAccessKey);
capabilities.setCapability("sauce:options", sauceOptions);
MutableCapabilities visualOptions = new MutableCapabilities();
visualOptions.setCapability("apiKey", screenerApiKey);
visualOptions.setCapability("projectName", "visual-e2e-test");
visualOptions.setCapability("viewportSize", "1280x1024");
capabilities.setCapability("sauce:visual", visualOptions);
URL url = new URL("https://hub.screener.io/wd/hub");
webDriver = new RemoteWebDriver(url, capabilities);
}
@Test
public void testVisualE2E() {
webDriver.get("https://screener.io");
JavascriptExecutor js = (JavascriptExecutor) webDriver;
js.executeScript("/*@visual.init*/", "My Visual Test 2");
js.executeScript("/*@visual.snapshot*/", "Home");
Map<String, Object> response = (Map<String, Object>) js.executeScript("/*@visual.end*/");
assertEquals( true, response.get("passed"));
}
}