Appium脚本初启动问题分析——2018-03-21

调试appium程序问题过程中,出现如下异常

java.lang.NoSuchMethodError: org.openqa.selenium.remote.HttpCommandExecutor.<init>(Ljava/util/Map;Ljava/net/URL;Lorg/openqa/selenium/remote/http/HttpClient$Factory;)V
    at io.appium.java_client.remote.AppiumCommandExecutor.<init>(AppiumCommandExecutor.java:56)
    at io.appium.java_client.remote.AppiumCommandExecutor.<init>(AppiumCommandExecutor.java:67)
    at io.appium.java_client.remote.AppiumCommandExecutor.<init>(AppiumCommandExecutor.java:73)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:93)
    at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:79)
    at ContactsTest.setUp(ContactsTest.java:90)
    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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

java.lang.NullPointerException
    at ContactsTest.tearDown(ContactsTest.java:122)
    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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

根据提示的异常信息提到junit、java-client、selenium-java、selenium-sever,以及网上搜索到的资料,可能是最原始的类库,也即junit、java-client、selenium-java、selenium-sever这几个jar文件导致的,那么我们现在要排除的就是对这几个文件的版本进行尝试更换,看看是否有异常信息改变或者改善,果然在进行更换selenium-java-2.44.0版本到selenium-java-2.6.0时,在运行脚本时,异常信息发生改变,如下

java.lang.NoSuchMethodError: com.google.common.base.Throwables.throwIfUnchecked(Ljava/lang/Throwable;)V
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:143)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:141)
    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 ContactsTest.setUp(ContactsTest.java:89)
    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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

java.lang.NullPointerException
    at ContactsTest.tearDown(ContactsTest.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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

并且,此时,控制台有异常提示

三月 21, 2018 5:19:43 下午 org.openqa.selenium.remote.ProtocolHandshake createSession
信息: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end

同时,在appium server端提示:如下

> info: Client User-Agent string: Apache-HttpClient/4.5.2 (Java/1.8.0_74)
> error: The following desired capabilities are required, but were not provided: platformName
> info: [debug] Got configuration error, not starting session
> info: [debug] Cleaning up appium session
> error: Failed to start an Appium session, err was: Error: The following desired capabilities are required, but were not provided: platformName
> info: [debug] Error: The following desired capabilities are required, but were not provided: platformName
>     at [object Object].Capabilities.checkValidity (D:\Program Files (x86)\Appium\node_modules\appium\lib\server\capabilities.js:146:13)
>     at [object Object].Appium.configure (D:\Program Files (x86)\Appium\node_modules\appium\lib\appium.js:238:35)
>     at [object Object].<anonymous> (D:\Program Files (x86)\Appium\node_modules\appium\lib\appium.js:118:10)
>     at [object Object].Appium.start (D:\Program Files (x86)\Appium\node_modules\appium\lib\appium.js:129:5)
...

这里给的提示是,创建session失败,因为desired capabilities的属性platformName需要但没有提供。此处,基本可以说明,初步的问题已经基本得到解决,但也可能只是表面上,提示不同而已,并没有真正解决,我们暂且把它视为已解决。但同时也出现后面提示的错误,那我们再次尝试加上capabilities的platformName属性,代码如下

capabilities.setCapability("platformName", "Android");

然后再次尝试运行Junit Test,依然出现创建session失败问题,但此时appium server提示信息已经改变,如下

> info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Bad app: E:\\eclipseWorkspace\\TestDemo\\apps\\RandomContant.apk. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: Error locating the app: ENOENT, stat 'E:\\eclipseWorkspace\\TestDemo\\apps\\RandomContant.apk')","origValue":"Bad app: E:\\eclipseWorkspace\\TestDemo\\apps\\RandomContant.apk. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: Error locating the app: ENOENT, stat 'E:\\eclipseWorkspace\\TestDemo\\apps\\RandomContant.apk'"},"sessionId":null}
...

意思是说,app的路径错误,然后我对其他能正常运行的脚本进行对比,如:

可正常运行的脚本为

public class CalculatorTest {

    public static void main(String[] args) throws MalformedURLException, InterruptedException {

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("deviceName", "8SHQ31206614HB2078X");
        capabilities.setCapability("automationName", "Appium");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("platformVersion", "7.0");
        capabilities.setCapability("appPackage", "com.android.calculator2");
        capabilities.setCapability("appActivity", ".Calculator");

        AppiumDriver driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

        driver.findElement(By.name("1")).click();
        driver.findElement(By.name("5")).click();
        driver.findElement(By.name("9")).click();
        driver.findElement(By.name("delete")).click();
        driver.findElement(By.name("+")).click();
        driver.findElement(By.name("6")).click();
        driver.findElement(By.name("=")).click();
        Thread.sleep(2000);

        String result = driver.findElement(By.id("com.android.calculator2:id/formula")).getText();
        System.out.println(result);

        driver.quit();
    }

}

异常运行脚本为

public class ContactsTest
{
    
    /**    
       
     * setUp(这里用一句话描述这个方法的作用)    
       
     * TODO(这里描述这个方法适用条件 – 可选)    
       
     * TODO(这里描述这个方法的执行流程 – 可选)    
       
     * TODO(这里描述这个方法的使用方法 – 可选)    
       
     * TODO(这里描述这个方法的注意事项 – 可选)    
       
     * @param   name    
       
     * @param  @return    设定文件    
       
     * @return String    DOM对象    
       
     * @Exception 异常对象    
       
     * @since  CodingExample Ver(编码范例查看) 1.1    
       
    */
    
    private AppiumDriver driver;
    
    @Before
    public void setUp()
        throws Exception
    {
        // set up appium
        
        File classpathRoot = new File(System.getProperty("user.dir"));
        
        File appDir = new File(classpathRoot, "/apps");
        
        File app = new File(appDir, "RandomContant.apk");
        
        DesiredCapabilities capabilities = new DesiredCapabilities();
        
        capabilities.setCapability("deviceName", "0123456789ABCDEF");
        
        capabilities.setCapability("platformName", "Android");
        
        capabilities.setCapability("platformVersion", "7.0");
        
        capabilities.setCapability("app", app.getAbsolutePath());
        
        // capabilities.setCapability("app", "E:\\eclipseWorkspace\\TestDemo\\apps\\RandomContant.apk");
        
        capabilities.setCapability("appPackage", "bbk.cly.RandomContacts");
        
        capabilities.setCapability("appActivity", ".RandomContacts");
        
        driver = new AppiumDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        
        System.out.println("App is launched!");
    }
    
    /**    
       
     * tearDown(这里用一句话描述这个方法的作用)    
       
     * TODO(这里描述这个方法适用条件 – 可选)    
       
     * TODO(这里描述这个方法的执行流程 – 可选)    
       
     * TODO(这里描述这个方法的使用方法 – 可选)    
       
     * TODO(这里描述这个方法的注意事项 – 可选)    
       
     * @param   name    
       
     * @param  @return    设定文件    
       
     * @return String    DOM对象    
       
     * @Exception 异常对象    
       
     * @since  CodingExample Ver(编码范例查看) 1.1    
       
    */
    @After
    public void tearDown()
        throws Exception
    {
        driver.quit();
    }
    
    @Test
    public void test()
    {
        WebElement el = driver.findElement(By.name("生成"));
        el.click();
        
        System.out.println("App is done!");
        // fail("Not yet implemented");
    }
    
}

通过前后对比路径的代码,发现可正常运行的脚本,并不需要初始化设置app路径,也即没有

        File classpathRoot = new File(System.getProperty("user.dir"));
        
        File appDir = new File(classpathRoot, "/apps");
        
        File app = new File(appDir, "RandomContant.apk");

        capabilities.setCapability("app", app.getAbsolutePath());

这部分的代码,那么去掉这部分的代码,进行尝试,果然脚本已经开始可以运行,但,最后还是失败了,提示如下
注:为何不需要设置app路径?

> info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Could not find a connected Android device.)","origValue":"Could not find a connected Android device."},"sessionId":null}

这里意思是无法连接上设备,我们知道,appium连接设备,是通过adb来连接的,那我们尝试在命令提示符cmd里输入adb devices连接

C:\Users\xxxxxxxx>adb devices
List of devices attached
0123456789ABCDEF        device

然后再次运行脚本,又提示以下错误,似乎有电脑,一波N折,appium server提示如下:

> info: [debug] Attempting to kill all 'uiautomator' processes
> info: [debug] Getting all processes with 'uiautomator'
> info: [debug] executing cmd: D:\AutoTest\SmartSDK\SmartSDK\platform-tools\adb.exe -s 0123456789ABCDEF shell "ps 'uiautomator'"
> info: [debug] Stopping logcat capture
> info: [debug] Logcat terminated with code null, signal SIGTERM
> info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
> warn: UiAutomator did not shut down fast enough, calling it gone
> info: [debug] Cleaning up android objects
> error: Failed to start an Appium session, err was: Error: Could not extract PIDs from ps output. PIDS: [], Procs: ["bad pid 'uiautomator'"]
> info: [debug] Cleaning up appium session
> info: [debug] Error: Could not extract PIDs from ps output. PIDS: [], Procs: ["bad pid 'uiautomator'"]
>     at D:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:1059:17
>     at [object Object].<anonymous> (D:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:180:9)
>     at ChildProcess.exithandler (child_process.js:742:7)
>     at ChildProcess.emit (events.js:110:17)
>     at maybeClose (child_process.js:1016:16)
>     at Process.ChildProcess._handle.onexit (child_process.js:1088:5)
> info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Could not extract PIDs from ps output. PIDS: [], Procs: [\"bad pid 'uiautomator'\"])","origValue":"Could not extract PIDs from ps output. PIDS: [], Procs: [\"bad pid 'uiautomator'\"]"},"sessionId":null}
> info: <-- POST /wd/hub/session 500 16381.255 ms - 288 

此处提示uiautomator进程出现问题,而uiautomator这个东西存在于SDK里面,这个SDK是公司为了某个自动化工具定制的,这让我们怀疑,这SDK是否出现了问题?当然这只是一个疑问。
而这里的关键信息是bad pid 'uiautomator',经过一番搜索后,得到:
Appium 1.4.13在Android 7上有bug,报错:
Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]
原解决方案见:https://discuss.appium.io/t/support-version-android-n/10206/5
总结自己的解决方案:
原因:
1. adb.js 中1035 行this.shell("ps '" + name + "'", function (err, stdout) {
对应执行的指令是ps 'uiautomator', Android7不支持这个指令格式,所以执行结果是bad pid 'uiautomator'
目前Appium未对此进行处理,所以需要修改此指令的执行方式
即将 Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js 文件修改

this.shell("ps '" + name + "'", function (err, stdout) {
    ...
    var procs = [];
    var outlines = stdout.split("\n");
    outlines.shift() //添加这行
    ...

于是再进行调试,好吧,还是有问题,出现了如下错误

> info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity)","origValue":"Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity"},"sessionId":null}

网上很多说法是:“要打开的activity不存在,activity路径错误,改为完整正确的activity路径”

仔细检查了好几遍发现,activity是存在的,activity路径也是正确的(当然这么低端的问题一般人也不会犯)

经过一番查找,问题解决如下:

注释掉setup中的如下两行:

capabilities.setCapability("appPackage", "xxx.xxx.xxx.activity");
capabilities.setCapability("appActivity", ".MainActivity");

但,如果前面没有添加app路径的话,会报No app set的错误,需要设置app路径,如我是:

        File classpathRoot = new File(System.getProperty("user.dir"));
        
        File appDir = new File(classpathRoot, "/apps");
        
        File app = new File(appDir, "xxx.apk");
        ...
        capabilities.setCapability("app", app.getAbsolutePath());

再次运行,问题解决了。

然而,在自己电脑上Android 7.0上运行脚本的时候,又出现了如下问题

> info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Command failed: C:\\Windows\\system32\\cmd.exe /s /c \"\"D:\\Program Files (x86)\\Android\\android-sdk\\platform-tools\\adb.exe\" -s emulator-5556 install \"D:\\Program Files (x86)\\Appium\\node_modules\\appium\\build\\settings_apk\\settings_apk-debug.apk\"\"\nadb: failed to install D:\\Program Files (x86)\\Appium\\node_modules\\appium\\build\\settings_apk\\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]\r\n)","killed":false,"code":1,"signal":null,"cmd":"C:\\Windows\\system32\\cmd.exe /s /c \"\"D:\\Program Files (x86)\\Android\\android-sdk\\platform-tools\\adb.exe\" -s emulator-5556 install \"D:\\Program Files (x86)\\Appium\\node_modules\\appium\\build\\settings_apk\\settings_apk-debug.apk\"\"","origValue":"Command failed: C:\\Windows\\system32\\cmd.exe /s /c \"\"D:\\Program Files (x86)\\Android\\android-sdk\\platform-tools\\adb.exe\" -s emulator-5556 install \"D:\\Program Files (x86)\\Appium\\node_modules\\appium\\build\\settings_apk\\settings_apk-debug.apk\"\"\nadb: failed to install D:\\Program Files (x86)\\Appium\\node_modules\\appium\\build\\settings_apk\\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]\r\n"},"sessionId":null}

原因是,Appium 1.14不完全兼容Android 7.0,之前在公司的电脑上可以正常运行Android 7.0的机器,但用自己电脑运行另一台Android 7.0的机器,就出现如上所示的异常。
解决方法是,把测试机换成Android 6.0的机器,另外一种解决办法是,升级Appium 1.14到1.72版本,但这个解决方法尚未实验。
说明:运行测试的时候我们不需要指定package和activity 这些信息,Appium会从apk中提取这些信息。

见:https://github.com/appium/appium/issues/2981paymand 的解释:

Don't know about the apk info tool above, but you can always get that info using the aapt tool from Android SDK with the following command:
`adt/sdk/build-tools/android-4.4/aapt dump badging app.apk` Note: You shouldn't need to specify appPackage, appActivity, etc. since Appium should be able to extract those from the apk using the method above anyway.

其他Appium的问题和技巧, 大家可以参考Appium的一些坑问题错误解决 与 技巧集锦

到此,初步运行的问题已经基本解决,文章有点长,本人才浅,欢迎指出不当指出。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,530评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 86,403评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,120评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,770评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,758评论 5 367
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,649评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,021评论 3 398
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,675评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,931评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,659评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,751评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,410评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,004评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,969评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,203评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,042评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,493评论 2 343

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,594评论 18 139
  • 文档转载:http://www.cnblogs.com/ydnice/p/5787800.html Appium环...
    涛b阅读 882评论 0 1
  • 女杰颂(献给三八节巾帼精英) 文/金风 巾帼精英百世芳,豪情妩媚一身藏。 胸怀似水柔心弱,壮志凌云毅力强。 闻鼓出...
    老顽童的诗词人生阅读 243评论 0 0
  • 上一篇写的是衡道众超人气的“病残弱小”四人组,感兴趣戳这里【一生一念,一念一人——《仙剑奇侠传6》(四)】 在这个...
    茗君阅读 2,604评论 9 4
  • 我曾经是电视迷,现在禁止孩子看电视,我也不看电视,省下了不少时间。手机也较少让孩子看,相对而言,可可今年看动画片的...
    小丫屠阅读 276评论 0 0