Reputation: 362
I'm running a JUnit test of my Wicket project with the help of selenium and chrome driver.
Our website supports HTML5 offline mode using manifest and all, which we also want to test.
We use ChromeDriver like:
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);
But unfourtnetly, there is an error when trying this in the middle of my test:
((NetworkConnection) chromeDriver).setNetworkConnection(ConnectionType.NONE);
The error is:
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)
Regarding this: https://bugs.chromium.org/p/chromedriver/issues/detail?id=984 this feature should be possible, but somehow it's not?
Could someone give me a hint?
Upvotes: 1
Views: 5572
Reputation: 1087
This seems to be intended for mobile emulation. I tested this and was able to reproduce your error, and then fix it by enabling mobile emulation, i.e.:
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);
I thought you might just need to set the network type to airplane mode, not none, but that didn't work (without also enabling mobile emulation).
Upvotes: 1