org.openqa.selenium.json.JsonException:无法确定类型来自:Y。最后 1 个字符读取:Y

org.openqa.selenium.json.JsonException: Unable to determine type from: Y. Last 1 characters read: Y

getDriver() 函数 returns iOS Driver 的一个实例。尝试使用以下命令重置应用程序时出现以下错误,

Driver.getDriver().resetApp();

我还尝试用 closeApp 和 launchApp 替换此命令,如下所示。但这也因同样的错误而失败。

Driver.getDriver().closeApp();
Driver.getDriver().launchApp();

该错误信息量不大,我也不确定如何修复此错误。有人可以帮我解决这个问题吗?

Unable to determine type from: Y. Last 1 characters read: Y
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'Kishores-MBP', ip: 'fe80:0:0:0:35:43cd:351c:edd3%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '1.8.0_231'
Driver info: driver.version: IOSDriver
org.openqa.selenium.json.JsonException: Unable to determine type from: Y. Last 1 characters read: Y
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'Kishores-MBP', ip: 'fe80:0:0:0:35:43cd:351c:edd3%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '1.8.0_231'
Driver info: driver.version: IOSDriver
    at org.openqa.selenium.json.JsonInput.peek(JsonInput.java:122)
    at org.openqa.selenium.json.JsonTypeCoercer.lambda$null(JsonTypeCoercer.java:140)
    at org.openqa.selenium.json.JsonTypeCoercer.coerce(JsonTypeCoercer.java:126)
    at org.openqa.selenium.json.Json.toType(Json.java:69)
    at org.openqa.selenium.json.Json.toType(Json.java:55)
    at org.openqa.selenium.json.Json.toType(Json.java:50)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:87)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:45)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.ios.IOSDriver.execute(IOSDriver.java:1)
    at io.appium.java_client.InteractsWithApps.resetApp(InteractsWithApps.java:93)
    at hid.seos.testCases.ui.ListEventsForEndpoint.initialise(ListEventsForEndpoint.java:27)
    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:134)
    at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:63)
    at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:348)
    at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:302)
    at org.testng.internal.TestInvoker.runConfigMethods(TestInvoker.java:695)
    at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:523)
    at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
    at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
    at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:816)
    at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
    at java.util.ArrayList.forEach(ArrayList.java:1257)
    at org.testng.TestRunner.privateRun(TestRunner.java:766)
    at org.testng.TestRunner.run(TestRunner.java:587)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
    at org.testng.SuiteRunner.access[=13=]0(SuiteRunner.java:28)
    at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:425)
    at org.testng.internal.thread.ThreadUtil.lambda$execute[=13=](ThreadUtil.java:68)
    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)

刚刚找出异常的根本原因。我花了很长时间,因为错误消息并没有太大帮助。

根本原因:我在 Appium 上使用 pcloudy,我只是错过了在 pcloudyDesiredCapabilities 中提到 platformVersion 的那一行。因此,如果其他人遇到同样的问题,请确保在初始化 Webdriver(AndroidDriver 或 IOSDriver)时没有遗漏 DesiredCapabilities 部分中的任何内容。