前两天, zhangmumu 同学开发了博客园 Android 版 APP:
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" 关键字。
效果如下:
最后,再次感谢 zhangmumu 开发的博客完 APP。
更多 Appium 教程来源: https://www.cnblogs.com/fnng/p/8185172.html