-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathNetworkSpeedEmulationTest.java
More file actions
59 lines (51 loc) · 3.02 KB
/
NetworkSpeedEmulationTest.java
File metadata and controls
59 lines (51 loc) · 3.02 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
package tests.usecases.devtools;
import aquality.selenium.browser.AqualityServices;
import aquality.selenium.browser.devtools.NetworkHandling;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.devtools.v145.network.model.ConnectionType;
import org.openqa.selenium.devtools.v145.network.model.NetworkConditions;
import org.testng.Assert;
import org.testng.annotations.Test;
import tests.BaseTest;
import theinternet.forms.WelcomeForm;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
public class NetworkSpeedEmulationTest extends BaseTest {
private static final int DOWNLOAD_THROUGHPUT = 53;
private static final int DOWNLOAD_THROUGHPUT_BIG = 530000;
private static final int UPLOAD_THROUGHPUT = 27;
private static final int UPLOAD_THROUGHPUT_BIG = 270000;
private static final int LATENCY = 27;
private final WelcomeForm welcomeForm = new WelcomeForm();
private NetworkHandling network() {
return getBrowser().devTools().network();
}
private List<NetworkConditions> getNetworkConditions(int downloadThroughput, int uploadThroughput, ConnectionType connectionType) {
return Collections.singletonList(new NetworkConditions(welcomeForm.getUrl(), LATENCY, downloadThroughput, uploadThroughput,
Optional.of(connectionType), Optional.empty(), Optional.empty(), Optional.empty()));
}
private List<NetworkConditions> getNetworkConditions(int downloadThroughput, int uploadThroughput) {
return Collections.singletonList(new NetworkConditions(welcomeForm.getUrl(), LATENCY, downloadThroughput, uploadThroughput,
Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
}
@Test
public void networkSpeedEmulationTest() {
getBrowser().setPageLoadTimeout(AqualityServices.getConfiguration().getTimeoutConfiguration().getScript());
getBrowser().goTo(welcomeForm.getUrl());
Assert.assertTrue(welcomeForm.state().waitForDisplayed(), "Form must be opened");
boolean isOffline = true;
network().emulateConditionsByRule(isOffline, getNetworkConditions(-1, -1));
network().overrideState(isOffline, LATENCY, -1, -1);
getBrowser().refresh();
getBrowser().waitForPageToLoad();
Assert.assertFalse(welcomeForm.state().isDisplayed(), "Form must not be opened when offline");
isOffline = false;
network().emulateConditionsByRule(isOffline, getNetworkConditions(DOWNLOAD_THROUGHPUT, UPLOAD_THROUGHPUT, ConnectionType.BLUETOOTH));
network().overrideState(isOffline, LATENCY, DOWNLOAD_THROUGHPUT, UPLOAD_THROUGHPUT, ConnectionType.BLUETOOTH);
Assert.assertThrows(TimeoutException.class, () -> getBrowser().refresh());
network().emulateConditionsByRule(isOffline, getNetworkConditions(DOWNLOAD_THROUGHPUT_BIG, UPLOAD_THROUGHPUT_BIG, ConnectionType.CELLULAR4G));
getBrowser().refresh();
Assert.assertTrue(welcomeForm.state().waitForDisplayed(), "Form must be opened when online with good speed");
}
}