# coding=utf-8 案例一: 2 ''' 3 Created on 2017-7-22 4 @author: Jennifer 5 Project:登录百度测试用例 6 ''' 7 from selenium import webdriver 8 import unittest, time 9 10 class BaiduTest(unittest.TestCase):11 def setUp(self):12 self.driver = webdriver.Chrome()13 self.driver.implicitly_wait(30) #隐性等待时间为30秒14 self.base_url = "https://www.baidu.com"15 16 def test_baidu(self):17 driver = self.driver18 driver.get(self.base_url + "/")19 driver.find_element_by_id("kw").clear()20 driver.find_element_by_id("kw").send_keys("unittest")21 driver.find_element_by_id("su").click()22 time.sleep(3)23 title=driver.title24 self.assertEqual(title, u"unittest_百度搜索") 25 26 def tearDown(self):27 self.driver.quit()28 29 if __name__ == "__main__":30 unittest.main() 案例二:
# coding=utf-8'''Created on 2017-7-22@author: JenniferProject:使用有道翻译测试用例'''from selenium import webdriverimport unittest, timeclass 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) def tearDown(self): self.driver.quit()if __name__ == "__main__": unittest.main()