标签:div 直接 param chrome arch src 自动化测试 baidu web自动化测试
#参数化库: parameterized
前提:先安装patameterized库 >>>python -m pip install parameterized
from selenium import webdriver
import unittest
from time import sleep
from parameterized import parameterized
class TestSearch(unittest.TestCase):
@classmethod #基于类级别只开启一次浏览器,执行当前目录下所有用例
def setUpClass(cls):
cls.dr = webdriver.Chrome()
cls.base_url = ‘https://www.baidu.com‘
@classmethod
def tearDownClass(cls):
cls.dr.quit()
@parameterized.expand([
(‘case1‘,‘selenium‘,‘selenium_百度搜索‘),
(‘case2‘,‘python‘,‘python_百度搜索‘),
(‘case3‘,‘unittest‘,‘unittest_百度搜索‘)
])
def test_search(self,name,searchkeys,assertResult):
dr = self.dr
dr.get(self.base_url)
dr.find_element_by_id("kw").send_keys(searchkeys)
dr.find_element_by_id("su").click()
sleep(3)
self.assertEqual(self.dr.title,assertResult)
@unittest.skip("直接跳过")
def test_selenium(self):
self.baidu_search("selenium")
self.assertEqual(self.dr.title,"selenium_百度搜索")
@unittest.skip("直接跳过")
def test_python(self):
self.baidu_search("python")
self.assertEqual(self.dr.title,"python_百度搜索")
if __name__ == "__main__":
unittest.main(verbosity=2) #打印日志级别
执行结果:
unittest_使用参数化web自动化测试_parameterized
标签:div 直接 param chrome arch src 自动化测试 baidu web自动化测试
原文地址:https://www.cnblogs.com/xlzhangq/p/13199401.html