标签:loader from ext https __file__ lte url enable elf
现有四个测试用例分别在两个.py文件中,如何执行这些文件?
unittest中有这样处理:unittest.TestLoader().discover()
第一个文件test_case1.py
from selenium import webdriver import unittest class Baidu_Link(unittest.TestCase): def setUp(self) -> None: self.driver = webdriver.Chrome() self.driver.get("http://www.baidu.com/") def tearDown(self) -> None: self.driver.quit() def test_baidu_news(self): ‘‘‘‘点击百度首页的新闻,看是否可以正常跳转‘‘‘ self.driver.find_element_by_link_text("新闻").click() self.assertEqual(self.driver.current_url, "http://news.baidu.com/") def test_baidu_map(self): ‘‘‘点击百度首页的地图,看是否可以正常跳转‘‘‘ self.driver.find_element_by_link_text("地图").click() self.assertEqual(self.driver.current_url, "https://map.baidu.com/@13225221.26,3748918.53,12z") if __name__ == "__main__": unittest.main(verbosity=2)
第二个.py文件:test_case2.py
import unittest from selenium import webdriver class Baidu_search(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get("http://www.baidu.com") def tearDown(self): self.driver.quit() def test_baidu_enbale(self): ‘‘‘测试百度首页的输入框可编辑‘‘‘ su = self.driver.find_element_by_id("kw") self.assertTrue(su.is_enabled()) def test_baidu_search(self): ‘‘‘测试百度首页的输入框可以搜索‘‘‘ search = self.driver.find_element_by_id("kw") search.send_keys("大数据") self.driver.find_element_by_id("su").click() self.assertEqual(search.get_attribute("value"), "大数据") if __name__ == "__main__": unittest.main(verbosity=2)
这两个文件怎么批量执行?
建立新的.py文件alltest.py
import unittest
import os
def allTest():
suite = unittest.TestLoader().discover(
start_dir=os.path.dirname(__file__),#文件地址
pattern="test_*.py",#文件类型
top_level_dir=None)
return suite
def run():
unittest.TextTestRunner(verbosity=2).run(allTest())
if __name__ == "__main__":
run()
执行结果:
test_baidu_map (test_case1.Baidu_Link) 点击百度首页的地图,看是否可以正常跳转 ... ok test_baidu_news (test_case1.Baidu_Link) ‘点击百度首页的新闻,看是否可以正常跳转 ... ok test_baidu_enbale (test_case2.Baidu_search) 测试百度首页的输入框可编辑 ... ok test_baidu_search (test_case2.Baidu_search) 测试百度首页的输入框可以搜索 ... ok ---------------------------------------------------------------------- Ran 4 tests in 40.277s OK
标签:loader from ext https __file__ lte url enable elf
原文地址:https://www.cnblogs.com/1510152012huang/p/10691576.html