Java Client 6.0.0: createSession exceptions throw odd WebDriverException
The problem
If createSession throws an exception (in my case we hit a 10 minute timeout), the end exception has incorrect message in the WebDriver Exception.
Real Message:
Caused by: org.openqa.selenium.WebDriverException: Error forwarding the new session Error forwarding the request unexpected end of stream on Connection{10.96.80.60:4848, proxy=DIRECT hostAddress=/10.96.80.60:4848 cipherSuite=none protocol=http/1.1}
Command duration or timeout: 600.10 seconds
WebDriverException Message:
Caused by: org.openqa.selenium.WebDriverException: It is impossible to create a new session because 'createSession' which takes HttpClient, InputStream and long was not found or it is not accessible
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'vr-qa05.dhcp.tripadvisor.com', ip: '10.96.81.45', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.4', java.version: '1.8.0_144'
Driver info: driver.version: IOSDriver
Full Stack:
Caused by: org.openqa.selenium.WebDriverException: It is impossible to create a new session because 'createSession' which takes HttpClient, InputStream and long was not found or it is not accessible
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'vr-qa05.dhcp.tripadvisor.com', ip: '10.96.81.45', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.4', java.version: '1.8.0_144'
Driver info: driver.version: IOSDriver
at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:182)
at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:196)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:218)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.ios.IOSDriver.execute(IOSDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:207)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130)
at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:84)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:94)
at io.appium.java_client.ios.IOSDriver.<init>(IOSDriver.java:90)
at com.tripadvisor.qa.mobile.common.appium.AppiumDriverFactory.lambda$createDriver$1(AppiumDriverFactory.java:169)
... 4 common frames omitted
Caused by: java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:172)
... 18 common frames omitted
Caused by: org.openqa.selenium.WebDriverException: Error forwarding the new session Error forwarding the request unexpected end of stream on Connection{10.96.80.60:4848, proxy=DIRECT hostAddress=/10.96.80.60:4848 cipherSuite=none protocol=http/1.1}
Command duration or timeout: 600.10 seconds
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
... 23 common frames omitted
Caused by: org.openqa.selenium.WebDriverException: Error forwarding the new session Error forwarding the request unexpected end of stream on Connection{10.96.80.60:4848, proxy=DIRECT hostAddress=/10.96.80.60:4848 cipherSuite=none protocol=http/1.1}
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'vr-qa05.dhcp.tripadvisor.com', ip: '10.96.81.45', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.4', java.version: '1.8.0_144'
Driver info: driver.version: unknown
at org.openqa.grid.web.servlet.handler.RequestHandler.process(RequestHandler.java:118)
at org.openqa.grid.web.servlet.DriverServlet.process(DriverServlet.java:86)
at org.openqa.grid.web.servlet.DriverServlet.doPost(DriverServlet.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.seleniumhq.jetty9.servlet.ServletHolder.handle(ServletHolder.java:860)
at org.seleniumhq.jetty9.servlet.ServletHandler.doHandle(ServletHandler.java:535)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
at org.seleniumhq.jetty9.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
at org.seleniumhq.jetty9.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168)
at org.seleniumhq.jetty9.servlet.ServletHandler.doScope(ServletHandler.java:473)
at org.seleniumhq.jetty9.server.session.SessionHandler.doScope(SessionHandler.java:1564)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166)
at org.seleniumhq.jetty9.server.handler.ContextHandler.doScope(ContextHandler.java:1155)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.seleniumhq.jetty9.server.Server.handle(Server.java:530)
at org.seleniumhq.jetty9.server.HttpChannel.handle(HttpChannel.java:347)
at org.seleniumhq.jetty9.server.HttpConnection.onFillable(HttpConnection.java:256)
at org.seleniumhq.jetty9.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
at org.seleniumhq.jetty9.io.FillInterest.fillable(FillInterest.java:102)
at org.seleniumhq.jetty9.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:247)
at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:140)
at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131)
at org.seleniumhq.jetty9.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:382)
at org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:708)
at org.seleniumhq.jetty9.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:626)
... 1 common frames omitted
Code that causes this: AppiumCommandExecutor Line 156-191
FileBackedOutputStream os = new FileBackedOutputStream(threshold);
try {
CountingOutputStream counter = new CountingOutputStream(os);
Writer writer = new OutputStreamWriter(counter, UTF_8);
NewAppiumSessionPayload payload = NewAppiumSessionPayload.create(desired);
payload.writeTo(writer);
try (InputStream rawIn = os.asByteSource().openBufferedStream();
BufferedInputStream contentStream = new BufferedInputStream(rawIn)) {
Method createSessionMethod = this.getClass().getSuperclass()
.getDeclaredMethod("createSession", HttpClient.class, InputStream.class, long.class);
createSessionMethod.setAccessible(true);
Optional<Result> result = (Optional<Result>) createSessionMethod
.invoke(this, client, contentStream, counter.getCount());
return result.map(result1 -> {
Result toReturn = result.get();
getLogger(ProtocolHandshake.class.getName())
.info(format("Detected dialect: %s", toReturn.getDialect()));
return toReturn;
}).orElseThrow(() -> new SessionNotCreatedException(
format("Unable to create new remote session. desired capabilities = %s", desired)));
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new WebDriverException(format("It is impossible to create a new session "
+ "because 'createSession' which takes %s, %s and %s was not found "
+ "or it is not accessible",
HttpClient.class.getSimpleName(),
InputStream.class.getSimpleName(),
long.class.getSimpleName()), e);
}
} finally {
os.reset();
}
Environment
- Appium version (or git revision) that exhibits the issue: 1.8.1
- Last Appium version that did not exhibit the issue (if applicable): (Unsure... I think this is java client related)
- Desktop OS/version used to run Appium: osx 10.13.4
- Node.js version (unless using Appium.app|exe): 8.11.1
- Mobile platform/version under test: iPhone 7 IOS 11.3.1
- Real device or emulator/simulator: Real Device
- Appium CLI or Appium.app|exe: Appium CLI
Link to Appium logs
No link here currently... as this appears to be just incorrect error reporting (appium log mainly has retries trying to start the app... unsure if this is a separate issue or not
Code To Reproduce Issue [ Good To Have ]
No code here, just possibly a phone that's not starting up the app correctly, so the createSession call to appium times out at 10 minutes
No idea but i go back to 6.0.0-BETA4, so no errors.
implementation group: 'io.appium', name: 'java-client', version: '6.0.0-BETA4'
+1 happens to me as well.
+2 Happening to me as well on java client 6.0.0.
+3 Facing Same issue.
The issue was solved for me after I installed ADB on my computer. https://stackoverflow.com/questions/31374085/installing-adb-on-mac-os-x
+4 We also have this problem.
I tried to switch from 6.0.0-BETA2 to 6.0.0 and observed the same exception
+5 Same issue
Can you all try 6.1.0 version please?
Tried 6.1.0 and it behaves the same. It's because AppiumCommandExecutor.createSession() treats InvocationTargetException the same as NoSuchMethodException and IllegalAccessException. You need a separate catch clause for it, something like this:
} catch (NoSuchMethodException | IllegalAccessException e) {
throw new WebDriverException(format("It is impossible to create a new session "
+ "because 'createSession' which takes %s, %s and %s was not found "
+ "or it is not accessible",
HttpClient.class.getSimpleName(),
InputStream.class.getSimpleName(),
long.class.getSimpleName()), e);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
String msg = format("Unable to create new remote session. desired capabilities = %s", desired);
String details = cause == null || cause.getMessage() == null ? "" : ", reason = " + cause.getMessage();
throw new SessionNotCreatedException(msg + details, cause);
}
+6 I am also experiencing the same issue.
@bennid I've been using 6.1.0 on Samsung Galaxy S7 Edge, Samsung, HTC, iPhone SE, iPhone X and alot more devices that we have here in our device lab. I don't experience the above issue. Can someone help me understand how are you folks trying to create the session? This helps me prioritize and close this.
My issue has been solved after deleted Appium Settings and Unlock app.
@SrinivasanTarget Tried using 6.1.0 and the issue exists. It works fine for me if I execute my script on single device. If I'm trying to do parallel execution on real iOS devices, facing the issue. I'm also getting wdaLocalPort must be of type number while doing parallel execution. The same script for parallel execution works fine on 5.0.4. Below is the log I'm getting.
org.openqa.selenium.WebDriverException: It is impossible to create a new session because 'createSession' which takes HttpClient, InputStream and long was not found or it is not accessible Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T15:15:08.936Z' System info: host: 'sasiswethas-iMac.local', ip: '169.254.147.191', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.5', java.version: '1.8.0_144' Driver info: driver.version: IOSDriver
at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:195)
at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:209)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:231)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.ios.IOSDriver.execute(IOSDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:207)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130)
at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:84)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:94)
at io.appium.java_client.ios.IOSDriver.<init>(IOSDriver.java:95)
at com.hybridFramework.testBase.TestBase.setUpApplication(TestBase.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:217)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:144)
at org.testng.TestRunner.beforeRun(TestRunner.java:634)
at org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
at org.testng.SuiteRunner.access$000(SuiteRunner.java:39)
at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:421)
at org.testng.internal.thread.ThreadUtil$2.call(ThreadUtil.java:64)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:185)
... 31 more
Caused by: org.openqa.selenium.InvalidArgumentException: 'wdaLocalPort' must be of type number
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T15:15:08.936Z'
System info: host: 'sasiswethas-iMac.local', ip: '169.254.147.191', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.5', java.version: '1.8.0_144'
Driver info: driver.version: IOSDriver
remote stacktrace: InvalidArgumentError: 'wdaLocalPort' must be of type number
at validateCaps (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/capabilities.js:52:11)
at parseCaps (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/capabilities.js:154:20)
at processCapabilities (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/capabilities.js:197:43)
at XCUITestDriver.callee$0$0$ (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/commands/session.js:36:14)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at enqueueResult (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:185:17)
at new Promise (
+7 I am also experiencing the same issue.
+8 same problem :(
Same here with 6.1.0 IOS with xcode 9.2 running on grid. If I run it outside the grid as an individual device test case, it is working fine.
Really only hitting this with Selenium Grid when there's a disconnect / issue with install / something wrong with the device under test.
There seems to be nothing wrong with the device. But never can't be sure. App is built properly, because there are instance when this issue is not even seen. The hub and node are running in the same machine. So no network issues should be there.
@junjunoori
I'm also getting wdaLocalPort must be of type number while doing parallel execution.
Please update to latest server and make sure you send wdaLocalPort as number not string.