#Exercise 9:ImportUnitTest fromSeleniumImportWebdriverImport TimeclassGloryroad (unittest. TestCase):defsetUp (self):#start the Firefox browserSelf.driver = Webdriver. Chrome (Executable_path ="C:\\chromedriver") defTestsogou (self):#Visit Sogou homepageSelf.driver.get ("http://sogou.com") #Empty search Input box default contentSELF.DRIVER.FIND_ELEMENT_BY_ID ("Query"). Clear ()#Enter "Glory Road automation Test" in the Search input boxSELF.DRIVER.FIND_ELEMENT_BY_ID ("Query"). Send_keys (U"Webdriver Practical Treasure") #Click the Search buttonSELF.DRIVER.FIND_ELEMENT_BY_ID ("STB"). Click ()#wait 3 secondsTime.sleep (3) assertU"Ms. Wu" inchSelf.driver.page_source, U"There are no keywords to look for in the page! ". Encode ("GBK") deftestbing (self):#Visit Sogou homepageSelf.driver.get ("http://cn.bing.com") #Empty search Input box default contentSELF.DRIVER.FIND_ELEMENT_BY_ID ("sb_form_q"). Clear ()#Enter "Glory Road automation Test" in the Search input boxSELF.DRIVER.FIND_ELEMENT_BY_ID ("sb_form_q"). Send_keys (U"Webdriver Practical Treasure") #Click the Search buttonSELF.DRIVER.FIND_ELEMENT_BY_ID ("Sb_form_go"). Click ()#wait 3 secondsTime.sleep (3) assertU"Miss Wang" inchSelf.driver.page_source, U"There are no keywords to look for in the page! ". Encode ("GBK") defTearDown (self):#Exit Browserself.driver.quit ()if __name__=='__main__': Unittest.main ()
"Python" unittest-5