Selenium python automated test DDT data driven

Source: Internet
Author: User
Tags selenium python

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.