[英]Kill network connection in the middle of the test using Selenium Java
我试图在测试过程中杀死我的网络。 当我杀死网络时,系统应该会提示一个对话框,说网络已经消失。 当我手动执行此操作时,我得到了对话框。 我使用了以下代码,
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)))); }
当我运行这段代码时,它不会给我那个对话框。 但是,当我刷新页面时,它告诉我没有网络。
我做错了什么?
手动步骤 -
我可以使用 bash 命令关闭互联网,
Runtime.getRuntime().exec("cmd /c ipconfig /release");
并使用它重新打开,
Runtime.getRuntime().exec("cmd /c ipconfig /renew");
这将自动关闭您的 wifi 并再次打开。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.