-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetworkInterceptorTest.java
30 lines (26 loc) · 1.06 KB
/
NetworkInterceptorTest.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
public class NetworkInterceptorTest {
private ChromeDriver chromeDriver = null;
private DevTools devTools = null;
@Before
public void setup() {
ChromeOptions chromeOptions = new ChromeOptions();
chromeDriver = new ChromeDriver(chromeOptions);
devTools = chromeDriver.getDevTools();
devTools.createSession();
}
@After
public void cleanup() { chromeDriver.quit(); }
@Test
public void networkInterceptorTest() throws IOException, InterruptedException {
File fi = new File(“/Users/Lana/Downloads/smiley.webp”);
Byte[] fileContent = Files.readAllBytes(fi.toPath());
NetworkInterceptor interceptor = new NetworkInterceptor(chromeDriver.
Route.matching(req -> req.getUri().contains(“img.ehowcdn.com”) && req.getMethod() == HttpMethod.GET).to(() -> req -> new HttpResponse()
.setStatus(200)
.setHeader(“content-type”, “image/webp”)
.setContent(Contents.bytes(fileContent))));
chromeDriver.get(“https://www.ehow.com”);
Thread.sleep(10000);
chromeDriver.quit();
}
}