第一个python脚本(含有断言)

#描述:通过百度搜索selenium。来练习unittest的

import time
import unittest
from selenium import webdriver
 
class BaiduSearch(unittest.TestCase):
	def setUp(self):
		'''
		测试固件的开头
		'''
	
		self.driver = webdriver.Chrome('D:/path/python3.6.8/chromedriver.exe')
		self.driver.maximize_window()
		time.sleep(2)
		self.driver.get('http://www.baidu.com')
		time.sleep(3)
	def tearDown(self):
		self.driver.quit()
		
	def test_baidu_search(self):
		self.driver.find_element_by_id('kw').send_keys('selenium')
		time.sleep(3)
		try:
			assert 'selenium' in self.driver.title
			print('test_pass!!')
		except Exception as e:
			print('test_fail!!',format(e))
			
if __name__ == '__main__':
	unittest.main()
			

 

你可能感兴趣的:(测试开发)