Installing DDT pip Install DDT
Directly on the code:
1 #Coding:utf-82 ImportDDT3 Import Time4 ImportExcelunit5 ImportUnitTest6 fromSeleniumImportWebdriver7 8 #test Data9data = Excelunit. Excelutil ("test.xlsx","Sheet1")TenTestData =Data.dict_data () One PrintTestData A - - @ddt. DDT the classBolg (unittest. TestCase): - """Login Blog""" - defsetUp (self): -Self.driver =Webdriver. Firefox () +URL ="Https://passport.cnblogs.com/user/signin" - self.driver.get (URL) +Self.driver.implicitly_wait (10) A at deflogin (self, username, PSW): - """Login method, account number and password parameterization""" -SELF.DRIVER.FIND_ELEMENT_BY_ID ("INPUT1"). Send_keys (username) -SELF.DRIVER.FIND_ELEMENT_BY_ID ("Input2"). Send_keys (PSW) -SELF.DRIVER.FIND_ELEMENT_BY_ID ("signin"). Click () -Time.sleep (3) in - defis_login_sucess (self): to """determine whether to get the login account name""" + Try: -Text = self.driver.find_element_by_id ("Lnk_current_user"). Text the Printtext * returnTrue $ except:Panax Notoginseng returnFalse - the@ddt. Data (*testData) + defTest_login (self, data): A """Login Case""" the Print("current test Data%s"%data) + #Call the Login method -Self.login (data["username"], data["Password"]) $ #Judging Results $result =self.is_login_sucess () - self.asserttrue (Result) - the defTearDown (self): - self.driver.quit ()Wuyi the - if __name__=="__main__": WuUnittest.main ()
Selenium python automated test DDT data driven