无法从本机切换到 WEBVIEW_chrome,显示异常:io.appium.java_client.NoSuchContextException
Unable to switch from native to WEBVIEW_chrome showing exception : io.appium.java_client.NoSuchContextException
我正在真实设备上测试网络应用程序并使用 Chrome 浏览器,我尝试设置集合,我得到了 NATIVE_APP 和 WEBVIEW_chrome 但是当我尝试切换到WEBVIEW_chrome 使用 driver.context() 方法抛出异常io.appium.java_client.NoSuchContextException:io.appium.java_client.NoSuchContextException: 处理命令时发生未知服务器端错误。原始错误: 未知服务器-处理命令时出现端错误。原始错误:未知错误:无法将端口转发到设备 18e6bebc:。未知错误:adb 命令失败。额外响应:<>。
请帮助我,自上两周以来我一直在苦苦挣扎。提前致谢。
我已尝试 amazon.in 的功能和测试脚本如下:
private static AndroidDriver<WebElement> driver = null;
@BeforeTest
public void initConfig() throws MalformedURLException, InterruptedException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Galaxy C9 Pro");
capabilities.setCapability("platformVersion", "8.0.0");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.android.chrome");
capabilities.setCapability("appActivity", "com.google.android.apps.chrome.Main");
capabilities.setCapability("startIWDP", true);
capabilities.setCapability("adbExecTimeout", 20000);
capabilities.setCapability(MobileCapabilityType.NO_RESET, true);
driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
}
@Test
public void chromeTest() throws InterruptedException {
System.out.println("Hello Android");
System.out.println("Started Mobile Testing......");
//driver.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);
System.out.println("start");
System.out.println("after wait 3000----------------------------------------------");
Set<String> context = driver.getContextHandles();
System.out.println(context.size());
for(String contexts : context) { System.out.println(contexts); }
WebElement searchbar_txt = driver.findElementById("com.android.chrome:id/search_box_text");
searchbar_txt.click();
WebElement url_Bar = driver.findElementById("com.android.chrome:id/url_bar");
url_Bar.sendKeys("amazon.in");
WebElement urlhistory = driver.findElementByXPath("//*[@text='amazon.in']");
// findElementByName("Kotak Securities");
urlhistory.click();
Thread.sleep(4000);
Set<String> context1 = driver.getContextHandles();
System.out.println(context1.size());
for(String contexts : context1) { System.out.println(contexts); }
// driver.context((String) context1.toArray()[1]);
driver.context("WEBVIEW_chrome");
Thread.sleep(4000);
driver.findElementById("nav-search-keywords").sendKeys("Bags");
driver.findElementByTagName("Submit").click();
Eclipse 控制台输出:
Nov 02, 2019 12:19:03 PM io.appium.java_client.remote.AppiumCommandExecutor lambda[=13=]
INFO: Detected dialect: W3C
Hello Android
Started Mobile Testing......
start
after wait 3000----------------------------------------------
1
NATIVE_APP
2
NATIVE_APP
WEBVIEW_chrome
FAILED: chromeTest
io.appium.java_client.NoSuchContextException: An unknown server-side error occurred while processing the command. Original error: An unknown server-side error occurred while processing the command. Original error: unknown error: Failed to forward ports to device 18e6bebc: . unknown error: The adb command failed. Extra response: <>.
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'TVDLT020', ip: '192.168.1.12', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {adbExecTimeout: 20000, appActivity: com.google.android.apps.chr..., appPackage: com.android.chrome, databaseEnabled: false, desired: {adbExecTimeout: 20000, appActivity: com.google.android.apps.chr..., appPackage: com.android.chrome, deviceName: Galaxy C9 Pro, noReset: true, platformName: android, platformVersion: 8.0.0, startIWDP: true}, deviceApiLevel: 26, deviceManufacturer: samsung, deviceModel: SM-C900F, deviceName: 18e6bebc, deviceScreenDensity: 420, deviceScreenSize: 1080x1920, deviceUDID: 18e6bebc, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, noReset: true, pixelRatio: 2.625, platform: LINUX, platformName: Android, platformVersion: 8.0.0, startIWDP: true, statBarHeight: 63, takesScreenshot: true, viewportRect: {height: 1857, left: 0, top: 63, width: 1080}, warnings: {}, webStorageEnabled: false}
Session ID: 3e90e00b-2eba-40b9-9b85-fc66fde1b491
at io.appium.java_client.AppiumDriver.context(AppiumDriver.java:229)
at appiumAndroidApp.appiumAndroid_GoogleWeb.chromeTest(appiumAndroid_GoogleWeb.java:93)
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:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: An unknown server-side error occurred while processing the command. Original error: unknown error: Failed to forward ports to device 18e6bebc: . unknown error: The adb command failed. Extra response: <>.
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'TVDLT020', ip: '192.168.1.12', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {adbExecTimeout: 20000, appActivity: com.google.android.apps.chr..., appPackage: com.android.chrome, databaseEnabled: false, desired: {adbExecTimeout: 20000, appActivity: com.google.android.apps.chr..., appPackage: com.android.chrome, deviceName: Galaxy C9 Pro, noReset: true, platformName: android, platformVersion: 8.0.0, startIWDP: true}, deviceApiLevel: 26, deviceManufacturer: samsung, deviceModel: SM-C900F, deviceName: 18e6bebc, deviceScreenDensity: 420, deviceScreenSize: 1080x1920, deviceUDID: 18e6bebc, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, noReset: true, pixelRatio: 2.625, platform: LINUX, platformName: Android, platformVersion: 8.0.0, startIWDP: true, statBarHeight: 63, takesScreenshot: true, viewportRect: {height: 1857, left: 0, top: 63, width: 1080}, warnings: {}, webStorageEnabled: false}
Session ID: 3e90e00b-2eba-40b9-9b85-fc66fde1b491
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.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
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:41)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at io.appium.java_client.AppiumDriver.context(AppiumDriver.java:226)
... 26 more
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
我无法切换上下文并在 amazon.in 的搜索栏上发送键 请指导我在哪里出错或做错了什么。
Appium 日志请参考下面link:
所以我遇到了类似的问题。我得到了这个错误
No Chromedriver found that can automate Chrome '69.0.3497'
我不得不在
更换 chromedriver
C:\Users\Daya\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\
与 here
中的兼容版本
无需切换上下文,您可以 运行 它具有 chrome 功能和 chrome 驱动程序本身的路径。
包括行:
capabilities.setCapability("appium:chromeOptions", ImmutableMap.of("w3c", false));
忽略 w3c 服务,因为 appium 或 chromedriver 似乎不再支持它。
我正在真实设备上测试网络应用程序并使用 Chrome 浏览器,我尝试设置集合,我得到了 NATIVE_APP 和 WEBVIEW_chrome 但是当我尝试切换到WEBVIEW_chrome 使用 driver.context() 方法抛出异常io.appium.java_client.NoSuchContextException:io.appium.java_client.NoSuchContextException: 处理命令时发生未知服务器端错误。原始错误: 未知服务器-处理命令时出现端错误。原始错误:未知错误:无法将端口转发到设备 18e6bebc:。未知错误:adb 命令失败。额外响应:<>。 请帮助我,自上两周以来我一直在苦苦挣扎。提前致谢。
我已尝试 amazon.in 的功能和测试脚本如下:
private static AndroidDriver<WebElement> driver = null;
@BeforeTest
public void initConfig() throws MalformedURLException, InterruptedException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Galaxy C9 Pro");
capabilities.setCapability("platformVersion", "8.0.0");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.android.chrome");
capabilities.setCapability("appActivity", "com.google.android.apps.chrome.Main");
capabilities.setCapability("startIWDP", true);
capabilities.setCapability("adbExecTimeout", 20000);
capabilities.setCapability(MobileCapabilityType.NO_RESET, true);
driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
}
@Test
public void chromeTest() throws InterruptedException {
System.out.println("Hello Android");
System.out.println("Started Mobile Testing......");
//driver.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);
System.out.println("start");
System.out.println("after wait 3000----------------------------------------------");
Set<String> context = driver.getContextHandles();
System.out.println(context.size());
for(String contexts : context) { System.out.println(contexts); }
WebElement searchbar_txt = driver.findElementById("com.android.chrome:id/search_box_text");
searchbar_txt.click();
WebElement url_Bar = driver.findElementById("com.android.chrome:id/url_bar");
url_Bar.sendKeys("amazon.in");
WebElement urlhistory = driver.findElementByXPath("//*[@text='amazon.in']");
// findElementByName("Kotak Securities");
urlhistory.click();
Thread.sleep(4000);
Set<String> context1 = driver.getContextHandles();
System.out.println(context1.size());
for(String contexts : context1) { System.out.println(contexts); }
// driver.context((String) context1.toArray()[1]);
driver.context("WEBVIEW_chrome");
Thread.sleep(4000);
driver.findElementById("nav-search-keywords").sendKeys("Bags");
driver.findElementByTagName("Submit").click();
Eclipse 控制台输出:
Nov 02, 2019 12:19:03 PM io.appium.java_client.remote.AppiumCommandExecutor lambda[=13=]
INFO: Detected dialect: W3C
Hello Android
Started Mobile Testing......
start
after wait 3000----------------------------------------------
1
NATIVE_APP
2
NATIVE_APP
WEBVIEW_chrome
FAILED: chromeTest
io.appium.java_client.NoSuchContextException: An unknown server-side error occurred while processing the command. Original error: An unknown server-side error occurred while processing the command. Original error: unknown error: Failed to forward ports to device 18e6bebc: . unknown error: The adb command failed. Extra response: <>.
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'TVDLT020', ip: '192.168.1.12', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {adbExecTimeout: 20000, appActivity: com.google.android.apps.chr..., appPackage: com.android.chrome, databaseEnabled: false, desired: {adbExecTimeout: 20000, appActivity: com.google.android.apps.chr..., appPackage: com.android.chrome, deviceName: Galaxy C9 Pro, noReset: true, platformName: android, platformVersion: 8.0.0, startIWDP: true}, deviceApiLevel: 26, deviceManufacturer: samsung, deviceModel: SM-C900F, deviceName: 18e6bebc, deviceScreenDensity: 420, deviceScreenSize: 1080x1920, deviceUDID: 18e6bebc, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, noReset: true, pixelRatio: 2.625, platform: LINUX, platformName: Android, platformVersion: 8.0.0, startIWDP: true, statBarHeight: 63, takesScreenshot: true, viewportRect: {height: 1857, left: 0, top: 63, width: 1080}, warnings: {}, webStorageEnabled: false}
Session ID: 3e90e00b-2eba-40b9-9b85-fc66fde1b491
at io.appium.java_client.AppiumDriver.context(AppiumDriver.java:229)
at appiumAndroidApp.appiumAndroid_GoogleWeb.chromeTest(appiumAndroid_GoogleWeb.java:93)
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:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: An unknown server-side error occurred while processing the command. Original error: unknown error: Failed to forward ports to device 18e6bebc: . unknown error: The adb command failed. Extra response: <>.
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'TVDLT020', ip: '192.168.1.12', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {adbExecTimeout: 20000, appActivity: com.google.android.apps.chr..., appPackage: com.android.chrome, databaseEnabled: false, desired: {adbExecTimeout: 20000, appActivity: com.google.android.apps.chr..., appPackage: com.android.chrome, deviceName: Galaxy C9 Pro, noReset: true, platformName: android, platformVersion: 8.0.0, startIWDP: true}, deviceApiLevel: 26, deviceManufacturer: samsung, deviceModel: SM-C900F, deviceName: 18e6bebc, deviceScreenDensity: 420, deviceScreenSize: 1080x1920, deviceUDID: 18e6bebc, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, noReset: true, pixelRatio: 2.625, platform: LINUX, platformName: Android, platformVersion: 8.0.0, startIWDP: true, statBarHeight: 63, takesScreenshot: true, viewportRect: {height: 1857, left: 0, top: 63, width: 1080}, warnings: {}, webStorageEnabled: false}
Session ID: 3e90e00b-2eba-40b9-9b85-fc66fde1b491
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.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
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:41)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at io.appium.java_client.AppiumDriver.context(AppiumDriver.java:226)
... 26 more
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
我无法切换上下文并在 amazon.in 的搜索栏上发送键 请指导我在哪里出错或做错了什么。
Appium 日志请参考下面link:
所以我遇到了类似的问题。我得到了这个错误
No Chromedriver found that can automate Chrome '69.0.3497'
我不得不在
更换 chromedriverC:\Users\Daya\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\
与 here
中的兼容版本无需切换上下文,您可以 运行 它具有 chrome 功能和 chrome 驱动程序本身的路径。
包括行:
capabilities.setCapability("appium:chromeOptions", ImmutableMap.of("w3c", false));
忽略 w3c 服务,因为 appium 或 chromedriver 似乎不再支持它。