#!/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(
"小视频")
***微信扫一扫,关注“python测试开发圈”,了解更多测试教程!***
转载于:https://www.cnblogs.com/guanfuchang/p/9118470.html