調試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/2981 中paymand 的解釋:
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的一些坑問題錯誤解決 與 技巧集錦
到此得运,初步運行的問題已經基本解決膝蜈,文章有點長,本人才淺熔掺,歡迎指出不當指出饱搏。