Last active
November 3, 2020 12:23
-
-
Save ShamaUgale/444c377db2badbd0e331df724ad8b89e to your computer and use it in GitHub Desktop.
This is a devtools with selenium 4 example to simulate no networkOffline( connection.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.devtools; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
import org.openqa.selenium.devtools.DevTools; | |
import org.openqa.selenium.devtools.network.Network; | |
import org.openqa.selenium.devtools.network.model.ConnectionType; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.Optional; | |
public class SetNetwork { | |
final static String PROJECT_PATH = System.getProperty("user.dir"); | |
public static void main(String[] args){ | |
System.setProperty("webdriver.chrome.driver", PROJECT_PATH + "/src/main/resources/chromedriver"); | |
ChromeDriver driver; | |
driver = new ChromeDriver(); | |
DevTools devTools = driver.getDevTools(); | |
devTools.createSession(); | |
devTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty())); | |
devTools.send(Network.emulateNetworkConditions( | |
false, | |
20, | |
20, | |
50, | |
Optional.of(ConnectionType.CELLULAR2G) | |
)); | |
driver.get("https://www.google.com"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment