• 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"])
  • 相关阅读:
    【Unity编程】欧拉角与万向节死锁(图文版)
    关于ListView中getView被重复调用的问题
    svn 错误集锦续
    android 无法生成R文件的原因剖析
    SVN下错误集锦
    视频文件格式
    国内各视频网站android pad客户端支持分辨率情况初步统计
    android 下的网络图片加载
    遇到问题描述:Android Please ensure that adb is correctly located at问题解决
    android 时间控件概述
  • 原文地址:https://www.cnblogs.com/zhaoquanmo/p/10819718.html
Copyright © 2020-2023  润新知