Python+Selenium unittestユニットテストフレームワーク
1438 ワード
# coding=utf-8
import time
import unittest
from selenium import webdriver
class BaiduSearch(unittest.TestCase):
def setUp(self):
"""
setUp() ,
:return:
"""
self.driver = webdriver.Chrome("C:\\Users\suxiahua\AppData\Local\Programs\Python\Python36\Lib\site-packages\chromedriver_win32\chromedriver.exe")
self.driver.maximize_window()
time.sleep(3)
self.driver.get("https://www.baidu.com")
def tearDown(self):
"""
,
:return:
"""
self.driver.quit()
def test_baidu_search(self):
"""
test , test 。
:return:
"""
self.driver.find_element_by_id('kw').send_keys('selenium')
time.sleep(1)
try:
assert 'selenium' in self.driver.title
print ('Test Pass.')
except Exception as e:
print ('Test Fail.', format(e))
if __name__ == '__main__':
unittest.main()