Appium Appium1.7.2 android toast 消息测试

老马 · 2018年01月27日 · 最后由 yajunzheng 回复于 2018年09月06日 · 4091 次阅读

测试目的:

在鼓捣 atx 基于 python 的 uiautomator2 的 toast 消息提示。之前看到过基于 appium uiautomator2 的 toast 消息的捕获方案。
所以得先弄懂,弄通,以致 debug 通 appium uiautomator2 的 toast 消息的原理与调用的链路和包关系。

预置条件:

在 ATX363 python3.6.3 虚拟环境中 安装 Appium-Python-Client

(ATX363) cmd@TR:~$ pip install Appium-Python-Client
Collecting Appium-Python-Client
  Downloading Appium-Python-Client-0.26.tar.gz
Collecting selenium>=2.47.0 (from Appium-Python-Client)
  Downloading selenium-3.8.1-py2.py3-none-any.whl (942kB)
    100% |████████████████████████████████| 952kB 44kB/s 
Installing collected packages: selenium, Appium-Python-Client
  Running setup.py install for Appium-Python-Client ... done
Successfully installed Appium-Python-Client-0.26 selenium-3.8.1

再安装 selenium 发现已经提示安装好了,应该是 Appium-Python-Client 关联安装的

(ATX363) cmd@TR:~$ pip install selenium
Requirement already satisfied: selenium in ./.pyenv/versions/3.6.3/envs/ATX363/lib/python3.6/site-packages

查看下目前 ATX363 虚拟环境下已安装的 python 第三方库信息和版本

(ATX363) cmd@TR:~$ pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
aircv (1.4.6)
Appium-Python-Client (0.26)
atx (1.1.3.dev36)
atx-uiautomator (0.3.3)
AxmlParserPY (0.0.3)
certifi (2018.1.18)
chardet (3.0.4)
colorama (0.3.9)
decorator (4.2.1)
facebook-wda (0.2.2.dev1)
fire (0.1.2)
futures (3.0.5)
humanize (0.5.1)
idna (2.6)
imageio (2.2.0)
maproxy (0.0.12)
numpy (1.14.0)
opencv-contrib-python (3.4.0.12)
Pillow (5.0.0)
pip (9.0.1)
progress (1.3)
py (1.5.2)
PyYAML (3.11)
requests (2.18.4)
retry (0.9.2)
selenium (3.8.1)
setuptools (28.8.0)
six (1.11.0)
tornado (5.0a1)
tqdm (4.5.0)
uiautomator2 (0.0.4.dev1)
urllib3 (1.22)
weditor (0.0.4.dev6)

USB 连接我的小米 mix2 真机 ,开启手机开发者选项,开始 usb 调试模式和其它相关。

cmd@TR:~$ adb devices -l
List of devices attached
yournumber               device usb:3-1 product:chiron model:MIX_2 device:chiron

向手机安装百度阅读 apk

cmd@TR:~/app$ adb install baiduyuedu_5150.apk
Success

犯贱又初始化向手机安装了 atx 的 uiautomator2 相关手机端

(ATX363) cmd@TR:~$ python -m uiautomator2 init
2018-01-27 10:08:39,404 - __main__.py:241 - INFO - Device(45806625) initialing ...
2018-01-27 10:08:39,646 - __main__.py:120 - INFO - install minicap
2018-01-27 10:08:39,768 - __main__.py:127 - INFO - install minitouch
2018-01-27 10:08:39,980 - __main__.py:142 - INFO - apk(1.0.9) already installed, skip
2018-01-27 10:08:41,310 - __main__.py:162 - INFO - atx-agent(0.1.5) already installed, skip
2018-01-27 10:08:44,575 - __main__.py:211 - INFO - atx-agent output: server started, listening on 172.25.69.55:7912
2018-01-27 10:08:44,575 - __main__.py:212 - INFO - success

检查 appium 版本和开启 appium 服务

cmd@TR:~$ appium -v
1.7.2
cmd@TR:~$ appium-doctor
info AppiumDoctor Appium Doctor v.1.4.3
info AppiumDoctor ### Diagnostic starting ###
info AppiumDoctor  ✔ The Node.js binary was found at: /opt/nodejs/bin/node
info AppiumDoctor  ✔ Node version is 6.10.3
info AppiumDoctor  ✔ ANDROID_HOME is set to: /opt/android-sdk-linux
info AppiumDoctor  ✔ JAVA_HOME is set to: /usr/lib/jvm/java-8-oracle
info AppiumDoctor  ✔ adb exists at: /opt/android-sdk-linux/platform-tools/adb
info AppiumDoctor  ✔ android exists at: /opt/android-sdk-linux/tools/android
info AppiumDoctor  ✔ emulator exists at: /opt/android-sdk-linux/tools/emulator
info AppiumDoctor  ✔ Bin directory of $JAVA_HOME is set
info AppiumDoctor ### Diagnostic completed, no fix needed. ###
info AppiumDoctor 
info AppiumDoctor Everything looks good, bye!
info AppiumDoctor 

cmd@TR:~$ appium --session-override -p 4730
[Appium] Welcome to Appium v1.7.2
[Appium] Non-default server args:
[Appium]   port: 4730
[Appium]   sessionOverride: true
[Appium] Appium REST http interface listener started on 0.0.0.0:4730

编辑脚本:

使用 pycharm,先去 File-> Settings-> Project -> Project Interpreter -> Add Local
在 Existing environment 中选择/home/cmd/.pyenv/versions/ATX363/bin/python 切换到 ATX363 虚拟环境,以便 import 到在该环境安装的 appium python clinet 和 selenium 包。

编辑 FindToastTest.py 脚本,内容如下

# coding:utf-8
from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.by import By
import unittest
import time

class FindToastTest(unittest.TestCase):

    def setUp(self):
        desired_caps = {"platformName": "Android",
                        "platformVersion": "7.1.1",
                        "deviceName": "MIX_2",
                        "udid": "yournumber",
                        "appPackage": "com.baidu.yuedu",
                        "appActivity": "com.baidu.yuedu.splash.SplashActivity",
                        "noReset": True,
                        'newCommandTimeout': 30,
                        "unicodeKeyboard": True,
                        "resetKeyboard": True,
                        'automationName': 'Uiautomator2',
                        "noSign": True}

        remote = "http://localhost:4730/wd/hub"
        self.d = webdriver.Remote(remote, desired_caps)


    def is_toast_exist(driver,toastmessage,timeout=30,poll_frequency=0.5):
        '''is toast exist, return True or False
        :Agrs:
         - driver - 传driver
         - toastmessage   - 页面上看到的toast消息文本内容
         - timeout - 最大超时时间,默认30s
         - poll_frequency  - 间隔查询时间,默认0.5s查询一次
        :Usage:
         is_toast_exist(driver, "toast消息的内容")
        '''
        try:
            toast_loc = ("xpath", ".//*[contains(@text,'%s')]" % toastmessage)
            WebDriverWait(driver, timeout, poll_frequency).until(expected_conditions.presence_of_element_located(toast_loc))
            return True
        except:
            return False

#       element = WebDriverWait(driver,timeout,poll_frequency).until(expected_conditions.presence_of_element_located((By.PARTIAL_LINK_TEXT,message)))


    def test_toast(self):
        #等待主页面activity出现
        self.d.wait_activity(".base.ui.MainActivity", 10)
        # 点击返回,退出app
        self.d.back()
        toastresult = self.is_toast_exist(self.d,'百度阅读:再按一次退出')
        if toastresult is True:
            print('Test Success find toast message')
        else:
            print('Test Failed not find toast message')



    def tearDown(self):
        try:
            self.d.quit()
        except:
            pass

if __name__ == '__main__':
    try:
        suite = unittest.TestLoader().loadTestsFromTestCase(FindToastTest)
        unittest.TextTestRunner(verbosity=2).run(suite)
    except SystemExit:
        pass

开始测试:

运行该脚本 已经安装有 atx-uiautomator2 的手机,连接 的 appium server 会报错
手机端卸载掉 uiautomator2 后,可以正常跑 FindToastTest.py 期间手机端弹出提示安装了 io.appium.uiautomator2.server 和 io.appium.uiautomator2.server.test
(当然如果是第一次用该手机的话还会提示安装 Unlock 和 Appium Setting )

参考内容:

参考了以下前辈和大神的方案,站在巨人的肩膀上,能让我们走的更远,感谢以下人士的不懈努力和分享。
http://blog.csdn.net/songer_xing/article/details/71272566

final WebDriverWait wait = new WebDriverWait(driver,3);
Assert.assertNotNull(wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//*[contains(@text,'"+ toast + "')]"))));
log.info("查找toast成功!");
return true;
} catch (Exception e) {
throw new AssertionError("找不到"+toast);

https://mp.weixin.qq.com/s?__biz=MzI5ODU1MzkwMA==&mid=2247484294&idx=1&sn=d860af3f4b4049d42f7f95cd086400e9&chksm=eca544c5dbd2cdd3b5810fa7f5d1316352266c45df093c0cc80ddac4e5f008de68398af29344&mpshare=1&scene=23&srcid=12259hUg47FJIQGCd7OEV9Dt#rd

def is_toast_exist(driver,text,timeout=30,poll_frequency=0.5):
   '''is toast exist, return True or False
   :Agrs:
    - driver - 传driver
    - text   - 页面上看到的文本内容
    - timeout - 最大超时时间,默认30s
    - poll_frequency  - 间隔查询时间,默认0.5s查询一次
   :Usage:
    is_toast_exist(driver, "看到的内容")
   '''
   try:
       toast_loc = ("xpath", ".//*[contains(@text,'%s')]"%text)
       WebDriverWait(driver, timeout, poll_frequency).until(EC.presence_of_element_located(toast_loc))
       return True
   except:
       return False

参考这个帖子http://testerhome.com/topics/2354 回帖中的 waitForElement,我自己写了一个 appium selendroid 模式下的 python 函数查找 toast

message消息内容
timeout超时时间
poll_frequency查询步长
driver就是driver

from

selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions

def find_toast(message,timeout,poll_frequency,driver):
    element = WebDriverWait(driver,timeout,poll_frequency).until(expected_conditions.presence_of_element_located((By.PARTIAL_LINK_TEXT,message)))

补充:

atx-uiautomator2 的 toast 消息也测试通过了
atx-uiautomator2 识别 android toast 测试

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 11 条回复 时间 点赞
老马 #12 · 2018年01月27日 Author

附上第二次跑的 appium server 端 log 留存以便逆向分析 server 执行过程和调用

cmd@TR:~$ appium --session-override -p 4730
[Appium] Welcome to Appium v1.7.2
[Appium] Non-default server args:
[Appium]   port: 4730
[Appium]   sessionOverride: true
[Appium] Appium REST http interface listener started on 0.0.0.0:4730
[HTTP] --> POST /wd/hub/session {"capabilities":{"firstMatch":[{}],"alwaysMatch":{"platformName":"Android"}},"desiredCapabilities":{"platformName":"Android","platformVersion":"7.1.1","deviceName":"MIX_2","udid":"45806625","appPackage":"com.baidu.yuedu","appActivity":"com.baidu.yuedu.splash.SplashActivity","noReset":true,"newCommandTimeout":30,"unicodeKeyboard":true,"resetKeyboard":true,"automationName":"Uiautomator2","noSign":true}}
[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{"platformName":"Android","platformVersion":"7.1.1","deviceName":"MIX_2","udid":"45806625","appPackage":"com.baidu.yuedu","appActivity":"com.baidu.yuedu.splash.SplashActivity","noReset":true,"newCommandTimeout":30,"unicodeKeyboard":true,"resetKeyboard":true,"automationName":"Uiautomator2","noSign":true},null,{"firstMatch":[{}],"alwaysMatch":{"platformName":"Android"}}]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1517024576592 (11:42:56 GMT+0800 (CST))
[Appium] Merged W3C capabilities {"firstMatch":[{}],"alwaysMatch":{"platformName... into desiredCapabilities object {"platformName":"Android","platformVersion":"7....
[Appium] Creating new AndroidUiautomator2Driver (v0.11.0) session
[Appium] Capabilities:
[Appium]   platformName: Android
[Appium]   platformVersion: 7.1.1
[Appium]   deviceName: MIX_2
[Appium]   udid: 45806625
[Appium]   appPackage: com.baidu.yuedu
[Appium]   appActivity: com.baidu.yuedu.splash.SplashActivity
[Appium]   noReset: true
[Appium]   newCommandTimeout: 30
[Appium]   unicodeKeyboard: true
[Appium]   resetKeyboard: true
[Appium]   automationName: Uiautomator2
[Appium]   noSign: true
[BaseDriver] Session created with session id: 24fb9178-cb4c-45b4-90e8-4613cf46664e
[debug] [AndroidDriver] Getting Java version
[AndroidDriver] Java version is: 1.8.0_161
[ADB] Checking whether adb is present
[ADB] Using adb from /opt/android-sdk-linux/platform-tools/adb
[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] Using device: 45806625
[ADB] Checking whether adb is present
[debug] [ADB] Setting device id to 45806625
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","getprop","ro.build.version.sdk"]
[debug] [ADB] Current device property 'ro.build.version.sdk': 25
[debug] [ADB] Device API level: 25
[AndroidDriver] No app sent in, not parsing package/activity
[ADB] Getting device platform version
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","getprop","ro.build.version.release"]
[debug] [ADB] Current device property 'ro.build.version.release': 7.1.1
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","wm","size"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","wm","density"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","getprop","ro.product.model"]
[debug] [ADB] Current device property 'ro.product.model': MIX 2
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","getprop","ro.product.manufacturer"]
[debug] [ADB] Current device property 'ro.product.manufacturer': Xiaomi
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","am","force-stop","io.appium.uiautomator2.server"]
[ADB] Checking whether aapt is present
[ADB] Using aapt from /opt/android-sdk-linux/build-tools/25.0.2/aapt
[debug] [ADB] Getting install status for io.appium.uiautomator2.server
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","pm","list","packages","io.appium.uiautomator2.server"]
[debug] [ADB] App is installed
[debug] [ADB] Getting install status for io.appium.uiautomator2.server.test
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","pm","list","packages","io.appium.uiautomator2.server.test"]
[debug] [ADB] App is installed
[debug] [ADB] Getting package info for io.appium.uiautomator2.server
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","dumpsys","package","io.appium.uiautomator2.server"]
[debug] [UiAutomator2] Waiting up to 20000ms for instrumentation 'io.appium.uiautomator2.server.test/android.support.test.runner.AndroidJUnitRunner' to be available
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","pm","list","instrumentation"]
[debug] [UiAutomator2] Instrumentation 'io.appium.uiautomator2.server.test/android.support.test.runner.AndroidJUnitRunner' available
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","wait-for-device"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","echo","ping"]
[AndroidDriver] setDeviceLanguageCountry requires language or country.
[AndroidDriver] Got language: 'null' and country: 'null'
[debug] [Logcat] Starting logcat capture
[debug] [AndroidDriver] Enabling Unicode keyboard support
[debug] [AndroidDriver] Pushing unicode ime to device...
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","install","/opt/nodejs/lib/node_modules/appium/node_modules/appium-android-ime/bin/UnicodeIME-debug.apk"]
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","install","/opt/nodejs/lib/node_modules/appium/node_modules/appium-android-ime/bin/UnicodeIME-debug.apk"]
[debug] [ADB] Application '/opt/nodejs/lib/node_modules/appium/node_modules/appium-android-ime/bin/UnicodeIME-debug.apk' already installed. Continuing.
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","settings","get","secure","default_input_method"]
[debug] [AndroidDriver] Unsetting previous IME io.appium.android.ime/.UnicodeIME
[debug] [AndroidDriver] Setting IME to 'io.appium.android.ime/.UnicodeIME'
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","ime","enable","io.appium.android.ime/.UnicodeIME"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","ime","set","io.appium.android.ime/.UnicodeIME"]
[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 '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","pm","list","packages","io.appium.settings"]
[debug] [ADB] App is not installed
[debug] [ADB] App '/opt/nodejs/lib/node_modules/appium/node_modules/io.appium.settings/app/build/outputs/apk/settings_apk-debug.apk' not installed. Installing
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","install","/opt/nodejs/lib/node_modules/appium/node_modules/io.appium.settings/app/build/outputs/apk/settings_apk-debug.apk"]
[debug] [ADB] Device API level: 25
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","dumpsys","package","io.appium.settings"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","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,;,pm,grant,io.appium.settings,android.permission.SET_ANIMATION_SCALE,;,pm,grant,io.appium.settings,android.permission.CHANGE_CONFIGURATION,;
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","pm","grant","io.appium.settings","android.permission.WRITE_SETTINGS",";","pm","grant","io.appium.settings","android.permission.ACCESS_MOCK_LOCATION",";","pm","grant","io.appium.settings","android.permission.SET_ANIMATION_SCALE",";","pm","grant","io.appium.settings","android.permission.CHANGE_CONFIGURATION",";"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","ps"]
[debug] [ADB] Device API level: 25
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","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: 25
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","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 '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","pm","list","packages","io.appium.unlock"]
[debug] [ADB] App is not installed
[debug] [ADB] App '/opt/nodejs/lib/node_modules/appium/node_modules/appium-unlock/bin/unlock_apk-debug.apk' not installed. Installing
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","install","/opt/nodejs/lib/node_modules/appium/node_modules/appium-unlock/bin/unlock_apk-debug.apk"]
[debug] [UiAutomator2] Forwarding UiAutomator2 Server port 6790 to 8200
[debug] [ADB] Forwarding system: 8200 to device: 6790
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","forward","tcp:8200","tcp:6790"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","dumpsys","window"]
[AndroidDriver] Screen already unlocked, doing nothing
[debug] [AndroidDriver] Extracting strings from apk null null /tmp/com.baidu.yuedu
[debug] [ADB] Extracting strings for language: default
[debug] [ADB] Device API level: 25
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","getprop","persist.sys.locale"]
[debug] [ADB] Current device property 'persist.sys.locale': 
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","getprop","ro.product.locale"]
[debug] [ADB] Current device property 'ro.product.locale': zh-CN
[debug] [ADB] No strings.xml for language 'zh', getting default strings.xml
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","rm","-rf","/data/local/tmp/strings.json"]
[debug] [UiAutomator2] No app capability. Assuming it is already on the device
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","am","force-stop","io.appium.uiautomator2.server"]
[UiAutomator2] Starting uiautomator2 server v0.3.0
[UiAutomator2] Running command: 'adb -s 45806625 shell am instrument -w io.appium.uiautomator2.server.test/android.support.test.runner.AndroidJUnitRunner'
[UiAutomator2] Waiting up to 20000ms for UiAutomator2 to be online...
[debug] [JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[debug] [JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[debug] [JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[debug] [JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[debug] [JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"SESSIONID\",\"status\":0,\"value\":\"Status Invoked\"}"
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://localhost:8200/wd/hub/session] with body: {"desiredCapabilities":{"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformName":"Android","platformVersion":"7.1.1","deviceName":"MIX_2","udid":"45806625","appPackage":"com.baidu.yuedu","appActivity":"com.baidu.yuedu.splash.SplashActivity","noReset":true,"newCommandTimeout":30,"unicodeKeyboard":true,"resetKeyboard":true,"automationName":"Uiautomator2","noSign":true},"platformName":"Android","platformVersion":"7.1.1","deviceName":"45806625","udid":"45806625","appPackage":"com.baidu.yuedu","appActivity":"com.baidu.yuedu.splash.SplashActivity","noReset":true,"newCommandTimeout":30,"unicodeKeyboard":true,"resetKeyboard":true,"automationName":"Uiautomator2","noSign":true,"deviceUDID":"45806625","deviceScreenSize":"1080x2160","deviceScreenDensity":440,"deviceModel":"MIX 2","deviceManufacturer":"Xiaomi"}}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"5cd67617-b9ae-4de5-a567-64a83e6d4887","status":0,"value":"Created Session"}
[UiAutomator2] UiAutomator2 did not start the activity we were waiting for, 'com.baidu.yuedu/com.baidu.yuedu.splash.SplashActivity'. Starting it ourselves
[debug] [ADB] Device API level: 25
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","am","start","-W","-n","com.baidu.yuedu/com.baidu.yuedu.splash.SplashActivity","-S","-a","android.intent.action.MAIN","-c","android.intent.category.LAUNCHER","-f","0x10200000"]
[Appium] New AndroidUiautomator2Driver session created successfully, session 24fb9178-cb4c-45b4-90e8-4613cf46664e added to master session list
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1517024599978 (11:43:19 GMT+0800 (CST))
[debug] [MJSONWP] Responding to client with driver.createSession() result: {"platformName":"Android","platformVersion":"7.1.1","deviceName":"MIX_2","udid":"45806625","appPackage":"com.baidu.yuedu","appActivity":"com.baidu.yuedu.splash.SplashActivity","noReset":true,"newCommandTimeout":30,"unicodeKeyboard":true,"resetKeyboard":true,"automationName":"Uiautomator2","noSign":true}
[HTTP] <-- POST /wd/hub/session 200 23392 ms - 376 
[HTTP] --> GET /wd/hub/session/24fb9178-cb4c-45b4-90e8-4613cf46664e/appium/device/current_activity {}
[debug] [MJSONWP] Calling AppiumDriver.getCurrentActivity() with args: ["24fb9178-cb4c-45b4-90e8-4613cf46664e"]
[debug] [ADB] Getting focused package and activity
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","dumpsys","window","windows"]
[debug] [MJSONWP] Responding to client with driver.getCurrentActivity() result: ".splash.SplashActivity"
[HTTP] <-- GET /wd/hub/session/24fb9178-cb4c-45b4-90e8-4613cf46664e/appium/device/current_activity 200 51 ms - 96 
[HTTP] --> GET /wd/hub/session/24fb9178-cb4c-45b4-90e8-4613cf46664e/appium/device/current_activity {}
[debug] [MJSONWP] Calling AppiumDriver.getCurrentActivity() with args: ["24fb9178-cb4c-45b4-90e8-4613cf46664e"]
[debug] [ADB] Getting focused package and activity
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","dumpsys","window","windows"]
[debug] [MJSONWP] Responding to client with driver.getCurrentActivity() result: ".splash.SplashActivity"
[HTTP] <-- GET /wd/hub/session/24fb9178-cb4c-45b4-90e8-4613cf46664e/appium/device/current_activity 200 44 ms - 96 
[HTTP] --> GET /wd/hub/session/24fb9178-cb4c-45b4-90e8-4613cf46664e/appium/device/current_activity {}
[debug] [MJSONWP] Calling AppiumDriver.getCurrentActivity() with args: ["24fb9178-cb4c-45b4-90e8-4613cf46664e"]
[debug] [ADB] Getting focused package and activity
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","dumpsys","window","windows"]
[debug] [MJSONWP] Responding to client with driver.getCurrentActivity() result: ".splash.SplashActivity"
[HTTP] <-- GET /wd/hub/session/24fb9178-cb4c-45b4-90e8-4613cf46664e/appium/device/current_activity 200 79 ms - 96 
[HTTP] --> GET /wd/hub/session/24fb9178-cb4c-45b4-90e8-4613cf46664e/appium/device/current_activity {}
[debug] [MJSONWP] Calling AppiumDriver.getCurrentActivity() with args: ["24fb9178-cb4c-45b4-90e8-4613cf46664e"]
[debug] [ADB] Getting focused package and activity
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","dumpsys","window","windows"]
[debug] [MJSONWP] Responding to client with driver.getCurrentActivity() result: ".splash.SplashActivity"
[HTTP] <-- GET /wd/hub/session/24fb9178-cb4c-45b4-90e8-4613cf46664e/appium/device/current_activity 200 83 ms - 96 
[HTTP] --> GET /wd/hub/session/24fb9178-cb4c-45b4-90e8-4613cf46664e/appium/device/current_activity {}
[debug] [MJSONWP] Calling AppiumDriver.getCurrentActivity() with args: ["24fb9178-cb4c-45b4-90e8-4613cf46664e"]
[debug] [ADB] Getting focused package and activity
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","dumpsys","window","windows"]
[debug] [MJSONWP] Responding to client with driver.getCurrentActivity() result: ".splash.SplashActivity"
[HTTP] <-- GET /wd/hub/session/24fb9178-cb4c-45b4-90e8-4613cf46664e/appium/device/current_activity 200 60 ms - 96 
[HTTP] --> GET /wd/hub/session/24fb9178-cb4c-45b4-90e8-4613cf46664e/appium/device/current_activity {}
[debug] [MJSONWP] Calling AppiumDriver.getCurrentActivity() with args: ["24fb9178-cb4c-45b4-90e8-4613cf46664e"]
[debug] [ADB] Getting focused package and activity
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","dumpsys","window","windows"]
[debug] [MJSONWP] Responding to client with driver.getCurrentActivity() result: ".base.ui.MainActivity"
[HTTP] <-- GET /wd/hub/session/24fb9178-cb4c-45b4-90e8-4613cf46664e/appium/device/current_activity 200 66 ms - 95 
[HTTP] --> POST /wd/hub/session/24fb9178-cb4c-45b4-90e8-4613cf46664e/back {"sessionId":"24fb9178-cb4c-45b4-90e8-4613cf46664e"}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[debug] [JSONWP Proxy] Proxying [POST /wd/hub/session/24fb9178-cb4c-45b4-90e8-4613cf46664e/back] to [POST http://localhost:8200/wd/hub/session/5cd67617-b9ae-4de5-a567-64a83e6d4887/back] with body: {"sessionId":"24fb9178-cb4c-45b4-90e8-4613cf46664e"}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"5cd67617-b9ae-4de5-a567-64a83e6d4887","status":0,"value":true}
[JSONWP Proxy] Replacing sessionId 5cd67617-b9ae-4de5-a567-64a83e6d4887 with 24fb9178-cb4c-45b4-90e8-4613cf46664e
[HTTP] <-- POST /wd/hub/session/24fb9178-cb4c-45b4-90e8-4613cf46664e/back 200 4540 ms - 76 
[HTTP] --> DELETE /wd/hub/session/24fb9178-cb4c-45b4-90e8-4613cf46664e {}
[debug] [MJSONWP] Calling AppiumDriver.deleteSession() with args: ["24fb9178-cb4c-45b4-90e8-4613cf46664e"]
[debug] [BaseDriver] Event 'quitSessionRequested' logged at 1517024609935 (11:43:29 GMT+0800 (CST))
[Appium] Removing session 24fb9178-cb4c-45b4-90e8-4613cf46664e from our master session list
[debug] [UiAutomator2] Deleting UiAutomator2 session
[debug] [UiAutomator2] Deleting UiAutomator2 server session
[debug] [JSONWP Proxy] Proxying [DELETE /] to [DELETE http://localhost:8200/wd/hub/session/5cd67617-b9ae-4de5-a567-64a83e6d4887] with no body
[debug] [JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"5cd67617-b9ae-4de5-a567-64a83e6d4887\",\"status\":0,\"value\":\"Session deleted\"}"
[debug] [UiAutomator2] Resetting IME to 'io.appium.android.ime/.UnicodeIME'
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","ime","set","io.appium.android.ime/.UnicodeIME"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","shell","am","force-stop","com.baidu.yuedu"]
[debug] [UiAutomator2] [UIAutomator2] io.appium.uiautomator2.server.test.AppiumUiAutomator2Server:.
[debug] [UiAutomator2] [UIAutomator2] Time: 14.045
[debug] [UiAutomator2] [UIAutomator2] OK (1 test)
[debug] [Logcat] Stopping logcat capture
[debug] [ADB] Removing forwarded port socket connection: 8200 
[debug] [ADB] Running '/opt/android-sdk-linux/platform-tools/adb' with args: ["-P",5037,"-s","45806625","forward","--remove","tcp:8200"]
[debug] [BaseDriver] Event 'quitSessionFinished' logged at 1517024611138 (11:43:31 GMT+0800 (CST))
[debug] [MJSONWP] Received response: null
[debug] [MJSONWP] But deleting session, so not returning
[debug] [MJSONWP] Responding to client with driver.deleteSession() result: null
[HTTP] <-- DELETE /wd/hub/session/24fb9178-cb4c-45b4-90e8-4613cf46664e 200 1206 ms - 76 

老马 atx-uiautomator2 识别 android toast 测试 中提及了此贴 01月27日 16:07

大哥 我用 ui2 启动报错 用 appium 启动就成功。什么原因呢
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: zipAlignApk failed. Original error: Command 'C:\Android\android-sdk\build-tools\27.0.3\zipalign.exe -f 4 C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-uiautomator2-driver\@0.11.0\@appium-uiautomator2-driver\uiautomator2\appium-uiautomator2-server-v0.3.0.apk C:\Users\woxia\AppData\Local\Temp\2018221-5612-1cbydc6.me19f\appium.tmp' exited with code 1. Stdout: ''; Stderr: ''

宣梦达 回复

哈哈 atx-u2 更新很快的, atx-u2 已经原生提供了个 识别 toast 的 api 方法了. 你可以不用我发的这个了.
这种不是个长久方案的.

@harsayer 谢谢大佬回答 我有一个问题困扰几天了 吃不下饭 就是我微信切换 webview 会卡主不动 过几分钟就会报错 哎
跟这个网址的问题是一样的:https://testerhome.com/topics/11754 但是他解决了 没写解决方案 哎

宣梦达 回复

https://testerhome.com/topics/12003 你试试这个人发的方法
哦 看到你回帖了 也许你替换的具体行为方式不对,
1 是直接找到路径 单独下载再替换的.
http://chromedriver.storage.googleapis.com/index.html
2 一般我都是 在 npm 安装过程中指定

CHROMEDRIVER_VERSION=2.25 npm i appium  -g
 npm install chromedriver --chromedriver_cdnurl=http://npm.taobao.org/mirrors/chromedriver --CHROMEDRIVER_VERSION=2.25

Linux:
export CHROMEDRIVER_CDNURL=http://npm.taobao.org/mirrors/chromedriver/
windows:
set  CHROMEDRIVER_CDNURL=http://npm.taobao.org/mirrors/chromedriver/
npm i appium -g

@harsayer 用代码安装 我也试了 一样会卡主 你的微信切换会卡主吗

@harsayer 大哥 有一个问题 我使用 UI2 运行启动微信会报错

报错信息如下

appium 报错如下
[Appium] Welcome to Appium v1.7.1
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
[HTTP] --> POST /wd/hub/session
[HTTP] {"capabilities":{"alwaysMatch":{"platformName":"Android"},"firstMatch":[{}]},"desiredCapabilities":{"deviceName":"35795c08","automationName":"UiAutomator2","noReset":true,"platformVersion":"7.1.1","appPackage":"com.tencent.mm","platformName":"Android","appActivity":".ui.LauncherUI"}}
[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{"deviceName":"35795c08","automationName":"UiAutomator2","noReset":true,"platformVersion":"7.1.1","appPackage":"com.tencent.mm","platformName":"Android","appActivity":".ui.LauncherUI"},null,{"alwaysMatch":{"platformName":"Android"},"firstMatch":[{}]}]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1521769030535 (09:37:10 GMT+0800 (中国标准时间))
[Appium] Creating new AndroidUiautomator2Driver (v0.11.0) session
[Appium] Capabilities:
[Appium] deviceName: '35795c08'
[Appium] automationName: 'UiAutomator2'
[Appium] noReset: true
[Appium] platformVersion: '7.1.1'
[Appium] appPackage: 'com.tencent.mm'
[Appium] platformName: 'Android'
[Appium] appActivity: '.ui.LauncherUI'
[debug] [BaseDriver] W3C capabilities [] and MJSONWP desired capabilities were provided
[BaseDriver] Falling back to MJSONWP desired capabilities
[BaseDriver] Session created with session id: 21bfc20f-129f-42e8-a44c-bc64bbde2175
[debug] [AndroidDriver] Getting Java version
[AndroidDriver] Java version is: 1.8.0_161
[ADB] Checking whether adb is present
[ADB] Found 1 'build-tools' folders under 'C:\Android\android-sdk' (newest first):
[ADB] C:/Android/android-sdk/build-tools/27.0.3
[ADB] Using adb.exe from C:\Android\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.1.1'
[debug] [ADB] Setting device id to 35795c08
[ADB] Getting device platform version
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Android\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","35795c08","shell","getprop","ro.build.version.release"]
[debug] [ADB] Current device property 'ro.build.version.release': 7.1.1
[AndroidDriver] Using device: 35795c08
[ADB] Checking whether adb is present
[ADB] Using adb.exe from C:\Android\android-sdk\platform-tools\adb.exe
[debug] [ADB] Setting device id to 35795c08
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Android\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","35795c08","shell","getprop","ro.build.version.sdk"]
[debug] [ADB] Current device property 'ro.build.version.sdk': 25
[debug] [ADB] Device API level: 25
[AndroidDriver] No app sent in, not parsing package/activity
[ADB] Getting device platform version
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Android\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","35795c08","shell","getprop","ro.build.version.release"]
[debug] [ADB] Current device property 'ro.build.version.release': 7.1.1
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Android\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","35795c08","shell","wm","size"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Android\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","35795c08","shell","wm","density"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Android\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","35795c08","shell","getprop","ro.product.model"]
[debug] [ADB] Current device property 'ro.product.model': ONEPLUS A5010
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Android\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","35795c08","shell","getprop","ro.product.manufacturer"]
[debug] [ADB] Current device property 'ro.product.manufacturer': OnePlus
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Android\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","35795c08","shell","am","force-stop","io.appium.uiautomator2.server"]
[ADB] Checking whether aapt is present
[ADB] Using aapt.exe from C:\Android\android-sdk\build-tools\27.0.3\aapt.exe
[debug] [ADB] Getting install status for io.appium.uiautomator2.server
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Android\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","35795c08","shell","pm","list","packages","io.appium.uiautomator2.server"]
[debug] [ADB] App is not installed
[debug] [ADB] Getting install status for io.appium.uiautomator2.server.test
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Android\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","35795c08","shell","pm","list","packages","io.appium.uiautomator2.server.test"]
[debug] [ADB] App is not installed
[debug] [ADB] Checking app cert for C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_appium-uiautomator2-driver@0.11.0@appium-uiautomator2-driver\uiautomator2\appium-uiautomator2-server-v0.3.0.apk
[ADB] Using apksigner.bat from C:\Android\android-sdk\build-tools\27.0.3\apksigner.bat
[ADB] Using apksigner.bat from C:\Android\android-sdk\build-tools\27.0.3\apksigner.bat
[debug] [ADB] Patching 'C:\Android\android-sdk\build-tools\27.0.3\apksigner.bat' for Windows...
[debug] [ADB] Starting patched 'C:\Users\woxia\AppData\Local\Temp\2018223-13176-94baul.m94r\apksigner.bat' with args 'verify,--print-certs,C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_appium-uiautomator2-driver@0.11.0@appium-uiautomator2-driver\uiautomator2\appium-uiautomator2-server-v0.3.0.apk'
[debug] [ADB] 'C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_appium-uiautomator2-driver@0.11.0@appium-uiautomator2-driver\uiautomator2\appium-uiautomator2-server-v0.3.0.apk' is not signed with debug cert.
[ADB] Using apksigner.bat from C:\Android\android-sdk\build-tools\27.0.3\apksigner.bat
[debug] [ADB] Zip-aligning 'C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_appium-uiautomator2-driver@0.11.0@appium-uiautomator2-driver\uiautomator2\appium-uiautomator2-server-v0.3.0.apk'
[ADB] Checking whether zipalign is present
[ADB] Using zipalign.exe from C:\Android\android-sdk\build-tools\27.0.3\zipalign.exe
[ADB] Error: zipAlignApk failed. Original error: Command 'C:\Android\android-sdk\build-tools\27.0.3\zipalign.exe -f 4 C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-uiautomator2-driver\@0.11.0\@appium-uiautomator2-driver\uiautomator2\appium-uiautomator2-server-v0.3.0.apk C:\Users\woxia\AppData\Local\Temp\2018223-13176-1qe09sk.tno7\appium.tmp' exited with code 1. Stdout: ''; Stderr: ''
[ADB] at Object.wrappedLogger.errorAndThrow (../../lib/logging.js:78:13)
[ADB] at ADB.callee$0$0$ (../../../lib/tools/apk-signing.js:179:9)
[ADB] at tryCatch (C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_babel-runtime@5.8.24@babel-runtime\regenerator\runtime.js:67:40)
[ADB] at GeneratorFunctionPrototype.invoke as _invoke
[ADB] at GeneratorFunctionPrototype.prototype.(anonymous function) as next
[ADB] at GeneratorFunctionPrototype.invoke (C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_babel-runtime@5.8.24@babel-runtime\regenerator\runtime.js:136:37)
[ADB] at
[debug] [ADB] Signing 'C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_appium-uiautomator2-driver@0.11.0@appium-uiautomator2-driver\uiautomator2\appium-uiautomator2-server-v0.3.0.apk' with default cert
[ADB] Using apksigner.bat from C:\Android\android-sdk\build-tools\27.0.3\apksigner.bat
[debug] [ADB] Patching 'C:\Android\android-sdk\build-tools\27.0.3\apksigner.bat' for Windows...
[debug] [ADB] Starting patched 'C:\Users\woxia\AppData\Local\Temp\2018223-13176-161hjdq.b04b\apksigner.bat' with args 'sign,--key,C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_appium-adb@6.5.1@appium-adb\keys\testkey.pk8,--cert,C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_appium-adb@6.5.1@appium-adb\keys\testkey.x509.pem,C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_appium-uiautomator2-driver@0.11.0@appium-uiautomator2-driver\uiautomator2\appium-uiautomator2-server-v0.3.0.apk'
[debug] [UiAutomator2] Deleting UiAutomator2 session
[debug] [UiAutomator2] Deleting UiAutomator2 server session
[UiAutomator2] Did not get confirmation UiAutomator2 deleteSession worked; Error was: Error: Trying to proxy a session command without session id
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Android\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","35795c08","shell","am","force-stop","com.tencent.mm"]
[debug] [ADB] Removing forwarded port socket connection: 8200
[debug] [ADB] Running 'C:\Android\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","35795c08","forward","--remove","tcp:8200"]
[debug] [ADB] Running 'C:\Android\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","35795c08","forward","--remove","tcp:8200"]
[UiAutomator2] Unable to remove port forward 'Error executing adbExec. Original error: 'Command 'C:\Android\android-sdk\platform-tools\adb.exe -P 5037 -s 35795c08 forward --remove tcp:8200' exited with code 1'; Stderr: 'error: listener 'tcp:8200' not found'; Code: '1''
[W3C] Encountered internal error running command: TypeError: Cannot create property 'replace' on boolean 'true'
[W3C] at ADB.callee$0$0$ (../../../lib/tools/apk-utils.js:333:20)
[W3C] at tryCatch (C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_babel-runtime@5.8.24@babel-runtime\regenerator\runtime.js:67:40)
[W3C] at GeneratorFunctionPrototype.invoke as _invoke
[W3C] at GeneratorFunctionPrototype.prototype.(anonymous function) as next
[W3C] at invoke (C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_babel-runtime@5.8.24@babel-runtime\regenerator\runtime.js:136:37)
[W3C] at enqueueResult (C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_babel-runtime@5.8.24@babel-runtime\regenerator\runtime.js:185:17)
[W3C] at new Promise ()
[W3C] at new F (C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_core-js@1.2.7@core-js\library\modules\$.export.js:30:36)
[W3C] at AsyncIterator.enqueue (C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_babel-runtime@5.8.24@babel-runtime\regenerator\runtime.js:184:12)
[W3C] at AsyncIterator.prototype.(anonymous function) as next
[W3C] at Object.runtime.async (C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_babel-runtime@5.8.24@babel-runtime\regenerator\runtime.js:209:12)
[W3C] at ADB.callee$0$0 as install
[W3C] at UiAutomator2Server.signAndInstall$ (../../lib/uiautomator2.js:109:20)
[W3C] at tryCatch (C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_babel-runtime@5.8.24@babel-runtime\regenerator\runtime.js:67:40)
[W3C] at GeneratorFunctionPrototype.invoke as _invoke
[W3C] at GeneratorFunctionPrototype.prototype.(anonymous function) as next
[W3C] at GeneratorFunctionPrototype.invoke (C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_babel-runtime@5.8.24@babel-runtime\regenerator\runtime.js:136:37)
[W3C] at
[HTTP] <-- POST /wd/hub/session 500 5971 ms - 1282

宣梦达 回复

自己复制出来日志 搜关键词 Error

[ADB] Error: zipAlignApk failed. Original error: Command 'C:\Android\android-sdk\build-tools\27.0.3\zipalign.exe -f 4 C:\Users\woxia\AppData\Roaming\npm\node_modules\appium\node_modules_appium-uiautomator2-driver\@0.11.0\@appium-uiautomator2-driver\uiautomator2\appium-uiautomator2-server-v0.3.0.apk C:\Users\woxia\AppData\Local\Temp\2018223-13176-1qe09sk.tno7\appium.tmp' exited with code 1. Stdout: ''; Stderr: ''
[ADB] at Object.wrappedLogger.errorAndThrow (../../lib/logging.js:78:13)

检查下你的 adb 也就是 android-sdk 配置

你的 appium 好像没有正常安装对,看下有这个么

@harsayer 大哥我加你 QQ 了 804181763 是我的 QQ

宣梦达 回复

大哥 我按着你这个思路获取不到 toast,可以请教你下吗,谢谢

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