注意:首先安装pycharm+python+git,这里不做解释,请自行百度解决
打开设置,配置pytest

配置github地址
https://github.com/LudvikWoo/guoya-pycharm-settings.git
https://github.com/xuepl/gy-pycharm-settings.git

新建一个pycharm项目-新建init.py文件
安装UI自动化的依赖包,文件输入:guoya_pip_ui
获取命令,命令行输入:pip3 install --upgrade guoya-ui


搭建UI自动化框架,获取目录文件

运行init.py

将下列的代码复制到conftest.py文件当中
from tools.os import os_tool
@pytest.fixture(scope='session')
def driver():
# 调用os_tool的get_root_path函数,获取当前项目下的驱动
driver = webdriver.Chrome(os_tool.get_root_path() + '/chrome_driver/chromedriver.exe')
# 最大化浏览器
driver.maximize_window()
# 隐性等待,超过8s报错提示超时
driver.implicitly_wait(8)
# 返回给调用者
yield driver
# 关闭浏览器以及后台程序
driver.quit()
新建测试case,将下列代码复制进去,验证是否能执行
from time import sleep
def test_baidu(driver):
driver.get('http://ui.yansl.com')
sleep(1)
# 点击表单元素
driver.find_element_by_xpath("//div[contains(text(),'表单元素(53)')]").click()
sleep(1)
# 点击输入框
driver.find_element_by_xpath("//li[contains(text(),'输入框(7)')]").click()
sleep(1)
# 定位文本输入框,输入 雷阳洪
driver.find_element_by_xpath("(//div[@class='el-form-item__content'])[3]/textarea").send_keys("雷阳洪")
sleep(1)
执行成功

网友评论