如何从量角器自动化将浏览器设置为脱机?

Mur*_*uru 6 firefox google-chrome ui-automation protractor

我有一个场景,它必须在没有连接时进行测试.为了实现自动化,我认为使浏览器脱机并测试方案是可行的.有人请帮助我如何在量角器执行测试期间将浏览器设置为脱机?有没有办法从量角器访问浏览器首选项?

Pét*_*óth 1

因为我不知道你用什么语言编码,所以我假设它是 Java

这个函数关闭wifi:

protected void disConnectInternet() throws IOException {
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))));

}
Run Code Online (Sandbox Code Playgroud)