zoukankan      html  css  js  c++  java
  • appium对博客园APP进行自动化测试

    下载与安装

    下载App 并安装到手机。
    https://files.cnblogs.com/files/zhangmumu/cnblogs.apk

    获取appPackage和appActivity

    参考appium测试之获取appPackage和appActivity

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

    • appPackage:com.cnblogs.xamarinandroid
    • appActivity:md522127645c21675e531a6ac609ef72b2a.SplashScreenActivity

    定位控件

    参考,Appium-desktop安装与使用

    编写测试脚本

    通过 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。

  • 相关阅读:
    7
    go http请求库HttpRequest
    Golang设计模式
    深挖 go 之 for-range 排坑指南
    go在并发情况下使用map
    Redis知识点总结
    go 条件与循环结构
    数据分析的数据源
    go 生产者消费者模型与发布订阅模型
    go 文件与目录操作
  • 原文地址:https://www.cnblogs.com/y666/p/8490012.html
Copyright © 2011-2022 走看看