appium+Python+Android 自动化测试实例

时间:2021-09-11 06:01:28
前提是已经安装python 1.安装easy_install python ez_setup.py 将D:\Program Files\python2.7\scripts添加到环境变量中 在附件中也有 ez_setup.py地址: http://peak.telecommunity.com/dist/ez_setup.py 2.安装python 依赖 easy_install nose(安装 nose) easy_install selenium(安装 selenium) easy_install Appium-Python-Client(安装 Appium-Python-Client)

3.desired_caps获取
  • 环境变量设置(根据个人实际目录配置)
ANDROID_HOME D:\adt-bundle-windows-x86_64-20140702\sdk path D:\adt-bundle-windows-x86_64-20140702\sdk\platform-tools; D:\adt-bundle-windows-x86_64-20140702\sdk\build-tools; %ANDROID_HOME%\tools;
  • 查看设备名称
adb devices 需要打开开发者选项中的USB调试 小米手机:关于手机-MIUI版本,连续点击多次(7次)-返回设置-更多设置-开发者选项-USB调试
  • package和activity的查看
   查看D:\adt-bundle-windows-x86_64-20140702\sdk\tools是否有aapt.exe 如果没有下载地址 http://dldx.csdn.net/fd.php?i=542658417878245&s=c1161d402ae860253c1af36a0fd1d39e 放到D:\adt-bundle-windows-x86_64-20140702\sdk\tools中 dos命令行中切换到aapt.exe目录执行(已经配置环境变量可以不切换目录):    aapt dump badging E:\apk\es3.apk   运行后的结果中以下两行分别是应用包名package和入口activity名称 package: name=’com.estrongs.android.pop’ launchable-activity: name=’com.estrongs.android.pop.view.FileExplorerActivity’ appium+Python+Android 自动化测试实例
launchable-activity在中间位置 appium+Python+Android 自动化测试实例

4.实例 importos importunittest fromappium importwebdriver fromtime importsleep
# Returns abs path relative to this file and not cwd PATH =lambdap: os.path.abspath( os.path.join(os.path.dirname(__file__), p) )
classContactsAndroidTests(unittest.TestCase): defsetUp(self): desired_caps = {} desired_caps['platformName'] = 'Android' desired_caps['platformVersion'] = '6.0' desired_caps['deviceName'] = 'HISSC6FA9LXXXXXXX' desired_caps['app'] = PATH('D:/workspace/testUI_new/app/test.apk') desired_caps['appPackage'] = 'com.xxx.xx' desired_caps['appActivity'] = 'com.xxx.xx.xxx'
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
deftearDown(self): self.driver.quit()
deftest_add_contacts(self):
sleep(2) self.driver.find_element_by_id("com.xxx.xx:id/dot_001").click() self.driver.find_element_by_id("com.xxx.xx:id/newguide_01_002").click()
if__name__ =='__main__': suite = unittest.TestLoader().loadTestsFromTestCase(ContactsAndroidTests) unittest.TextTestRunner(verbosity=2).run(suite)

5.元素定位 android sdk tool所在目录  双击uiautomatorviewer.bat 
id 、content-desc、class都可以使用 appium+Python+Android 自动化测试实例