美文网首页
1、unittest运行报错

1、unittest运行报错

作者: 阿飞丫 | 来源:发表于2019-12-29 22:56 被阅读0次
image.png

1、出错代码

from selenium import webdriver
import unittest
import time


class YoudaoTest(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.implicitly_wait(30)  # 隐性等待时间为30秒
        self.base_url = "http://www.youdao.com"

    def test_youdao(self):
        driver = self.driver
        driver.get(self.base_url + "/")
        driver.find_element_by_id("translateContent").clear()
        driver.find_element_by_id("translateContent").send_keys(u"你好")
        driver.find_element_by_id("translateContent").submit()
        time.sleep(3)
        page_source = driver.page_source
        self.assertIn("hello", page_source)
        print("youdao ok")
        
    def tearDown(self):
        self.driver.quit()

if __name__ == "__main__":
    unittest.main(verbosity=2)

2、以下代码不会报错

def setUp(self):
    self.driver = webdriver.Chrome()
    self.driver.implicitly_wait(30)  # 隐性等待时间为30秒

if __name__=='__main__':
    # #执行测试
    # runner = unittest.TextTestRunner()
    # runner.run(discover)
    suite = unittest.TestSuite()# 1\构造用例集
    suite.addTest(BaiduTest("test_baidu"))  # 2、执行顺序是安加载顺序
    suite.addTest(YoudaoTest("test_youdao"))
    #suite.addTest(UC7TestCase("testDeleteFolder"))
    # 执行测试
    runner = unittest.TextTestRunner()# #3、实例化runner类
    runner.run(suite) # 4、执行测试

def tearDown(self):
    self.driver.quit()

相关文章

网友评论

      本文标题:1、unittest运行报错

      本文链接:https://www.haomeiwen.com/subject/kqiuoctx.html