使用yaml实现selenium的po
Project description
Selenium的PO模型封装
使用Yaml
文件进行元素信息的管理
安装
$ pip install selenium-po
使用方法
创建一份yaml
代码中使用的是name
后的内容,实际页面元素定位使用的value
中的内容,方便后续统一维护
pages:
- page:
pageName: index
desc: 首页
locators:
- {desc: "搜索栏",type: "id",value: "kw",timeout: 3, name: "index_input"}
- {desc: "查询按钮",type: "id",value: "su",timeout: 3, name: "index_search"}
- page:
pageName: news
desc: 新闻
locators:
- {desc: "搜索栏",type: "id",value: "ww",timeout: 3, name: "news_input"}
- {desc: "查询按钮",type: "id",value: "s_btn_wr",timeout: 3, name: "news_search"}
创建一个页面操作对象
import os
import time
from selenium_po.elementoperator import ElementOperator
path = os.path.dirname(os.path.abspath(__file__))
class BaiDuIndexAction(ElementOperator):
def __init__(self, path=f"{path}/pages.yaml", file_name='index', driver=None):
super(BaiDuIndexAction, self).__init__(path, file_name, driver)
self.url = 'http://www.baidu.com'
测试
if __name__ == '__main__':
baidu = BaiDuIndexAction()
baidu.open(baidu.url, baidu.index_input)
baidu.input(baidu.index_input, "python")
baidu.click(baidu.index_search)
time.sleep(2)
baidu.screenshot_pic("1.png")
baidu.close()
输出
往「首页_搜索栏」输入「python」
点击「首页_查询按钮」
截图
公众号:「测试游记」
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
selenium-po-0.0.2.tar.gz
(4.9 kB
view hashes)
Built Distribution
selenium_po-0.0.2-py3.8.egg
(9.3 kB
view hashes)