Appium+Python 安卓APP自动化测试:环境搭建与基础操作

环境配置

Appium环境搭建超详细教程:https://zhuanlan.zhihu.com/p/49193525

AppiumDesktop控制手机和安卓模拟器:https://zhuanlan.zhihu.com/p/49428952

自动化测试

import time
import unittest
from appium import webdriver

class LoginAndroidTests(unittest.TestCase):
    def setUp(self):
        # 初始化测试平台
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '7.1.2'
        desired_caps['deviceName'] = 'Nexus'
        desired_caps['appPackage'] = 'com.***.***'
desired_caps['appActivity'] = '.***.***'
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) self.driver.implicitly_wait(10) def tearDown(self): self.driver.quit() def testLogin(self): self.driver.find_element_by_id('***').send_keys('***') # 输入账号
self.driver.find_element_by_id('***').send_keys('***') # 输入密码
self.driver.find_element_by_id('***').click() # 登录
time.sleep(3) # 等待欢迎页面跳过 name = self.driver.find_element_by_id('***').text
self.assertEqual("***",name) if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromTestCase(LoginAndroidTests) unittest.TextTestRunner(verbosity=2).run(suite)
原文地址:https://www.cnblogs.com/nicole-zhang/p/14631791.html