python3 运行

mac2022-06-30  34

参考灰蓝大神  https://blog.csdn.net/huilan_same/article/details/76572481 文中的代码 if __name__=="__main__": report = Report_path+'/report.html' with open(report,'wb') as f: runer = HTMLTestRunner(f,verbosity=2,title='测试框架',description='修改HTMLTestRuner') runer.run(TestBaidu('test_search'))   unittest.main() case会跑两次,一次是通过runer.run()的方式,另一次是通过unittest.main()来跑。当用runner跑的时候case的结果是Error的。仔细检查后发现,在下面这段代码中: def test_search(self): datas = ExcelReader(self.excel).data for d in datas: with self.subTest(data=d): #self.sub_setUp() self.driver.find_element(*self.locator_kw).send_keys(d['search ']) self.driver.find_element(*self.locator_su).click() sleep(2) links = self.driver.find_elements(*self.locator_result) for link in links: logger.info(link.text) #self.sub_tearDown()   我的driver是定义为classmethod 的,如下: @classmethod def setUpClass(self): self.driver = webdriver.Chrome() self.driver.get(self.url) 如果只是跑unittest.main(). case运行前会先跑这一个方法。但是用runner跑,只会跑指定的case。故无法初始化driver.  

 

转载于:https://www.cnblogs.com/Q-lucia/p/9123060.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)