|
22 | 22 |
|
23 | 23 | import eu.tsystems.mms.tic.testframework.AbstractWebDriverTest; |
24 | 24 | import eu.tsystems.mms.tic.testframework.constants.Browsers; |
| 25 | +import eu.tsystems.mms.tic.testframework.pageobjects.UiElement; |
25 | 26 | import eu.tsystems.mms.tic.testframework.pageobjects.UiElementFinder; |
26 | 27 | import eu.tsystems.mms.tic.testframework.testing.ChromeDevToolsProvider; |
27 | 28 | import eu.tsystems.mms.tic.testframework.utils.TimerUtils; |
|
37 | 38 | import org.openqa.selenium.devtools.HasDevTools; |
38 | 39 | import org.openqa.selenium.devtools.events.ConsoleEvent; |
39 | 40 | import org.openqa.selenium.devtools.v130.emulation.Emulation; |
| 41 | +import org.openqa.selenium.devtools.v130.fetch.Fetch; |
40 | 42 | import org.openqa.selenium.devtools.v130.log.Log; |
41 | 43 | import org.openqa.selenium.devtools.v130.log.model.LogEntry; |
42 | 44 | import org.openqa.selenium.devtools.v130.network.Network; |
| 45 | +import org.openqa.selenium.devtools.v130.network.model.Request; |
43 | 46 | import org.openqa.selenium.devtools.v130.network.model.RequestWillBeSent; |
44 | 47 | import org.openqa.selenium.devtools.v130.network.model.ResponseReceived; |
45 | 48 | import org.openqa.selenium.logging.HasLogEvents; |
@@ -348,4 +351,52 @@ public void testT14_MobileDeviceEmulation() { |
348 | 351 |
|
349 | 352 | } |
350 | 353 |
|
| 354 | + /** |
| 355 | + * This test calls the page https://weatherstack.com/ which uses your local IP address to show your local weather. |
| 356 | + * With the help of the Request fetcher you can modify the request to change to IP address. |
| 357 | + * |
| 358 | + * See details at https://chromedevtools.github.io/devtools-protocol/tot/Fetch/ |
| 359 | + */ |
| 360 | + @Test |
| 361 | + public void testT15_Network_changeRequest() { |
| 362 | + WebDriver webDriver = WEB_DRIVER_MANAGER.getWebDriver(); |
| 363 | + DevTools rawDevTools = CHROME_DEV_TOOLS.getRawDevTools(webDriver); |
| 364 | + final String location1 = "213.136.89.121"; // free German proxy server in Munich |
| 365 | + |
| 366 | + rawDevTools.send(Fetch.enable(Optional.empty(), Optional.empty())); |
| 367 | + rawDevTools.addListener(Fetch.requestPaused(), requestConsumer -> { |
| 368 | + Request request = requestConsumer.getRequest(); |
| 369 | + String currentUrl = request.getUrl(); |
| 370 | + if (currentUrl.contains("ws_api.php?ip=")) { |
| 371 | + String updatedUrl = currentUrl.substring(0, currentUrl.indexOf("?")) + "?ip=" + location1; |
| 372 | + rawDevTools.send( |
| 373 | + Fetch.continueRequest( |
| 374 | + requestConsumer.getRequestId(), |
| 375 | + Optional.of(updatedUrl), |
| 376 | + Optional.empty(), |
| 377 | + Optional.empty(), |
| 378 | + Optional.empty(), |
| 379 | + Optional.empty())); |
| 380 | + } else { |
| 381 | + rawDevTools.send( |
| 382 | + Fetch.continueRequest( |
| 383 | + requestConsumer.getRequestId(), |
| 384 | + Optional.of(currentUrl), |
| 385 | + Optional.empty(), |
| 386 | + Optional.empty(), |
| 387 | + Optional.empty(), |
| 388 | + Optional.empty())); |
| 389 | + |
| 390 | + } |
| 391 | + |
| 392 | + }); |
| 393 | + |
| 394 | + webDriver.get("https://weatherstack.com/"); |
| 395 | + |
| 396 | + UiElementFinder uiElementFinder = UI_ELEMENT_FINDER_FACTORY.create(webDriver); |
| 397 | + uiElementFinder.find(By.xpath("//div[@id = 'cookiescript_accept']")).click(); |
| 398 | + UiElement weatherLocation = uiElementFinder.find(By.xpath("//span[@data-api = 'location']")); |
| 399 | + weatherLocation.assertThat().text().isContaining("Munich"); |
| 400 | + } |
| 401 | + |
351 | 402 | } |
0 commit comments