forked from saucelabs-training/demo-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisualCrossPlatformTests.java
101 lines (87 loc) · 3.69 KB
/
VisualCrossPlatformTests.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
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
98
99
100
101
package com.saucedemo.tests;
import com.pages.CheckoutStepOnePage;
import com.pages.LoginPage;
import com.pages.ProductsPage;
import com.pages.ShoppingCartPage;
import com.saucedemo.Endpoints;
import com.saucedemo.WebTestsBase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import static org.junit.Assert.assertTrue;
@RunWith(Parameterized.class)
public class VisualCrossPlatformTests extends WebTestsBase {
/*
* Configure our data driven parameters
* */
@Parameterized.Parameter
public String browserName;
@Parameterized.Parameter(2)
public String browserVersion;
@Parameterized.Parameter(1)
public String platform;
@Parameterized.Parameter(3)
public String viewportSize;
@Parameterized.Parameter(4)
public String deviceName;
String deviceNameValue;
@Parameterized.Parameters(name = "{4}")
public static Collection<Object[]> crossBrowserData() {
return Arrays.asList(new Object[][]{
{"Chrome", "Windows 10", "latest", "412x732", "Pixel XL"},
{"Chrome", "Windows 10", "latest", "412x869", "Galaxy Note 10+"},
{"Safari", "macOS 10.15", "latest", "375x812", "iPhone X"}
});
}
@Before
public void setUp() throws Exception {
deviceNameValue = testName.getMethodName().split("\\[", -1)[1];
MutableCapabilities browserOptions = new MutableCapabilities();
browserOptions.setCapability(CapabilityType.BROWSER_NAME, browserName);
browserOptions.setCapability(CapabilityType.BROWSER_VERSION, browserVersion);
browserOptions.setCapability(CapabilityType.PLATFORM_NAME, platform);
MutableCapabilities sauceOptions = new MutableCapabilities();
sauceOptions.setCapability("username", sauceUsername);
sauceOptions.setCapability("accesskey", sauceAccessKey);
sauceOptions.setCapability("build", buildName);
browserOptions.setCapability("sauce:options", sauceOptions);
MutableCapabilities visualOptions = new MutableCapabilities();
visualOptions.setCapability("apiKey", screenerApiKey);
visualOptions.setCapability("projectName", "Sauce Demo");
visualOptions.setCapability("viewportSize", viewportSize);
browserOptions.setCapability("sauce:visual", visualOptions);
URL url = Endpoints.getScreenerHub();
driver = new RemoteWebDriver(url, browserOptions);
}
@After
public void afterEach()
{
Map<String, Object> response = (Map<String, Object>) getJSExecutor().executeScript("/*@visual.end*/");
boolean isTestPassed = Boolean.parseBoolean(response.get("passed").toString());
assertTrue(isTestPassed);
}
@Test()
public void pagesRenderCorrectly() {
LoginPage loginPage = new LoginPage(driver);
loginPage.visit();
getJSExecutor().executeScript("/*@visual.init*/", "Responsive Flows");
loginPage.takeSnapshot(deviceNameValue);
loginPage.login("standard_user");
new ProductsPage(driver).takeSnapshot(deviceNameValue);
ShoppingCartPage shoppingCartPage = new ShoppingCartPage(driver);
shoppingCartPage.visit();
shoppingCartPage.takeSnapshot(deviceNameValue);
CheckoutStepOnePage stepOneCheckoutPage = new CheckoutStepOnePage(driver);
stepOneCheckoutPage.visit();
stepOneCheckoutPage.takeSnapshot(deviceNameValue);
}
}