zoukankan      html  css  js  c++  java
  • appium+python手机app自动化测试配置和测试代码示例

    前提是配置好了adb环境变量(安卓),安装了python

    1. 安装appium server

    下载地址  :    http://appium.io/

    2. 安装appium client和selenium

    在cmd中输入 pip install selenium   

                          pip install Appium-Python-Client

    如果出现retrying问题, 使用带pip源的命令,如   

    pip install selenium -i https://pypi.tuna.tsinghua.edu.cn/simple/

    pip install Appium-Python-Client -i https://pypi.mirrors.ustc.edu.cn/simple/

    3. 编写脚本, 代码中需要包含对appium server的设置, 可以根据实际需要增/删设置项, 如

    
    
    # -*- coding: utf-8 -*-
    from appium import webdriver
    from time import sleep
    
    CAPS = {
        "deviceName": " MEIZU_E3",
        "platformName": "Android",
        "platformVersion": "7.1.1",
        #'app' = 'E:/autotestingPro/app/UCliulanqi_701.apk'  #指向.apk文件,如果设置appPackage和appActivity,那么这项会被忽略
        "appPackage": " com.meizu.flyme.flymebbs",
        "appActivity": ".ui.LoadingActivity",
        #"noReset": True,  
    }
    
    driver = webdriver.Remote('http://localhost:4723/wd/hub', CAPS)
    sleep(3)

    4. 打开appium server, 设置主机为 127.0.0.1,设置端口为 4723, 启动server

    5. 连接手机,安装应用,运行脚本。完整测试脚本如下例(用Unittest):

    # coding: utf-8
    import
    unittest from appium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By desired_caps = {'platformName': 'Android', 'platformVersion': '5.1.1', 'deviceName': 'MEIZU_E3', #设备名来自adb devices "appPackage": " com.meizu.flyme.flymebbs", "appActivity": ".ui.LoadingActivity",} appium_server = 'http://localhost:4723/wd/hub' class LearnAppiumTest(unittest.TestCase): def setUp(self): self.driver = webdriver.Remote(appium_server, desired_caps) def tearDown(self): self.driver.quit() def test_01(self): text_view = self.driver.find_element_by_id("text_view") assert text_view.text == 'Hello World! Hello World!' # 测试应该不通过 def test_02(self): wait = WebDriverWait(self.driver, 6) wait.until(EC.element_to_be_clickable((By.ID, 'button'))) button = self.driver.find_element_by_id("button") button.click() wait = WebDriverWait(self.driver, 6) wait.until(EC.presence_of_element_located((By.ID, 'text_view'))) text_view = self.driver.find_element_by_id("text_view") assert text_view.text == '3' # 测试应该通过 if __name__ == '__main__': unittest.main()
  • 相关阅读:
    element_2对话框
    填报
    润乾报表中进度条的一种实现方式
    列名作为分类值时如何画出统计图
    填报之动态扩展列
    自由格式填报的制作
    复杂报表设计之动态报表
    如何通过动态参数实现周报制作
    如何实现行列互换效果?
    大数据集报表点击表头排序
  • 原文地址:https://www.cnblogs.com/zpf1092841490/p/11600055.html
Copyright © 2011-2022 走看看