首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

用Appium对博客园APP进行自动化测试

前两天,zhangmumu 同学开发了博客园Android 版APP:

http://www.cnblogs.com/zhangmumu/p/8146725.html

比官方的好用,官方的APP首页打开很慢。我刚好在用 appium,顺便对该APP写了个简单的自动化测试,供测试同学学习。

下载与安装

下载App 并安装到手机。

https://files.cnblogs.com/files/zhangmumu/cnblogs.apk

获取appPackage和appActivity

参考

http://www.cnblogs.com/fnng/p/7350900.html

最终,得到的APP信息如下:

appPackage:

appActivity:

md522127645c21675e531a6ac609ef72b2a.SplashScreenActivity

定位控件

参考

http://www.cnblogs.com/fnng/category/695788.html

编写测试脚本

通过 python + appium + unittest 编写appium自动化测试。

from appium import webdriver

from time import sleep

from appium.webdriver.common.touch_action import TouchAction

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.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):

if __name__ == '__main__':

unittest.main()

操作步骤:打开 APP ,点击搜索按钮,搜索“appium”关键字。

效果如下:

最后,再次感谢 zhangmumu 开发的博客完APP。

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20190214B0XA1S00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券