【问题标题】:error "network connection must be enabled" while setting networkConnection with ChromeDriver使用 ChromeDriver 设置 networkConnection 时出现错误“必须启用网络连接”
【发布时间】:2017-04-26 07:20:24
【问题描述】:

我正在使用 selenium 和 chrome 驱动程序对我的 Wicket 项目进行 JUnit 测试。

我们的网站支持使用 manifest 和 all 的 HTML5 离线模式,我们也想测试一下。

我们像这样使用 ChromeDriver:

Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("binary", binarylocation);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
capabilities.setCapability(CapabilityType.SUPPORTS_NETWORK_CONNECTION, true);
driver = new ChromeDriver(capabilities);

但不幸的是,在我的测试过程中尝试此操作时出现错误:

((NetworkConnection) chromeDriver).setNetworkConnection(ConnectionType.NONE);

错误是:

org.openqa.selenium.WebDriverException: unknown error: network connection must be enabled
  (Session info: chrome=57.0.2987.98)
  (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 4 milliseconds
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'xxx', ip: 'xx.xx.xx.xx', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.29.461591 (62ebf098771772160f391d75e589dc567915b233), userDataDir=C:\Users\xxx\AppData\Local\Temp\scoped_dir164_11339}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=57.0.2987.98, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: c344d7f922bc0973d46959e17103672c
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:671)
    at org.openqa.selenium.remote.RemoteExecuteMethod.execute(RemoteExecuteMethod.java:35)
    at org.openqa.selenium.remote.mobile.RemoteNetworkConnection.setNetworkConnection(RemoteNetworkConnection.java:46)
    at org.openqa.selenium.chrome.ChromeDriver.setNetworkConnection(ChromeDriver.java:230)

关于这个:https://bugs.chromium.org/p/chromedriver/issues/detail?id=984这个功能应该是可能的,但不知何故它不是?

有人可以给我一个提示吗?

【问题讨论】:

    标签: selenium selenium-chromedriver


    【解决方案1】:

    这似乎是为移动仿真设计的。我对此进行了测试并能够重现您的错误,然后通过启用移动仿真来修复它,即:

    Map<String, String> mobileEmulation = new HashMap<String, String>();
    mobileEmulation.put("deviceName", "Laptop with touch");
    
    Map<String, Object> chromeOptions = new HashMap<String, Object>();
    chromeOptions.put("mobileEmulation", mobileEmulation);
    chromeOptions.put("binary", binarylocation);
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
    capabilities.setCapability(CapabilityType.SUPPORTS_NETWORK_CONNECTION, true);
    driver = new ChromeDriver(capabilities);
    

    我认为您可能只需将网络类型设置为飞行模式,而不是无,但这不起作用(还没有启用移动仿真)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-30
      • 2020-03-09
      • 1970-01-01
      • 2020-01-02
      相关资源
      最近更新 更多