当前位置: 首页 > news >正文

基于python的一个元素多种定位方式

基于 Python 的 Page Factory 设计模式测试库, 类似于Java的Page Factory模式,旨在减少代码冗余,简单易用,具有高度的可扩展能力。

支持以@annotation的方式定义元素
支持同一个元素多种定位方式
支持动态的定位方式

安装

pip install pythium

用法

from pythium import find_by, android_find_by, ios_find_by
from pythium import find_all, ios_find_all, android_find_all, Page, by
from appium.webdriver.webelement import WebElement as MobileElement
from selenium.webdriver.remote.webelement import WebElement
from typing import Any, List


class LoginPage(Page):

    @find_by(css=".search")
    @ios_find_by(ios_predicate='value == "Search something"')
    @android_find_by(android_uiautomator='resourceId("com.app:id/search_txtbox")')
    def search_input(self) -> WebElement: ...

    @property
    @find_by(css=".search")
    @ios_find_by(ios_predicate='value == "Search something"')
    @android_find_by(android_uiautomator='resourceId("com.app:id/search_txtbox")')
    def search_input_with_property(self) -> WebElement: ...

    @property
    @find_all(by(css=".icon-logo1"), by(css=".icon-logo"))
    def find_all_web_test(self) -> WebElement: return Any

    @property
    @ios_find_all(by(ios_predicate='value == "Search something"'), by(ios_predicate='value == "Search result"'))
    @android_find_all(by(android_uiautomator='resourceId("com.app:id/search_txtbox")'), by(android_uiautomator='resourceId("com.app:id/search_txtbox")'))
    def find_all_mobile_test(self) -> WebElement: return Any

    # for dynamical locator
    @find_by(xpath="//div[{n}]/a[{k}]/div[{m}]/{f}")
    @ios_find_by(xpath="//div[1]/a[{n}]/div[{k}]")
    def dynamical_locator(self, n, k, m=4, f=6) -> WebElement: ...

    # for list WebElements
    @find_by(css=".login")
    def list_web_elements(self) -> List[MobileElement]: ...```

    def _is_loaded(self):
        print("implement something...")

if __name__ == '__main__':
    from selenium import webdriver
    driver = webdriver.Chrome()
    login = LoginPage(driver)
    # no @property
    login.search_input.click()
    # with @property
    login.search_input_with_property.click()
    # for dynamical locator
    login.dynamical_locator(2, 3, 4, 5).click()
    # for list WebElement
    print(len(login.list_web_elements()))

find_all, ios_find_all, android_find_all 使用多个定位元素,元素之间为or的关系,按顺序查找

例子: @find_all(by(css=".icon-logo1"), by(id="icon"))
首先查找元素 by(css=".icon-logo1"), 如果找到则返回 WebElement;
如果没找到则通过 by(id="icon")继续找, 如果找到则返回WebElement, 最后没找到则抛出异常 Exception.
 

http://www.lryc.cn/news/112570.html

相关文章:

  • Fastdfs集群搭建
  • 【深度学习】Vision Transformer论文,ViT的一些见解《 一幅图像抵得上16x16个词:用于大规模图像识别的Transformer模型》
  • 在centos7上使用非编译方式安装ffmpeg
  • 【微信小程序】导出Excel文件
  • 接口测试—知识速查(Postman)
  • 机器学习深度学习——序列模型(NLP启动!)
  • 小白到运维工程师自学之路 第六十四集 (dockerfile构建tomcat、mysql、lnmp、redis镜像)
  • 超低功耗水表电器表LCD驱动显示芯片,高抗干扰性能提供LQFP48、LQFP64的封装
  • SpringBoot3---核心特性---2、Web开发III(模板引擎、国际化、错误处理)
  • MemFire教程|FastAPI+MemFire Cloud+LangChain开发ChatGPT应用-Part2
  • C# File.Exists与Directory.Exists用法
  • (深度学习,自监督、半监督、无监督!!!)神经网络修改网络结构如何下手???
  • Codejock Task Panel ActiveX Crack
  • LeetCode 热题 100 JavaScript--141. 环形链表
  • 文字转语音
  • 让ELK在同一个docker网络下通过名字直接访问
  • EventBus 开源库学习(一)
  • 车载以太网SOME/IP的个人总结
  • vue2.29-Vue3跟vue2的区别
  • 【深度学习】分类和分割常见损失函数
  • Redhat Linux 安装MySQL安装手册
  • 题目:2303.计算应缴税款总额
  • Kotlin 1.9.0 发布:带来多项新特性,改进 Multiplatform/Native 支持
  • 接口测试——认知(一)
  • 剑指 Offer 10- I. 斐波那契数列
  • 洪水填充算法详解
  • ubuntu18.04安装docker及docker基本命令的使用
  • DataWhale 机器学习夏令营第二期——AI量化模型预测挑战赛 学习记录
  • 简单认识ELK日志分析系统
  • 【算法笔记】深度优先遍历-解决排列组合问题-