Appium appium-desktop 启动 app 后 无法继续操作

roc · 2018年02月26日 · 最后由 python_lipengpeng 回复于 2019年06月10日 · 2565 次阅读

在打开 app 后,没有执行操作,而是直接结束运行了,
log 中说没有启动 activity,但是怎么修改呢?

脚本代码:

package com.testcase.demo;

    import org.testng.annotations.Test;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.AfterClass;

    import io.appium.java_client.AppiumDriver;
    import io.appium.java_client.android.AndroidDriver;

    import java.net.URL;
    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;

    public class demo1 {
        private AppiumDriver  driver;


      @BeforeClass
      public void setup() throws Exception {
            DesiredCapabilities cap = new DesiredCapabilities();
            cap.setCapability(CapabilityType.BROWSER_NAME, ""); 
            cap.setCapability("platformName", "Android"); //指定测试平台
            cap.setCapability("deviceName", "MKJNW17C20005057"); //指定测试机的ID,通过adb命令`adb devices`获取
            cap.setCapability("platformVersion", "8.0"); 

            //将上面获取到的包名和Activity名设置为值
            cap.setCapability("appPackage", "com.android.ayplatform");
            cap.setCapability("appActivity", "com.android.ayplatform.activity.WelcomeActivity");

            //A new session could not be created
            //cap.setCapability("appWaitActivity","com.android.ayplatform.activity.WelcomeActivity");

            //每次启动时覆盖session,否则第二次后运行会报错不能新建session
            cap.setCapability("sessionOverride", true);
            //解决每次启动APP需要确认权限问题--即不重复安装
            cap.setCapability("noReset", true);
            cap.setCapability("noSign", true);


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


      }

      @Test 
      public void plus() throws InterruptedException{

          //
          Thread.sleep(3000);
          driver.findElementById("com.android.ayplatform:id/tv_tab_title").click();


      }

      @AfterClass
      public void tearDown() throws Exception {

          driver.quit();

      }



    }

log 输出为:

[info] [Appium] Welcome to Appium v1.7.2
[info] [Appium] Non-default server args:
[info] [Appium]   address: 127.0.0.1
[info] [Appium] Appium REST http interface listener started on 127.0.0.1:4723[info] [HTTP] --> POST /wd/hub/session {"desiredCapabilities":{"appPackage":"com.android.ayplatform","appActivity":"com.android.ayplatform.activity.WelcomeActivity","noReset":true,"noSign":true,"platformVersion":"8.0","browserName":"","sessionOverride":true,"platformName":"Android","deviceName":"MKJNW17C20005057"},"requiredCapabilities":{},"capabilities":{"desiredCapabilities":{"appPackage":"com.android.ayplatform","appActivity":"com.android.ayplatform.activity.WelcomeActivity","noReset":true,"noSign":true,"platformVersion":"8.0","browserName":"","sessionOverride":true,"platformName":"Android","deviceName":"MKJNW17C20005057"},"requiredCapabilities":{}},"alwaysMatch":{"appPackage":"com.android.ayplatform","appActivity":"com.android.ayplatform.activity.WelcomeActivity","noReset":true,"noSign":true,"platformVersion":"8.0","browserName":"","sessionOverride":true,"platformName":"Android","deviceName":"MKJNW17C20005057"},"firstMatch":[]}
[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{"appPackage":"com.android.ayplatform","appActivity":"com.android.ayplatform.activity.WelcomeActivity","noReset":true,"noSign":true,"platformVersion":"8.0","browserName":"","sessionOverride":true,"platformName":"Android","deviceName":"MKJNW17C20005057"},{},{"desiredCapabilities":{"appPackage":"com.android.ayplatform","appActivity":"com.android.ayplatform.activity.WelcomeActivity","noReset":true,"noSign":true,"platformVersion":"8.0","browserName":"","sessionOverride":true,"platformName":"Android","deviceName":"MKJNW17C20005057"},"requiredCapabilities":{}}]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1519638239571 (17:43:59 GMT+0800 (中国标准时间))
[info] [Appium] Merged W3C capabilities {"desiredCapabilities":{"appPackage":"com.andro... into desiredCapabilities object {"appPackage":"com.android.ayplatform","appActi...
[info] [Appium] Creating new AndroidDriver (v1.37.0) session
[info] [Appium] Capabilities:
[info] [Appium]   appPackage: com.android.ayplatform
[info] [Appium]   appActivity: com.android.ayplatform.activity.WelcomeActivity
[info] [Appium]   noReset: true
[info] [Appium]   noSign: true
[info] [Appium]   platformVersion: 8.0
[info] [Appium]   browserName: 
[info] [Appium]   sessionOverride: true
[info] [Appium]   platformName: Android
[info] [Appium]   deviceName: MKJNW17C20005057
[warn] [BaseDriver] The following capabilities were provided, but are not recognized by appium: sessionOverride.
[info] [BaseDriver] Session created with session id: 615cb23c-6193-4270-a686-38627f1c9af8
[debug] [AndroidDriver] Getting Java version[info] [AndroidDriver] Java version is: 1.8.0_131
[info] [ADB] Checking whether adb is present
[info] [ADB] Using adb.exe from E:\dev soft\android-sdk\platform-tools\adb.exe
[info] [AndroidDriver] Retrieving device list
[debug] [ADB] Trying to find a connected android device
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[info] [AndroidDriver] Looking for a device with Android '8.0'
[debug] [ADB] Setting device id to MKJNW17C20005057
[info] [ADB] Getting device platform version
[debug] [ADB] Getting connected devices...[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","getprop","ro.build.version.release"]
[debug] [ADB] Current device property 'ro.build.version.release': 8.0.0
[info] [AndroidDriver] Using device: MKJNW17C20005057
[info] [ADB] Checking whether adb is present
[debug] [ADB] Setting device id to MKJNW17C20005057
[info] [AndroidDriver] App file was not listed, instead we're going to run com.android.ayplatform 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 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","pm","list","packages","com.android.ayplatform"][info] [AndroidDriver] Starting Android session
[debug] [ADB] Running 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","wait-for-device"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","echo","ping"][warn] [AndroidDriver] setDeviceLanguageCountry requires language or country.
[warn] [AndroidDriver] Got language: 'undefined' and country: 'undefined'
[debug] [Logcat] Starting logcat capture
[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 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","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 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","dumpsys","package","io.appium.settings"][info] [ADB] Checking whether aapt is present
[info] [ADB] Using aapt.exe from E:\dev soft\android-sdk\build-tools\27.0.3\aapt.exe
[debug] [ADB] The installed 'io.appium.settings' package does not require upgrade (5 >= 5)
[debug] [ADB] Getting connected devices...[debug] [ADB] Current device property 'ro.build.version.sdk': 26
[debug] [ADB] Device API level: 26
[debug] [ADB] Getting connected devices...[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","dumpsys","package","io.appium.settings"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","pm","dump","io.appium.settings"][debug] [ADB] Got the following command chunks to execute: pm,grant,io.appium.settings,android.permission.WRITE_SETTINGS,;,pm,grant,io.appium.settings,android.permission.ACCESS_MOCK_LOCATION,;
[debug] [ADB] Getting connected devices...[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","pm","grant","io.appium.settings","android.permission.WRITE_SETTINGS",";","pm","grant","io.appium.settings","android.permission.ACCESS_MOCK_LOCATION",";"][debug] [ADB] Running 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","pm","grant","io.appium.settings","android.permission.WRITE_SETTINGS",";","pm","grant","io.appium.settings","android.permission.ACCESS_MOCK_LOCATION",";"][debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","ps"][debug] [ADB] Device API level: 26
[debug] [ADB] Getting connected devices...[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","appops","set","io.appium.settings","android:mock_location","allow"]
[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 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","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 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","dumpsys","package","io.appium.unlock"][debug] [ADB] The installed 'io.appium.unlock' package does not require upgrade (2 >= 2)
[info] [ADB] Getting device platform version
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","getprop","ro.build.version.release"][debug] [ADB] Current device property 'ro.build.version.release': 8.0.0
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","wm","size"][debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","getprop","ro.product.model"][debug] [ADB] Current device property 'ro.product.model': LLD-AL00
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","getprop","ro.product.manufacturer"][debug] [ADB] Current device property 'ro.product.manufacturer': HUAWEI
[warn] [AndroidDriver] No app sent in, not parsing package/activity
[debug] [AndroidDriver] No app capability. Assuming it is already on the device
[debug] [AndroidBootstrap] Watching for bootstrap disconnect
[debug] [ADB] Forwarding system: 4724 to device: 4724
[debug] [ADB] Running 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","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 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","push","C:\\Users\\kmnm\\AppData\\Local\\Programs\\appium-desktop\\resources\\app\\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 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","ps"][debug] [UiAutomator] Moving to state 'online'
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Registered crash watchers.
[info] [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 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","dumpsys","window"][debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","am","start","-W","-n","com.android.ayplatform/com.android.ayplatform.activity.WelcomeActivity","-S"][info] [Appium] New AndroidDriver session created successfully, session 615cb23c-6193-4270-a686-38627f1c9af8 added to master session list
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1519638253341 (17:44:13 GMT+0800 (中国标准时间))
[debug] [MJSONWP] Responding to client with driver.createSession() result: {"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"appPackage":"com.android.ayplatform","appActivity":"com.android.ayplatform.activity.WelcomeActivity","noReset":true,"noSign":true,"platformVersion":"8.0","browserName":"","sessionOverride":true,"platformName":"Android","deviceName":"MKJNW17C20005057"},"appPackage":"com.android.ayplatform","appActivity":"com.android.ayplatform.activity.WelcomeActivity","noReset":true,"noSign":true,"platformVersion":"8.0.0","browserName":"","sessionOverride":true,"platformName":"Android","deviceName":"MKJNW17C20005057","deviceUDID":"MKJNW17C20005057","deviceScreenSize":"1080x2160","deviceModel":"LLD-AL00","deviceManufacturer":"HUAWEI"}
[info] [HTTP] <-- POST /wd/hub/session 200 13775 ms - 903 [info] [HTTP] --> POST /wd/hub/session/615cb23c-6193-4270-a686-38627f1c9af8/element {"using":"id","value":"com.android.ayplatform:id/tv_tab_title"}
[debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["id","com.android.ayplatform:id/tv_tab_title","615cb23c-6193-4270-a686-38627f1c9af8"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.android.ayplatform:id/tv_tab_title","context":"","multiple":false}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.android.ayplatform:id/tv_tab_title","context":"","multiple":false}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.android.ayplatform:id/tv_tab_title' using 'ID' with the contextId: '' multiple: false
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.android.ayplatform:id/tv_tab_title]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":{"ELEMENT":"1"}}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"1"}
[info] [HTTP] <-- POST /wd/hub/session/615cb23c-6193-4270-a686-38627f1c9af8/element 200 117 ms - 87 
[info] [HTTP] --> POST /wd/hub/session/615cb23c-6193-4270-a686-38627f1c9af8/element/1/click {"id":"1"}
[debug] [MJSONWP] Calling AppiumDriver.click() with args: ["1","615cb23c-6193-4270-a686-38627f1c9af8"]
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:click","params":{"elementId":"1"}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"1"}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: click[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [MJSONWP] Responding to client with driver.click() result: true
[info] [HTTP] <-- POST /wd/hub/session/615cb23c-6193-4270-a686-38627f1c9af8/element/1/click 200 3286 ms - 76 
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
[info] [HTTP] --> DELETE /wd/hub/session/615cb23c-6193-4270-a686-38627f1c9af8 {}
[debug] [MJSONWP] Calling AppiumDriver.deleteSession() with args: ["615cb23c-6193-4270-a686-38627f1c9af8"]
[debug] [BaseDriver] Event 'quitSessionRequested' logged at 1519638259821 (17:44:19 GMT+0800 (中国标准时间))
[info] [Appium] Removing session 615cb23c-6193-4270-a686-38627f1c9af8 from our master session list
[debug] [AndroidDriver] Shutting down Android driver
[debug] [ADB] Getting connected devices...[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","am","force-stop","com.android.ayplatform"][debug] [ADB] Pressing the HOME button
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","input","keyevent",3][debug] [AndroidBootstrap] Sending command to android: {"cmd":"shutdown"}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"shutdown"}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type SHUTDOWN
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [UiAutomator] Shutting down UiAutomator
[debug] [UiAutomator] Moving to state 'stopping'
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":"OK, shutting down"}
[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 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","ps"]
[info] [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 'E:\dev soft\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","MKJNW17C20005057","shell","am","force-stop","io.appium.unlock"]
[debug] [AndroidDriver] Not cleaning generated files. Add `clearSystemFiles` capability if wanted.
[debug] [BaseDriver] Event 'quitSessionFinished' logged at 1519638261858 (17:44:21 GMT+0800 (中国标准时间))
[debug] [MJSONWP] Received response: null
[debug] [MJSONWP] But deleting session, so not returning
[debug] [MJSONWP] Responding to client with driver.deleteSession() result: null
[info] [HTTP] <-- DELETE /wd/hub/session/615cb23c-6193-4270-a686-38627f1c9af8 200 2038 ms - 76 
共收到 5 条回复 时间 点赞

android 8.0 请增加 desired_caps['automationName'] = 'UIAutomator2'

roc #2 · 2018年02月28日 Author
Wensau 回复

啊.已经解决了,感谢😀

有错误提示吗?

roc 回复

请问怎么解决的呀,我也遇到的一样的问题 App file was not listed,

roc 回复

怎么解决的 a.我也遇到同样的问题,启动之后不往下运行了

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册