-
Notifications
You must be signed in to change notification settings - Fork 34
/
EmulationTests.java
84 lines (72 loc) · 3.48 KB
/
EmulationTests.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
package tests.usecases.devtools;
import aquality.selenium.browser.AlertActions;
import aquality.selenium.browser.AqualityServices;
import aquality.selenium.browser.devtools.EmulationHandling;
import org.openqa.selenium.NoAlertPresentException;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import tests.BaseTest;
import theinternet.TheInternetPage;
import theinternet.forms.JavaScriptAlertsForm;
import java.util.Collections;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;
public class EmulationTests extends BaseTest {
private static EmulationHandling emulation() {
return AqualityServices.getBrowser().devTools().emulation();
}
@Override
@BeforeMethod
protected void beforeMethod() {
}
@Test
public void browserCanEmulateTest() {
Assert.assertTrue(emulation().canEmulate(), "Emulation should be supported in browser");
}
@Test
public void setScriptExecutionDisabledAndEnableAgainTest() {
AqualityServices.getBrowser().goTo(TheInternetPage.JAVASCRIPT_ALERTS.getAddress());
JavaScriptAlertsForm alertsForm = new JavaScriptAlertsForm();
alertsForm.getBtnJsAlert().click();
AqualityServices.getBrowser().handleAlert(AlertActions.ACCEPT);
emulation().setScriptExecutionDisabled();
alertsForm.getBtnJsAlert().click();
Assert.assertThrows(NoAlertPresentException.class, () -> AqualityServices.getBrowser().handleAlert(AlertActions.ACCEPT));
emulation().setScriptExecutionDisabled(false);
alertsForm.getBtnJsAlert().click();
AqualityServices.getBrowser().handleAlert(AlertActions.ACCEPT);
}
@Test
public void setTouchEmulationEnabledAndDisabledTest() {
BooleanSupplier isTouchEnabled = () -> getScriptResultOrDefault("isTouchEnabled.js", false);
if (isTouchEnabled.getAsBoolean()) {
throw new IllegalStateException("Touch should be initially disabled");
}
emulation().setTouchEmulationEnabled();
Assert.assertTrue(isTouchEnabled.getAsBoolean(), "Touch should be enabled");
emulation().setTouchEmulationEnabled(false);
Assert.assertFalse(isTouchEnabled.getAsBoolean(), "Touch should be disabled");
}
@Test
public void setEmulatedMediaTest() {
final String emulatedMedia = "projection";
final String width = "600";
Supplier<String> getMediaType = () -> getScriptResultOrDefault("getMediaType.js", "");
String initialValue = getMediaType.get();
if (initialValue.contains(emulatedMedia)) {
throw new IllegalStateException("Initial media type should differ from value to be set");
}
emulation().setEmulatedMedia(emulatedMedia, Collections.singletonMap("width", width));
Assert.assertEquals(getMediaType.get(), emulatedMedia, "Media type should equal to emulated");
emulation().disableEmulatedMediaOverride();
Assert.assertEquals(getMediaType.get(), initialValue, "Media type should equal to initial after disabling the override");
emulation().setEmulatedMedia(Collections.singletonMap("media", emulatedMedia));
Assert.assertEquals(getMediaType.get(), emulatedMedia, "Media type should equal to emulated");
}
@Test
public void settingDefaultBackgroundColorOverrideDoesNotThrowTest() {
emulation().setDefaultBackgroundColorOverride(0, 255, 38);
emulation().clearDefaultBackgroundColorOverride();
}
}