Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法从本机切换到WEBVIEW_chrome显示异常:io.appium.java_client.NoSuchContextException_Java_Selenium_Google Chrome_Adb_Appium Android - Fatal编程技术网

无法从本机切换到WEBVIEW_chrome显示异常:io.appium.java_client.NoSuchContextException

无法从本机切换到WEBVIEW_chrome显示异常:io.appium.java_client.NoSuchContextException,java,selenium,google-chrome,adb,appium-android,Java,Selenium,Google Chrome,Adb,Appium Android,我正在真实设备上测试web应用程序,并使用Chrome浏览器,我尝试设置集合,同时获得本机应用程序和WEBVIEW\u Chrome,但当我尝试使用driver.context()方法切换到WEBVIEW\u Chrome时,它引发异常“io.appium.java_client.NoSuchContextException:io.appium.java_client.NoSuchContextException:处理命令时发生未知的服务器端错误。原始错误:处理命令时发生未知的服务器端错误。原始

我正在真实设备上测试web应用程序,并使用Chrome浏览器,我尝试设置集合,同时获得本机应用程序和WEBVIEW\u Chrome,但当我尝试使用driver.context()方法切换到WEBVIEW\u Chrome时,它引发异常“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();
私有静态AndroidDriver=null;
@试验前
public void initConfig()引发畸形的DurException、InterruptedException{
DesiredCapabilities=新的DesiredCapabilities();
能力。设置能力(“deviceName”、“Galaxy C9 Pro”);
能力。设置能力(“平台版”、“8.0.0”);
能力。设置能力(“平台名”、“安卓”);
setCapability(“appPackage”、“com.android.chrome”);
setCapability(“appActivity”、“com.google.android.apps.chrome.Main”);
能力。设置能力(“startIWDP”,真);
能力。设置能力(“adbExecTimeout”,20000);
能力。设置能力(MobileCapabilityType.NO_RESET,true);
驱动程序=新的AndroidDriver(新的URL(“http://127.0.0.1:4723/wd/hub(能力),;
driver.manage().timeouts().implicitlyWait(80,TimeUnit.SECONDS);
}
@试验
public void chromeTest()引发中断异常{
System.out.println(“Hello Android”);
System.out.println(“启动移动测试……”);
//driver.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);
系统输出打印项次(“开始”);
System.out.println(“等待3000后------------------------------------------”;
Set context=driver.getContextHandles();
System.out.println(context.size());
for(字符串上下文:上下文){System.out.println(上下文);}
WebElement searchbar_txt=driver.findElementById(“com.android.chrome:id/search_box_text”);
搜索栏_txt.click();
WebElement url\u Bar=driver.findElementById(“com.android.chrome:id/url\u Bar”);
url_Bar.sendKeys(“amazon.in”);
WebElement urlhistory=driver.findelementbypath(“/*[@text='amazon.in']);
//findElementByName(“Kotak证券”);
urlhistory.click();
睡眠(4000);
Set context1=driver.getContextHandles();
System.out.println(context1.size());
for(字符串上下文:context1){System.out.println(上下文);}
//driver.context((字符串)context1.toArray()[1]);
驱动程序上下文(“WEBVIEW_chrome”);
睡眠(4000);
driver.findElementById(“导航搜索关键字”).sendKeys(“行李”);
driver.findElementByTagName(“提交”)。单击();
Eclipse控制台输出:

Nov 02, 2019 12:19:03 PM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
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
===============================================

2019年11月2日12:19:03 PM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
信息:检测到的方言:W3C
你好,安卓
开始移动测试。。。。。。
开始
等待3000后----------------------------------------------
1.
本地应用程序
2.
本地应用程序
网络视图浏览器
失败:chromeTest
io.appium.java_client.NoSuchContextException:处理命令时发生未知服务器端错误。原始错误:处理命令时发生未知服务器端错误。原始错误:未知错误:无法将端口转发到设备18e6bebc:。未知错误:adb命令失败。额外响应:。
构建信息:版本:“3.141.59”,修订版:“e82be7d358”,时间:“2018-11-14T08:25:48”
系统信息:主机:'TVDLT020',ip:'192.168.1.12',os.name:'Windows 10',os.arch:'amd64',os.version:'10.0',java.version:'1.8.0_201'
驱动程序信息:io.appium.java_client.android.AndroidDriver
功能{adbExecTimeout:20000,appActivity:com.google.android.apps.chr…,appPackage:com.android.chrome,databaseEnabled:false,所需:{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,DeviceScreedency:420,deviceScreenSize:1080x1920,DeviceAudid:18e6bebc,javascriptEnabled:true,locationContextEnabled:false,networkConnectionEnabled:true,noReset:true,像素比率:2.625,平台:LINUX,平台名称:Android,平台版本n:8.0.0,startIWDP:true,statBarHeight:63,takesScreenshot:true,viewportRect:{height:1857,left:0,top:63,width:1080},警告:{},WebStorage Enabled:false}
会话ID:3e90e00b-2eba-40b9-9b85-fc66fde1b491
位于io.appium.java_client.AppiumDriver.context(AppiumDriver.java:229)
在appiumandroidap.appiumAndroid_GoogleWeb.chromeTest(appiumAndroid_GoogleWeb.java:93)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中
位于java.lang.reflect.Method.invoke(Method.java:498)
位于org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
位于org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
位于org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
位于org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
位于org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)