【功能自动化】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)
相关推荐
你的秋裤穿反了17 分钟前
二. 和利时添加硬件
自动化
happymagic24 分钟前
vmware workstation Pro 虚拟机设定启停的时间段
运维·服务器·windows
一只鹿鹿鹿35 分钟前
三甲综合智慧医院信息化总体解决方案(PPT文件)
大数据·运维·物联网·安全·政务
AI的探索之旅43 分钟前
BOM管理的AI自动化:从原理图到采购清单,我搭了一套全自动工具链
运维·人工智能·自动化
Kina_C1 小时前
HAProxy 负载均衡实战:从安装配置到高级参数详解
linux·运维·负载均衡·haproxy
oh,huoyuyan2 小时前
跨境电商自动化运营工具推荐:火车采集器 & 火语言RPA
大数据·自动化·rpa
Tyfrank2 小时前
Linux内核收包路径及中断
linux·运维·单片机
淼澄研学3 小时前
Python自动化办公实操:基于pandas与requests的5个提效场景解析
python·自动化·pandas
阳光九叶草LXGZXJ3 小时前
达梦数据库-报错-11-cmd 13 validate error
linux·运维·数据库·sql·学习
~光~~3 小时前
【嵌入式linux学习_OV8858 bring up】L1_从Sensor到RK3588发生了什么
linux·运维·学习