appium对博客园APP进行自动化测试
2019-12-17 11:08:34
http://www.cnblogs.com/zhangmumu/p/8146725.html
比官方的好用,官方的APP首页打开很慢。我刚好在用 appium,顺便对该APP写了个简单的自动化测试,供测试同学学习。
下载App 并安装到手机。
https://files.cnblogs.com/files/zhangmumu/cnblogs.apk
参考appium测试之获取appPackage和appActivity
最终,得到的APP信息如下:
通过 python + appium + unittest 编写appium自动化测试。
from appium import webdriver
from time import sleep
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.common.keys import Keys
import unittest
class SearchTest(unittest.TestCase):
def setUp(self):
desired_caps = {}
desired_caps['automationName'] = 'Appium'
desired_caps['deviceName'] = 'PRO_5'
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '7.0'
desired_caps['noReset'] = True
desired_caps["appPackage"] = "com.cnblogs.xamarinandroid"
desired_caps["appActivity"] = "md522127645c21675e531a6ac609ef72b2a.SplashScreenActivity"
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
sleep(5)
def test_case(self):
driver = self.driver
# 点击搜索按钮
driver.find_element_by_accessibility_id("搜索").click()
# 搜索框
search_src_text = driver.find_element_by_id("com.cnblogs.xamarinandroid:id/search_src_text")
search_src_text.click()
# 输入搜索关键字“appium”
driver.keyevent(29) # a
driver.keyevent(44) # p
driver.keyevent(44) # p
driver.keyevent(37) # i
driver.keyevent(49) # u
driver.keyevent(41) # m
sleep(1)
# 回车搜索
driver.keyevent(66)
driver.keyevent(66)
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
unittest.main()
操作步骤:打开 APP ,点击搜索按钮,搜索“appium”关键字。
效果如下:
扫描二维码分享到微信