import unittest
from Report import HTMLTestRunner
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class TestCase01(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.driver = webdriver.Chrome()
cls.driver.implicitly_wait(10)
@classmethod
def tearDownClass(cls):
cls.driver.quit()
def test_case_01(self):
self.driver.get('https://www.baidu.com/')
title = self.driver.title
self.assertEqual(title, '百度一下,你就知道')
def test_case_02(self):
self.driver.get('https://www.hao123.com/')
title = self.driver.title
self.assertEqual(title, 'hao123 上网从这里开始')
def test_case_03(self):
self.driver.get('https://pythonav.com/login/')
self.driver.find_element_by_id('id_username').send_keys('亚洲')
self.driver.find_element_by_id('id_password').send_keys('喜欢bao哥')
code = self.driver.find_element_by_id('id_code')
code.send_keys('abc', Keys.ENTER)
msg = self.driver.find_element_by_xpath('//*[@id="fm"]/div[3]/div/div[1]/span').text
if '验证码错误,请重新输入。' == msg:
# self.driver.save_screenshot('error.png')
self.assertFalse('验证码错误,请重新输入。')
if __name__ == '__main__':
suite = unittest.makeSuite(TestCase01)
f = open('report.html', 'wb')
HTMLTestRunner(
stream=f,
verbosity=2,
title='百度首页测试报告',
description='判断title是否符合预期',
tester='张开'
).run(suite)