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時,在運行腳本時勋桶,異常信息發(fā)生改變脱衙,如下

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)
...

這里給的提示是,創(chuàng)建session失敗眠饮,因為desired capabilities的屬性platformName需要但沒有提供奥帘。此處,基本可以說明仪召,初步的問題已經基本得到解決寨蹋,但也可能只是表面上,提示不同而已扔茅,并沒有真正解決已旧,我們暫且把它視為已解決。但同時也出現后面提示的錯誤召娜,那我們再次嘗試加上capabilities的platformName屬性运褪,代碼如下

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

然后再次嘗試運行Junit Test,依然出現創(chuàng)建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(這里描述這個方法的執(zhí)行流程 – 可選)    
       
     * 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(這里描述這個方法的執(zhí)行流程 – 可選)    
       
     * 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");
    }
    
}

通過前后對比路徑的代碼弧可,發(fā)現可正常運行的腳本,并不需要初始化設置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) {
對應執(zhí)行的指令是ps 'uiautomator', Android7不支持這個指令格式,所以執(zhí)行結果是bad pid 'uiautomator'
目前Appium未對此進行處理,所以需要修改此指令的執(zhí)行方式
即將 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路徑”

仔細檢查了好幾遍發(fā)現,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閱讀 217,084評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件鬓催,死亡現場離奇詭異,居然都是意外死亡报慕,警方通過查閱死者的電腦和手機深浮,發(fā)現死者居然都...
    沈念sama閱讀 92,623評論 3 392
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來眠冈,“玉大人飞苇,你說我怎么就攤上這事菌瘫。” “怎么了布卡?”我有些...
    開封第一講書人閱讀 163,450評論 0 353
  • 文/不壞的土叔 我叫張陵雨让,是天一觀的道長。 經常有香客問我忿等,道長栖忠,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,322評論 1 293
  • 正文 為了忘掉前任贸街,我火速辦了婚禮庵寞,結果婚禮上,老公的妹妹穿的比我還像新娘薛匪。我一直安慰自己捐川,他們只是感情好,可當我...
    茶點故事閱讀 67,370評論 6 390
  • 文/花漫 我一把揭開白布逸尖。 她就那樣靜靜地躺著古沥,像睡著了一般。 火紅的嫁衣襯著肌膚如雪娇跟。 梳的紋絲不亂的頭發(fā)上岩齿,一...
    開封第一講書人閱讀 51,274評論 1 300
  • 那天,我揣著相機與錄音苞俘,去河邊找鬼盹沈。 笑死,一個胖子當著我的面吹牛吃谣,可吹牛的內容都是我干的襟诸。 我是一名探鬼主播,決...
    沈念sama閱讀 40,126評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼基协,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了菇用?” 一聲冷哼從身側響起澜驮,我...
    開封第一講書人閱讀 38,980評論 0 275
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎惋鸥,沒想到半個月后杂穷,有當地人在樹林里發(fā)現了一具尸體,經...
    沈念sama閱讀 45,414評論 1 313
  • 正文 獨居荒郊野嶺守林人離奇死亡卦绣,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,599評論 3 334
  • 正文 我和宋清朗相戀三年耐量,在試婚紗的時候發(fā)現自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片滤港。...
    茶點故事閱讀 39,773評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡廊蜒,死狀恐怖趴拧,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情山叮,我是刑警寧澤著榴,帶...
    沈念sama閱讀 35,470評論 5 344
  • 正文 年R本政府宣布,位于F島的核電站屁倔,受9級特大地震影響脑又,放射性物質發(fā)生泄漏。R本人自食惡果不足惜锐借,卻給世界環(huán)境...
    茶點故事閱讀 41,080評論 3 327
  • 文/蒙蒙 一问麸、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧钞翔,春花似錦严卖、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,713評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至驮捍,卻和暖如春疟呐,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背东且。 一陣腳步聲響...
    開封第一講書人閱讀 32,852評論 1 269
  • 我被黑心中介騙來泰國打工启具, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人珊泳。 一個月前我還...
    沈念sama閱讀 47,865評論 2 370
  • 正文 我出身青樓鲁冯,卻偏偏與公主長得像,于是被迫代替她去往敵國和親色查。 傳聞我的和親對象是個殘疾皇子薯演,可洞房花燭夜當晚...
    茶點故事閱讀 44,689評論 2 354

推薦閱讀更多精彩內容

  • Spring Cloud為開發(fā)人員提供了快速構建分布式系統中一些常見模式的工具(例如配置管理,服務發(fā)現秧了,斷路器跨扮,智...
    卡卡羅2017閱讀 134,654評論 18 139
  • 文檔轉載:http://www.cnblogs.com/ydnice/p/5787800.html Appium環(huán)...
    濤b閱讀 887評論 0 1
  • 女杰頌(獻給三八節(jié)巾幗精英) 文/金風 巾幗精英百世芳,豪情嫵媚一身藏验毡。 胸懷似水柔心弱衡创,壯志凌云毅力強。 聞鼓出...
    老頑童的詩詞人生閱讀 248評論 0 0
  • 上一篇寫的是衡道眾超人氣的“病殘弱小”四人組,感興趣戳這里【一生一念狮辽,一念一人——《仙劍奇?zhèn)b傳6》(四)】 在這個...
    茗君閱讀 2,637評論 9 4
  • 我曾經是電視迷一也,現在禁止孩子看電視巢寡,我也不看電視,省下了不少時間塘秦。手機也較少讓孩子看讼渊,相對而言,可可今年看動畫片的...
    小丫屠閱讀 282評論 0 0