zoukankan      html  css  js  c++  java
  • appium页面元素封装(十一)

    1、首先封装一个基类

    """
    appium的二次封装
    """
    from selenium.webdriver.support.wait import WebDriverWait
    
    class Base:
        # 初始化
        def __init__(self, driver):
            self.driver = driver
    
        # 获取单个元素
        def find_element(self, loc, timeout=10, poll=0.5):
            """
            :param loc: 定位方式+属性值,类似(By.XPATH,"xpath语句") (By.ID, "id属性值")
            :param timeout: 等待时间
            :param poll: 请求间隔
            """
            return WebDriverWait(self.driver, timeout, poll).until(lambda x: x.find_element(*loc))
        
        # 获取一组元素
        def find_elements(self, loc, timeout=10, poll=0.5):
            """
            :param loc: 定位方式+属性值,类似(By.XPATH,"xpath语句") (By.ID, "id属性值")
            :param timeout: 等待时间
            :param poll: 请求间隔
            """
            return WebDriverWait(self.driver, timeout, poll).until(lambda x: x.find_element(*loc))
    
        # 点击
        def click_element(self, loc):
            # 元组类型 (By.XPATH,"xpath语句") (By.ID, "id属性值")
            self.find_element(loc).click()
    
        # 输入
        def input_element(self, loc, text):
            """
            :param text: 输入内容
            """
            self.find_element(loc).send_keys(text)

    2、调用基类来使用

    from selenium.webdriver.common.by import By
    from init_driver.Init_driver import init_driver
    from Base.base import Base
    import pytest
    
    class Test_search:
        def setup(self):
            # 实例化driver类
            self.driver = init_driver()
            # 实例化base类
            self.base_obj = Base(self.driver)
    
        def teardown(self):
            self.driver.quit()
    
        def test_001(self):
            # 搜索按钮
            search_b = (By.ID, "com.android.settings:id/search")
            # 输入框
            input_t = (By.CLASS_NAME, "android.widget.EditText")
            # 点击搜索按钮
            self.base_obj.click_element(search_b)
            # 输入内容
            self.base_obj.input_element(input_t, "123你好")
    
    if __name__ == '__main__':
        pytest.main(["-s", "test_13.py", "--html=../report/report.html"])
  • 相关阅读:
    MySQL数据库学习笔记(八)----JDBC入门及简单增删改数据库的操作
    vim使用技巧大全
    virtualbox下centos虚拟机安装增强工具教程和常见错误解决
    python初始化list列表(1维、2维)
    Python中列表(list)、字典(dict)排序的程序
    字符画
    php 过滤器filter_var验证邮箱/url/ip等
    Python3 MySQL 数据库连接
    PHP socket 服务器框架集
    python3 获取int最大值
  • 原文地址:https://www.cnblogs.com/zhaoquanmo/p/10819718.html
Copyright © 2011-2022 走看看