3- 测试执行

下面我们看一个实例:

import unittest
from selenium import webdriver

class Baidu(unittest.TestCase):
    def setUp(self):
        self.driver=webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.implicitly_wait(30)
        self.driver.get("http://www.baidu.com")
    def tearDown(self):
        self.driver.quit()

    def test_baidu_title(self):
        "验证百度首页的title"
        self.assertEqual(self.driver.title,'百度一下,你就知道')
    def test_baidu_url(self):
        "验证百度首页的url"
        self.assertEqual(self.driver.current_url,"https://www.taobao.com")
if __name__ == '__main__':
    unittest.main()

打印结果为:

D:\Python3\python.exe D:/code/wuya/test.py
.F
======================================================================
FAIL: test_baidu_url (__main__.Baidu)
验证百度首页的url
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:/code/wuya/test.py", line 68, in test_baidu_url
    self.assertEqual(self.driver.current_url,"https://www.taobao.com")
AssertionError: 'https://www.baidu.com/' != 'https://www.taobao.com'
- https://www.baidu.com/
?               ^^^    -
+ https://www.taobao.com
?             +++  ^


----------------------------------------------------------------------
Ran 2 tests in 11.835s

FAILED (failures=1)

Process finished with exit code 1

 

posted @ 2019-08-22 22:11  WiltChamberlain  阅读(117)  评论(0编辑  收藏  举报