设为首页 加入收藏

TOP

Pytest-selenium简单使用示例
2019-06-05 02:08:05 】 浏览:126
Tags:Pytest-selenium 简单 使用 示例

Pytest-selenium是Pytest的一个插件, 安装方法:


pip3 install pytest pytest-selenium


然后在运行时指定通过--driver指定浏览器即可:
pytest test_baidu.py --driver Chrome


需要提前配置好selenium环境及chromedriver


下面是一个Django后台添加课程的简单使用示例:
# test_add_course.py
import pytest
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.expected_conditions import presence_of_element_located as element_exist



def test_add_course(selenium, login, del_course):  # 通过参数使用fixtures方法login及del_course
    selenium.find_element_by_link_text("Courses").click()  # 点击'Courses'链接
    selenium.find_element_by_class_name("addlink").click()  # 点击'新增 COURSE'按钮
    Select(selenium.find_element_by_id("id_owner")).select_by_visible_text("hanzhichao")  # 选择作者
    Select(selenium.find_element_by_id("id_subject")).select_by_visible_text("接口测试")  # 选择主题
    selenium.find_element_by_id("id_title").send_keys("Python接口测试教程")  # 输入文章标题
    selenium.find_element_by_id("id_overview").send_keys("作者:临渊")  # 输入描述
    selenium.find_element_by_class_name("default").click()  # 点击保存
    assert element_exist(("link text", "Python接口测试教程"))  # 断言返回的页面存在标题名的链接


运行方法:
pytest test_add_course.py --driver Chrome


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇剑指offer中数据结构与算法部分笔.. 下一篇Python语法基础之初始化函数和类..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目