标签:source for port login sim selenium 错误 集合 多个
原文链接:https://www.cnblogs.com/eastonliu/p/9141457.html
unittest是python内置的一个单元测试框架,在学习怎么使用它之前,我们先来了解它的一些概念和原理。
# coding = utf-8 import unittest import warnings from selenium import webdriver from time import sleep # 驱动文件路径 driverfile_path = r‘D:\coship\Test_Framework\drivers\IEDriverServer.exe‘ class CmsLoginTest(unittest.TestCase): def setUp(self): # 这行代码的作用是忽略一些告警打印 warnings.simplefilter("ignore", ResourceWarning) print("test start!") self.driver = webdriver.Ie(executable_path=driverfile_path) self.driver.get("http://172.21.13.83:28080/") def tearDown(self): self.driver.quit() print("test end!") def test_login1(self): ‘‘‘用户名、密码为空‘‘‘ self.driver.find_element_by_css_selector("#imageField").click() error_message1 = self.driver.find_element_by_css_selector("[for=‘loginName‘]").text error_message2 = self.driver.find_element_by_css_selector("[for=‘textfield‘]").text self.assertEqual(error_message1, ‘用户名不能为空‘) self.assertEqual(error_message2, ‘密码不能为空‘) print("用例test_login1执行结束") def test_login3(self): ‘‘‘用户名、密码正确‘‘‘ self.driver.find_element_by_css_selector("[name=‘admin.loginName‘]").send_keys("autotest") self.driver.find_element_by_css_selector("[name=‘admin.password‘]").send_keys("111111") self.driver.find_element_by_css_selector("#imageField").click() sleep(1) self.driver.switch_to.frame("topFrame") username = self.driver.find_element_by_css_selector("#nav_top>ul>li>a").text self.assertEqual(username,"autotest") print("用例test_login3执行结束") def test_login2(self): ‘‘‘用户名正确,密码错误‘‘‘ self.driver.find_element_by_css_selector("[name=‘admin.loginName‘]").send_keys("autotest") self.driver.find_element_by_css_selector("[name=‘admin.password‘]").send_keys("123456") self.driver.find_element_by_css_selector("#imageField").click() error_message = self.driver.find_element_by_css_selector(".errorMessage").text self.assertEqual(error_message, ‘密码错误,请重新输入!‘) print("用例test_login2执行结束") def login4(self): ‘‘‘用户名不存在‘‘‘ self.driver.find_element_by_css_selector("[name=‘admin.loginName‘]").send_keys("test007") self.driver.find_element_by_css_selector("[name=‘admin.password‘]").send_keys("123456") self.driver.find_element_by_css_selector("#imageField").click() error_message = self.driver.find_element_by_css_selector(".errorMessage").text self.assertEqual(error_message, ‘用户不存在!‘) print("用例login4执行结束") if __name__ == "__main__": unittest.main()
1)测试文件必须先import unittest
2)测试类必须继承unittest.TestCase
3)测试方法必须以“test_”开头
4)测试类必须要有unittest.main()方法
5)没有用例失败重跑功能
标签:source for port login sim selenium 错误 集合 多个
原文地址:https://www.cnblogs.com/lvchengda/p/13176446.html