【功能自动化】WebTours:使用unittest编写注册测试用例

环境搭建:

需要配置WebTours网站

代码实现:

python 复制代码
# 导入包
from selenium import webdriver
from selenium.webdriver.support.select import Select
from time import sleep
import unittest

driver = None
class Reg(unittest.TestCase):
    
    @classmethod
    def setUpClass(cls):
        global driver
        driver = webdriver.Chrome()
    
    @classmethod
    def tearDownClass(cls):
        driver.quit()
        
    def setUp(self):
        print("test function")
    
    def tearDown(self):
        print("function over")
    
    def testOpenWeb(self):
        driver.get("http://127.0.0.1:1080/WebTours/")
        # 等待3秒
        sleep(3)
    
    def testRegister(self):
        driver.switch_to.default_content()
        driver.switch_to.frame("body")
        driver.switch_to.frame("info")

        driver.find_element_by_link_text("sign up now").click()

        sleep(3)
        # 跳转页面,还是需要切换框架
        driver.switch_to.default_content()
        driver.switch_to.frame("body")
        driver.switch_to.frame("info")

        driver.find_element_by_name("username").send_keys("test")
        driver.find_element_by_name("password").send_keys('123456')
        driver.find_element_by_name("passwordConfirm").send_keys('123456')
        driver.find_element_by_name("register").click()
        sleep(3)

if __name__=="__main__":
    # verbosity=2 显示详细信息,可以省略,测试信息不详细
    unittest.main(verbosity=2)
相关推荐
2302_8057710710 小时前
Day20:实战:接口自动化测试框架封装之一------接口关联封装
功能测试·自动化·测试用例
祖力5510 小时前
Linux系统移植、烧录与环境的搭建
linux·运维·服务器
对讲机数码科普10 小时前
从电路原理到协议栈:模拟对讲机与数字对讲机的技术内核拆解
运维·网络·架构·软件工程
打工仔折腾 AI10 小时前
极空间用 Docker 部署 Photopea:网页版 PS 的私有化实践
运维·后端·python·docker·容器·langchain·ai agent 实战
工具人555510 小时前
Docker 最新超详细版教程
运维·docker·容器
我送炭你添花10 小时前
ASA原理与电子维修实战:前言 一路修来,一路学习
运维·网络·学习
张小姐的猫10 小时前
【Linux】网络编程 —— 多路转接:epoll
linux·运维·网络
木卫二号Coding11 小时前
第八十六篇-Strata 部署指南(Ubuntu 22.04 + Tesla V100【单卡】)
linux·运维·人工智能·ubuntu
linweidong12 小时前
Redis 集群故障排查与修复实战:从 Connection refused 到内存打满的七个现场
运维·数据库·redis·缓存·redis集群·运维面经·实施面经