[英]Kill network connection in the middle of the test using Selenium Java
I'm trying to kill my network in the middle of a test.我试图在测试过程中杀死我的网络。 and when I kill the network, the system should prompt a dialog saying network is gone.
当我杀死网络时,系统应该会提示一个对话框,说网络已经消失。 When I do this manually, I get the dialog.
当我手动执行此操作时,我得到了对话框。 And I used the following code,
我使用了以下代码,
public void exitBrowserTab() throws IOException { WebDriver driver = new ChromeDriver(); driver.get("url"); driver.findElement(By.id("login-username")).sendKeys("username"); driver.findElement(By.id("login-password")).sendKeys("password"); driver.findElement(By.id("signin-button")).click(); Map map = new HashMap(); map.put("offline", true); map.put("latency", 5); map.put("download_throughput", 500); map.put("upload_throughput", 1024); CommandExecutor executor = ((ChromeDriver)driver).getCommandExecutor(); Response response = executor.execute(new Command(((ChromeDriver)driver).getSessionId(), "setNetworkConditions", ImmutableMap.of("network_conditions", ImmutableMap.copyOf(map)))); }
When I run this code, it won't give me that dialog.当我运行这段代码时,它不会给我那个对话框。 but, when I refresh the page, it tells me that there's no network.
但是,当我刷新页面时,它告诉我没有网络。
What did I do wrong?我做错了什么?
Manual Steps -手动步骤 -
I could turn of internet using the bash command,我可以使用 bash 命令关闭互联网,
Runtime.getRuntime().exec("cmd /c ipconfig /release");
and turn it back on using,并使用它重新打开,
Runtime.getRuntime().exec("cmd /c ipconfig /renew");
This will automatically turn off your wifi and turn it on again.这将自动关闭您的 wifi 并再次打开。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.