【问题标题】:Error : impossible to create a new session because 'createSession' which takes HttpClient, InputStream and long was not found错误:无法创建新会话,因为找不到需要 HttpClient、InputStream 和 long 的“createSession”
【发布时间】:2018-11-20 09:13:14
【问题描述】:

我正在尝试自动化一个 android 混合应用,但出现以下错误:

1) 线程“main”org.openqa.selenium.WebDriverException 中的异常:无法创建新会话,因为未找到需要 HttpClient、InputStream 和 long 的“createSession”或无法访问

2) 原因:java.lang.reflect.InvocationTargetException

3) 原因:org.openqa.selenium.WebDriverException: 未找到此类上下文。

4) NoSuchContextError: 没有找到这样的上下文。

以下是我要执行的代码

package Demo;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
public class NewTest {

private static AndroidDriver<MobileElement> driver;
public static void main(String[] args) throws MalformedURLException, InterruptedException {

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "android");
capabilities.setCapability("deviceName", "ZY223ZMPG6");
capabilities.setCapability("platformVersion", "7.0");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("autoGrantPermissions","true");
capabilities.setCapability("appPackage", "com.equationswork.enis");
capabilities.setCapability("appActivity", "com.equationswork.enis.MainActivity");
capabilities.setCapability("--session-override","true");
capabilities.setCapability("autoWebview","true");
capabilities.setCapability("chromedriverExecutable","C:\\Users\\Anjani \\AppData\\Roaming\\npm\\node_modules\\appium\\node_modules\\appium-chromedriver\\chromedriver\\win\\chromedriver.exe");
AppiumDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new  URL("http://0.0.0.0:4723/wd/hub"), capabilities);
        //driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
        Thread.sleep(5000);
        //System.out.println(driver.getPageSource());
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
 System.out.println(contextNames); //prints out something like   NATIVE_APP \n WEBVIEW_1
        }
driver.context((String) contextNames.toArray()[1]);
driver.context("WEBVIEW_1");
driver.findElement(By.id("btnGuest")).click();
//driver.quit(); 
   }
}

Following are the errors thrown:
Exception in thread "main" 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: 'DESKTOP-LAHP4RL', ip: '10.0.0.65', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_171'
Driver info: driver.version: AndroidDriver
    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.android.AndroidDriver.execute(AndroidDriver.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.android.AndroidDriver.<init>(AndroidDriver.java:88)
    at Demo.NewTest.main(NewTest.java:31)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:172)
    ... 13 more
Caused by: org.openqa.selenium.WebDriverException: No such context found.
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'DESKTOP-LAHP4RL', ip: '10.0.0.65', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_171'
Driver info: driver.version: AndroidDriver
remote stacktrace: NoSuchContextError: No such context found.
    at AndroidDriver.callee$0$0$ (C:\Users\Anjani\AppData\Roaming\npm\node_modules\appium\node_modules\appium-android-driver\lib\commands\context.js:49:11)
    at tryCatch (C:\Users\Anjani\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\Anjani\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (C:\Users\Anjani\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (C:\Users\Anjani\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
    at <anonymous>
    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.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
    at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
    at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
    at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
    at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
    at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
    at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
    ... 18 more

Following is the selenium server log

[Appium] Welcome to Appium v1.8.0
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
[HTTP] --> POST /wd/hub/session
[HTTP] {"desiredCapabilities":{"appActivity":"com.equationswork.enis.MainActivity","appPackage":"com.equationswork.enis","chromedriverExecutable":"C:\\Users\\Anjani\\AppData\\Roaming\\npm\\node_modules\\appium\\node_modules\\appium-chromedriver\\chromedriver\\win\\chromedriver.exe","platformVersion":"7.0","autoGrantPermissions":"true","browserName":"android","--session-override":"true","autoWebview":"true","platformName":"Android","deviceName":"ZY223ZMPG6"},"capabilities":{"desiredCapabilities":{"appActivity":"com.equationswork.enis.MainActivity","appPackage":"com.equationswork.enis","chromedriverExecutable":"C:\\Users\\Anjani\\AppData\\Roaming\\npm\\node_modules\\appium\\node_modules\\appium-chromedriver\\chromedriver\\win\\chromedriver.exe","platformVersion":"7.0","autoGrantPermissions":"true","browserName":"android","--session-override":"true","autoWebview":"true","platformName":"Android","deviceName":"ZY223ZMPG6"},"firstMatch":[{"--session-override":"true","appium:appActivity":"com.equati
[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{"appActivity":"com.equationswork.enis.MainActivity","appPackage":"com.equationswork.enis","chromedriverExecutable":"C:\\Users\\Anjani\\AppData\\Roaming\\npm\\node_modules\\appium\\node_modules\\appium-chromedriver\\chromedriver\\win\\chromedriver.exe","platformVersion":"7.0","autoGrantPermissions":"true","browserName":"android","--session-override":"true","autoWebview":"true","platformName":"Android","deviceName":"ZY223ZMPG6"},null,{"desiredCapabilities":{"appActivity":"com.equationswork.enis.MainActivity","appPackage":"com.equationswork.enis","chromedriverExecutable":"C:\\Users\\Anjani\\AppData\\Roaming\\npm\\node_modules\\appium\\node_modules\\appium-chromedriver\\chromedriver\\win\\chromedriver.exe","platformVersion":"7.0","autoGrantPermissions":"true","browserName":"android","--session-override":"true","autoWebview":"true","platformName":"Android","deviceName":"ZY223ZMPG6"},"firstMatch":[{"--session-override":"true","appium:appActivity":"com.equationswork.enis.MainActivity","appium:appPackage":"com.e...
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1528700143344 (12:25:43 GMT+0530 (India Standard Time))
[BaseDriver] The capabilities ["--session-override"] are not standard capabilities and should have an extension prefix
[BaseDriver] Boolean capability passed in as string. Functionality may be compromised.
[Appium] Consider setting 'automationName' capability to 'uiautomator2' on Android >= 6, since UIAutomator framework is not maintained anymore by the OS vendor.
[Appium] Creating new AndroidDriver (v2.4.1) session
[Appium] Capabilities:
[Appium]   --session-override: true
[Appium]   browserName: android
[Appium]   platformName: android
[Appium]   appActivity: com.equationswork.enis.MainActivity
[Appium]   appPackage: com.equationswork.enis
[Appium]   autoGrantPermissions: true
[Appium]   autoWebview: true
[Appium]   chromedriverExecutable: C:\Users\Anjani\AppData\Roaming\npm\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe
[Appium]   deviceName: ZY223ZMPG6
[Appium]   platformVersion: 7.0
[debug] [BaseDriver] W3C capabilities {"alwaysMatch":{"appium:--s... and MJSONWP desired capabilities [object Object] were provided
[debug] [BaseDriver] Creating session with W3C capabilities: {"alwaysMatch":{"appium:--s...
[BaseDriver] Boolean capability passed in as string. Functionality may be compromised.
[BaseDriver] Boolean capability passed in as string. Functionality may be compromised.
[BaseDriver] Capability 'autoWebview' changed from string to boolean. This may cause unexpected behavior
[BaseDriver] Capability 'autoGrantPermissions' changed from string to boolean. This may cause unexpected behavior
[BaseDriver] The following capabilities were provided, but are not recognized by appium: --session-override.
[BaseDriver] Session created with session id: e5ce581e-243f-4a72-bc16-f2d84070f32b
[debug] [AndroidDriver] Getting Java version
[AndroidDriver] Java version is: 1.8.0_171
[ADB] Checking whether adb is present
[ADB] Found 1 'build-tools' folders under 'C:\Users\Anjani\AppData\Local\Android\sdk' (newest first):
[ADB]     C:/Users/Anjani/AppData/Local/Android/sdk/build-tools/23.0.3
[ADB] Using adb.exe from C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe
[AndroidDriver] Retrieving device list
[debug] [ADB] Trying to find a connected android device
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[AndroidDriver] Looking for a device with Android '7.0'
[debug] [ADB] Setting device id to ZY223ZMPG6
[ADB] Getting device platform version
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell getprop ro.build.version.release'
[debug] [ADB] Current device property 'ro.build.version.release': 7.0
[AndroidDriver] Using device: ZY223ZMPG6
[ADB] Checking whether adb is present
[ADB] Using adb.exe from C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe
[debug] [ADB] Setting device id to ZY223ZMPG6
[AndroidDriver] App file was not listed, instead we're going to run com.equationswork.enis directly on the device
[debug] [AndroidDriver] Checking whether package is present on the device
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell pm list packages com.equationswork.enis'
[AndroidDriver] Starting Android session
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 wait-for-device'
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell echo ping'
[debug] [AndroidDriver] Pushing settings apk to device...
[debug] [ADB] Getting install status for io.appium.settings
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell pm list packages io.appium.settings'
[debug] [ADB] App is installed
[debug] [ADB] Getting package info for 'io.appium.settings'
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell dumpsys package io.appium.settings'
[ADB] Checking whether aapt is present
[ADB] Using aapt.exe from C:\Users\Anjani\AppData\Local\Android\sdk\build-tools\23.0.3\aapt.exe
[debug] [ADB] The installed 'io.appium.settings' package does not require upgrade ('2.3.0' >= '2.3.0')
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell ps'
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell getprop ro.build.version.sdk'
[debug] [ADB] Current device property 'ro.build.version.sdk': 24
[debug] [ADB] Device API level: 24
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell am start -W -n io.appium.settings/.Settings -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000'[debug] [ADB] Device API level: 24
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell appops set io.appium.settings android\:mock_location allow'
[AndroidDriver] setDeviceLanguageCountry requires language or country.
[AndroidDriver] Got language: 'null' and country: 'null'
[debug] [Logcat] Starting logcat capture
[debug] [AndroidDriver] Pushing unlock helper app to device...
[debug] [ADB] Getting install status for io.appium.unlock
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell pm list packages io.appium.unlock'
[debug] [ADB] App is installed
[debug] [ADB] Getting package info for 'io.appium.unlock'
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell dumpsys package io.appium.unlock'
[ADB] Checking whether aapt is present
[ADB] Using aapt.exe from C:\Users\Anjani\AppData\Local\Android\sdk\build-tools\23.0.3\aapt.exe
[debug] [ADB] The installed 'io.appium.unlock' package does not require upgrade ('2.0.0' >= '2.0.0')
[ADB] Getting device platform version
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell getprop ro.build.version.release'
[debug] [ADB] Current device property 'ro.build.version.release': 7.0
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell wm size'
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell getprop ro.product.model'
[debug] [ADB] Current device property 'ro.product.model': Moto G (5) Plus
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell getprop ro.product.manufacturer'
[debug] [ADB] Current device property 'ro.product.manufacturer': motorola
[AndroidDriver] No app sent in, not parsing package/activity
[debug] [AndroidDriver] No app capability. Assuming it is already on the device
[debug] [ADB] Getting install status for com.equationswork.enis
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell pm list packages com.equationswork.enis'
[debug] [ADB] App is installed
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell am force-stop com.equationswork.enis'
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell pm clear com.equationswork.enis'
[debug] [ADB] Device API level: 24
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell dumpsys package com.equationswork.enis'
[debug] [AndroidDriver] Performed fast reset on the installed 'com.equationswork.enis' application (stop and clear)
[debug] [AndroidBootstrap] Watching for bootstrap disconnect
[debug] [ADB] Forwarding system: 4724 to device: 4724
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 forward tcp\:4724 tcp\:4724'
[debug] [UiAutomator] Starting UiAutomator
[debug] [UiAutomator] Moving to state 'starting'
[debug] [UiAutomator] Parsing uiautomator jar
[debug] [UiAutomator] Found jar name: 'AppiumBootstrap.jar'
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 push C\:\\Users\\Anjani\\AppData\\Roaming\\npm\\node_modules\\appium\\node_modules\\appium-android-bootstrap\\bootstrap\\bin\\AppiumBootstrap.jar /data/local/tmp/'
[debug] [ADB] Attempting to kill all uiautomator processes
[debug] [ADB] Getting all processes with uiautomator
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell ps'
[ADB] No uiautomator process found to kill, continuing...
[debug] [UiAutomator] Starting UIAutomator
[debug] [ADB] Creating ADB subprocess with args: ["-P",5037,"-s","ZY223ZMPG6","shell","uiautomator","runtest","AppiumBootstrap.jar","-c","io.appium.android.bootstrap.Bootstrap","-e","pkg","com.equationswork.enis","-e","disableAndroidWatchers",false,"-e","acceptSslCerts",false]
[debug] [UiAutomator] Moving to state 'online'
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Loading json...
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Registered crash watchers.
[AndroidBootstrap] Android bootstrap socket is now connected
[debug] [ADB] Getting connected devices...
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Client connected
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell dumpsys window'
[AndroidDriver] Screen already unlocked, doing nothing
[debug] [ADB] Device API level: 24
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell am start -W -n com.equationswork.enis/com.equationswork.enis.MainActivity -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000'
[AndroidDriver] Setting auto webview to context 'WEBVIEW_com.equationswork.enis' with timeout 2000ms
[debug] [AndroidDriver] Getting a list of available webviews
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell cat /proc/net/unix'
[debug] [AndroidDriver] Found webviews: ["WEBVIEW_chrome"]
[debug] [AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_chrome"]
[debug] [AndroidDriver] Getting a list of available webviews
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell cat /proc/net/unix'
[debug] [AndroidDriver] Found webviews: ["WEBVIEW_chrome"]
[debug] [AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_chrome"]
[debug] [AndroidDriver] Getting a list of available webviews
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell cat /proc/net/unix'
[debug] [AndroidDriver] Found webviews: ["WEBVIEW_chrome"]
[debug] [AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_chrome"]
[debug] [AndroidDriver] Getting a list of available webviews
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell cat /proc/net/unix'
[debug] [AndroidDriver] Found webviews: ["WEBVIEW_chrome"]
[debug] [AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_chrome"]
[debug] [AndroidDriver] Shutting down Android driver
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell am force-stop com.equationswork.enis'
[debug] [ADB] Pressing the HOME button
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell input keyevent 3'
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"shutdown"}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [UiAutomator] Shutting down UiAutomator
[debug] [UiAutomator] Moving to state 'stopping'
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"shutdown"}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type SHUTDOWN
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":"OK, shutting down"}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Closed client connection
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: numtests=1
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: stream=.
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: current=1
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS_CODE: 0
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: stream=
[debug] [AndroidBootstrap] [UIAUTO STDOUT] Test results for WatcherResultPrinter=.
[debug] [AndroidBootstrap] [UIAUTO STDOUT] Time: 5.426
[debug] [AndroidBootstrap] [UIAUTO STDOUT] OK (1 test)
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS_CODE: -1
[debug] [UiAutomator] UiAutomator shut down normally
[debug] [UiAutomator] Moving to state 'stopped'
[debug] [ADB] Attempting to kill all uiautomator processes
[debug] [ADB] Getting all processes with uiautomator
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell ps'
[ADB] No uiautomator process found to kill, continuing...
[debug] [UiAutomator] Moving to state 'stopped'
[debug] [Logcat] Stopping logcat capture
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Anjani\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s ZY223ZMPG6 shell am force-stop io.appium.unlock'
[debug] [AndroidDriver] Not cleaning generated files. Add `clearSystemFiles` capability if wanted.
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1528700164410 (12:26:04 GMT+0530 (India Standard Time))
[HTTP] <-- POST /wd/hub/session 400 21093 ms - 1026
[HTTP]

【问题讨论】:

  • 我正在处理类似的问题stackoverflow.com/q/50715334/8016330 乍一看,这可能是 appium java 客户端的问题。您能否尝试更新到最新版本,如果有帮助,请告诉我
  • 我正在使用 Gradle,io.appium',名称:'java-client',版本:'6.0.0' org.seleniumhq.selenium',名称:'selenium-java',版本: '3.12.0' org.testng',名称:'testng',版本:'6.14.3' com.google.code.gson',名称:'gson',版本:'2.8.5'
  • @AnjaniKumar,你有解决方案吗?
  • 我也想知道你是否解决了这个问题,因为我的框架中报告了同样的错误。请回复。
  • 我已经发布了这个答案stackoverflow.com/a/54346053/6262727

标签: android automation appium hybrid-mobile-app


【解决方案1】:

转到开发者选项并启用以下选项--

  1. USB 调试 - USB 连接时的调试模式

  2. 通过 USB 安装 - 允许通过 USB 安装应用程序

  3. USB 调试(安全设置)- 允许通过 USB 调试授予权限和模拟输入

这对我有用。

【讨论】:

    【解决方案2】:

    运行命令:appium-doctor

    分析是否存在 Java_Home 和 Android_Home 问题

    转到 bash 配置文件并再次保存

    do : gradle build 如果设备检测或设备有任何问题 内存,看日志在这种情况下需要一个新的模拟器

    运行你的项目

    这对我有用

    【讨论】:

      【解决方案3】:

      我希望你启动 appium 服务器,可能使用相同的 URL 和端口用于初始化驱动程序对象。 还有一件事,请使用 string.contains("WEBVIEW") 为每个循环多使用一个来切换上下文

      【讨论】:

        【解决方案4】:

        Appium 日志告诉问题与功能和 我假设在您的路径中,在“\Anjani”之后有一个空格,位于所需的功能中。 这可能是原因。

        ("chromedriverExecutable","C:\\Users\\Anjani \\AppData\\....")
        

        就我而言,我设置了"NO_Reset=false**e**" (with double "e" )

        希望对你有帮助。

        【讨论】:

          【解决方案5】:

          如果已经有一个 Appium 服务器在相同的 IP 和相同的端口上运行,则会显示此错误消息。确保在尝试启动 appium 服务器之前终止所有 appium 服务器,或者您可以通过编程方式为每个 appium 服务器指定新端口。

          【讨论】:

            【解决方案6】:

            确保您的设备已连接,否则会抛出您指定的错误。要验证您是否连接了设备,请在终端中运行以下命令:

            adb devices
            

            【讨论】:

              【解决方案7】:

              如果我们手动运行 Appium Desktop Server,可能会出现此问题。 尝试通过终端“$ appium”运行 Appium 服务器 在 Appium 服务器启动后运行您的脚本

              希望它会起作用......!

              【讨论】:

                【解决方案8】:

                就我而言,这是由于 DesiredCapabilities。确保正确分配了“appPackage”、“appActivity”或其他 Capabilities。

                【讨论】:

                  【解决方案9】:

                  只要我们在所需功能中遇到问题,就会出现此错误。查看所需的功能并确保所有数据都是正确的。对我来说,我是在 int 中传递 Android 版本,而它想要在 String 中。逐行查看整个错误日志,您将获得更多见解。还要确保 appium UI 未打开,因为两者都将使用相同的端口。

                  【讨论】:

                    【解决方案10】:

                    遇到同样的问题,然后我意识到我的环回 IP 地址不正确。然后我改变了ip,它对我有用。 来自 http://127.0.0.0:4723/wd/hub http://127.0.0.1:4723/wd/hub 正确的是http://127.0.0.1:4723/wd/hub

                    【讨论】:

                      【解决方案11】:

                      当您在 URL 方法中传递本地主机的 IP 时,它必须是 127.0.0.1,例如所有本地主机通用的 URL("http://127.0.0.1:4723/wd/hub")。

                      希望对你有帮助!!!!

                      乐于助人....

                      【讨论】:

                        【解决方案12】:

                        我在 Android 自动化项目中也遇到了这个问题。 找到解决方案。在测试有帮助之前删除“io.appium.uiautomator2.server”和“io.appium.uiautomator2.server.test”包。 这两个包将在创建会话期间自动重新安装。

                        【讨论】:

                          【解决方案13】:

                          有时会出现此问题,因为 USB 调试不接受通过 USB 安装的应用

                          为此,请在您的手机中进入开发者选项模式,并授予通过 USB 安装应用程序的所有权限。

                          【讨论】:

                            【解决方案14】:

                            我在这个论坛找到了解决方案> https://github.com/appium/appium/issues/11210

                            也许它也可以帮助你。

                            将 IP 从 0.0.0.0 更改为 127.0.0.1 对我有用。 此外,请尝试在每次执行之前重新启动服务器。我在我的测试设置中为此编写了一个小脚本,也许你可以尝试一下。

                            如果您将 AUTOMATION_NAME 的功能用作 ANDROID_UIAUTOMATOR2,则可能会遇到此问题。

                            desiredCap.setCapability(MobileCapabilityType.AUTOMATION_NAME,AutomationName.ANDROID_UIAUTOMATOR2);
                            

                            解决方案: 1.尝试删除/评论这一行 2. 或者,运行以下命令:

                            adb shell pm list packages -f > D://t.txt
                            adb uninstall io.appium.uiautomator2.server
                            adb uninstall io.appium.uiautomator2.server.test
                            

                            这些包会在会话开始时再次自动安装。

                            【讨论】:

                              猜你喜欢
                              • 2019-04-22
                              • 2019-03-08
                              • 2020-05-15
                              • 2019-06-08
                              • 2020-01-23
                              • 1970-01-01
                              • 2012-02-28
                              • 1970-01-01
                              • 1970-01-01
                              相关资源
                              最近更新 更多