1.新增元素染色功能,在本地调试执行时可以精确地看到操作了什么元素

2.新增访问百度的demo供参考
This commit is contained in:
caiweichao 2022-09-07 10:31:45 +08:00
parent 6e27ada1df
commit 73cfa5c0ec
6 changed files with 74 additions and 3 deletions

View File

@ -93,7 +93,6 @@ class BasicPage:
"""
self.driver.execute_script("arguments[0].setAttribute('style', 'background: yellow; border: 2px solid red;');",
element)
def __wait_element_visible(self, model: str, locator: tuple) -> None:
"""
等待元素可见

12
PageObject/elements.py Normal file
View File

@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
# @Author : caiweichao
# @explain : 项目元素选择器
from selenium.webdriver.common.by import By as by
class PageBaidu:
url = "https://www.baidu.com/"
# 百度搜索内如输入框
input = (by.XPATH, '//input[@id="kw"]')
# baidu一下
baiduButton = (by.XPATH, '//input[@id="su"]')

24
PageObject/page_baidu.py Normal file
View File

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# @Author : caiweichao
# @explain : 文件说明
from Commons.ui_auto.basic_page import BasicPage
from PageObject import elements
import allure
class PageBaidu(BasicPage):
# 实例化的百度定位元素
ele_baidu = elements.PageBaidu()
@allure.step("访问百度页面")
def get_baidu(self):
self.get_url(url=self.ele_baidu.url)
@allure.step("输入需要查询的关键字")
def input_keyword(self, keyword):
self.input_text(locator=self.ele_baidu.input, content=keyword)
@allure.step("点击百度一下")
def click_baidu_button(self):
self.click_element(locator=self.ele_baidu.baiduButton)

View File

@ -37,6 +37,9 @@
1. 接口自动化支持多关键字校验按照下图在excel中维护用例写一个参数就换行
2. Commons/api_auto/assert_method.py 支持接口多字段校验
1. [![Xj28pV.jpg](https://s1.ax1x.com/2022/06/19/Xj28pV.jpg)](https://imgtu.com/i/Xj28pV)
- 20220907
1. 新增ui自动化demo
2. 新增元素染色功能
3. [![vHJmjS.jpg](https://s1.ax1x.com/2022/09/07/vHJmjS.jpg)](https://imgse.com/i/vHJmjS)

View File

@ -54,7 +54,13 @@ def get_drvier(model=None):
return driver
@pytest.fixture(scope='session')
@pytest.fixture()
def global_step():
_driver = get_drvier()
yield _driver
@pytest.fixture()
def kill_driver():
yield None
driver.close()

27
TestCase/test_demo.py Normal file
View File

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# @Author : caiweichao
# @explain : ui自动化demo
import time
from PageObject.page_baidu import PageBaidu
import pytest
import allure
# 使用打开浏览器的测试夹具会自动识别chrome浏览器版本并且安装对应的driver
@pytest.mark.usefixtures("global_step")
@pytest.mark.usefixtures("kill_driver")
@allure.feature('访问百度demo')
class TestDemo:
def test_baidu_demo1(self, global_step):
PageBaidu(global_step).get_baidu()
PageBaidu(global_step).input_keyword(keyword="getee")
PageBaidu(global_step).click_baidu_button()
time.sleep(3)
def test_baidu_demo2(self, global_step):
PageBaidu(global_step).get_baidu()
PageBaidu(global_step).input_keyword(keyword="github")
PageBaidu(global_step).click_baidu_button()
time.sleep(3)