1. 程式人生 > >使用Appium操作YY語音例子

使用Appium操作YY語音例子

activit pytho mission 當前 erb 查看包名 click 啟動 abs

#!/usr/bin/env python 
# -*- coding: utf-8 -*-

import os
import unittest
from appium import webdriver
import time

# Returns abs path relative to this file and not cwd
PATH = lambda p: os.path.abspath(
    os.path.join(os.path.dirname(__file__), p)
)


class YY(unittest.TestCase):
    def setUp(self):
        desired_caps 
= { platformName: Android, deviceName: 611AKBPP22HR5, # adb devices查到的設備名 platformVersion: 4.4.2, appPackage: com.duowan.mobile, # 被測App的包名 appActivity: com.yy.mobile.ui.splash.SplashActivity,# 啟動時的Activity #
‘app‘:PATH(‘E:\yymobile_client-7.7.1.apk‘) } self.driver = webdriver.Remote(http://localhost:4723/wd/hub,desired_caps) def tearDown(self): self.driver.quit() def test_index_module(self): self.driver.wait_activity(com.yy.mobile.ui.home.MainActivity,30) el
= self.driver.find_element_by_name("小視頻") self.assertIsNotNone(el) el.click() time.sleep(3) yueBang = self.driver.find_element_by_name("一起玩") self.assertIsNotNone(yueBang) yueBang.click() if __name__ == __main__: # suite = unittest.TestLoader().loadTestsFromTestCase(YY) # unittest.TextTestRunner(verbosity=2).run(suite) unittest.main()

查看包名與啟動activity:推薦使用aapt工具,aapt是sdk自帶的一個工具,在sdk\build-tools目錄下

D:\Android\sdk\build-tools>aapt dump badging F:\ChromeDownloads\yymobile_client-7.7.1.apk
package: name=com.duowan.mobile versionCode=60513 versionName=7.7.1 platformBuildVersionName=6.0-2704002
sdkVersion:14
targetSdkVersion:22
uses-permission: name=android.permission.ACCESS_WIFI_STATE
......
launchable-activity: name=com.yy.mobile.ui.splash.SplashActivity  label=‘‘ icon=‘‘
......

查看當前activity:打開到對應的窗口後,執行命令 adb shell dumpsys window w |findstr \/ |findstr name=

D:\Android\sdk\build-tools>adb shell dumpsys window w |findstr \/ |findstr name=
      mSurface=Surface(name=com.duowan.mobile/com.yy.mobile.ui.home.MainActivity)

等待activity:driver.wait_activity,30s後超時

self.driver.wait_activity(com.yy.mobile.ui.home.MainActivity,30)

根據name定位元素

技術分享圖片

el = self.driver.find_element_by_name("小視頻")

使用Appium操作YY語音例子