Selenium Notes 7

Source: Internet
Author: User

#!/usr/bin/env python#-*-coding:utf-8-*-"""@desc: Test the login function of 126 mailbox 1. Use the public method public.login2. Place the test data in an XML file, using data-driven (/test_data/login.xml) 3. Here we use Xml.dom.minidom to read the XML data"""ImportUnitTestImportXml.dom.minidomImportOSImportSYS fromSeleniumImportWebdrivercur_dir=os.getcwd () sys.path.append (Cur_dir.split (R'\test_case') [0]) fromPublicImportLoginfpath= Cur_dir.split ('Test_case') [0] +'Test_data'+ Os.path.sep +'Login.xml'#open an XML documentDom =xml.dom.minidom.parse (Fpath)#Get document Element ObjectRoot =dom.documentelementclassTestlogin (unittest. TestCase):defsetUp (self): Self.driver=Webdriver. Firefox () self.driver.implicitly_wait (30) Logins= Root.getelementsbytagname ('URL') Self.base_url=Logins[0].firstchild.data self.verificationerrors= []    #use Case 1: User name, password is empty    defTest_null (self): driver=self.driver driver.get (self.base_url)#reading the data in XMLlogins = Root.getelementsbytagname ('NULL')        #gets the username, password property value of the null tagUsername = Logins[0].getattribute ("username") Password= Logins[0].getattribute ("Password") Prompt_info=Logins[0].firstchild.data#LoginLogin.login (self, username, password)#get assertion information to assertText = Driver.find_element_by_xpath ("//div[@class = ' Error-tt ']/p"). Text self.assertequal (text, prompt_info)#use case 2: User name is empty    defTest_user_null (self): driver=self.driver driver.get (self.base_url) Logins= Root.getelementsbytagname ('User_null')        #get username, Passwrod attribute values for user_null tagsUsername = Logins[0].getattribute ("username") Password= Logins[0].getattribute ("Password") Prompt_info=Logins[0].firstchild.data#LoginLogin.login (self, username, password)#get assertion information to assertText = Driver.find_element_by_xpath ("//div[@class = ' Error-tt ']/p"). Text self.assertequal (text, prompt_info)#use case 3: password is empty    defTest_pwd_null (self): driver=self.driver driver.get (self.base_url) Logins= Root.getelementsbytagname ('Pwd_null')        #get username, Passwrod attribute values for pwd_null tagsUsername = Logins[0].getattribute ("username") Password= Logins[0].getattribute ("Password") Prompt_info=Logins[0].firstchild.data#LoginLogin.login (self, username, password)#get assertion information to assertText = Driver.find_element_by_xpath ("//div[@class = ' Error-tt ']/p"). Text self.assertequal (text, prompt_info)#use case 4: Wrong user name and password    defTest_error (self): driver=self.driver driver.get (self.base_url) Logins= Root.getelementsbytagname ('Error')        #get the Username, Passwrod property value of the error tagUsername = Logins[0].getattribute ("username") Password= Logins[0].getattribute ("Password") Prompt_info=Logins[0].firstchild.data#LoginLogin.login (self, username, password)#get assertion information to assertText = Driver.find_element_by_xpath ("//div[@class = ' Error-tt ']/p"). Text self.assertequal (text, prompt_info)defTearDown (self): Self.driver.quit () self.assertequal ([], self.verificationerrors)if __name__=="__main__": Unittest.main ()

Selenium Notes 7

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.