【问题标题】:Wny can't I control Chrome Selenium Web Driver under Internet disconnect [WebDriver Exception]我无法在 Internet 断开连接下控制 Chrome Selenium Web 驱动程序 [WebDriver 异常]
【发布时间】:2019-03-28 08:54:06
【问题描述】:

我正在使用 Chrome 网络驱动程序。 自动化测试没问题。

但是,我还必须测试异常情况。 只有 Internet 断开连接的情况是问题。

[前置条件]

  1. 运行我的自动化应用程序。
  2. 在正常运行期间关闭 wifi 连接。
  3. 我在 chrome 浏览器上看到了 "ERR_INTERNET_DISCONNECTED" 消息。
  4. 1 分钟后发生"OpenQA.Selenium.WebDriverException" 据我所知,对远程 Web 驱动程序的 HTTP 请求超时 60 秒后
  5. 我使用 try~catch 捕获了异常,但是,在那之后,我不能 控制 chrome 网络驱动程序。我的意思是,我将发送命令 s _driver.Quit()_driver.Close(),_driver.URL()..等等。不执行任何 API 调用。

    do {
        try {
          _driver.FindElement(By.XPath(composeXPath)).Click();
          _driver.Navigate().Back();
        } catch (System.Net.WebException e) {
          System.Diagnostics.Debug.WriteLine("[Web Actor]WebException expired");
    
        } catch (OpenQA.Selenium.WebDriverException e) {
          System.Diagnostics.Debug.WriteLine("[Web Actor]WebDriverException");
          _driver.Quit();
        }
      } while (exit_flag == false);
    }
    

这是webdriver中的基本概念还是正常操作?
您可以轻松地制作这种异常情况。
如果你遇到同样的经历,请帮助我。
在打开 Wifi 并从 chrome 浏览器重新加载 url 之前,我无法访问 到 chrome WEB 驱动程序。
我要走了。

【问题讨论】:

    标签: c# selenium selenium-webdriver


    【解决方案1】:
     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))));
    }
    

    【讨论】:

      猜你喜欢
      • 2018-05-04
      • 1970-01-01
      • 1970-01-01
      • 2016-08-11
      • 2021-09-16
      • 2014-03-23
      • 2016-06-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多