【功能自动化】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)
相关推荐
梁正雄2 小时前
15、Docker swarm-2-安装与存储
运维·docker·容器
fyakm2 小时前
Linux文件搜索:grep、find命令实战应用(附案例)
linux·运维·服务器
wanhengidc4 小时前
云手机存在的意义是什么
运维·服务器·arm开发·安全·智能手机
snow@li5 小时前
运维:部署Jenkins
运维·jenkins
A~taoker6 小时前
扣子工作流——测试用例表格生成
功能测试·自动化
大海绵啤酒肚6 小时前
OpenStack虚拟化平台之T版搭建部署
linux·运维·云计算·openstack
The Chosen One9858 小时前
【Linux】Linux权限讲解 :写给文件的一封情书
linux·运维·服务器
测试199810 小时前
如何写出一个完整的测试用例?
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·接口测试
Thexhy10 小时前
在centos 7上配置FIP服务器的详细教程!!!
linux·运维·centos
FJW02081410 小时前
DevOps——CI/CD持续集成与持续交付/部署的理解与部署
运维·ci/cd·devops