Blog Park Login--selenium+python

Source: Internet
Author: User

#Coding:utf-8 fromSeleniumImportWebdriverImportUnitTestclassCnblog (unittest. TestCase):defsetUp (self): Self.driver=Webdriver. Firefox () Self.url="Https://passport.cnblogs.com/user/signin"self.driver.get (Self.url) Self.driver.maximize_window () self.driver.implicitly_wait (10)    defCnblog_login (Self,username,password): self.driver.find_element_by_id ("INPUT1"). Clear () self.driver.find_element_by_id ("INPUT1"). Send_keys (username) self.driver.find_element_by_id ("Input2"). Send_keys (password) self.driver.find_element_by_id ("signin"). Click ()deftest_login_1 (self): self.cnblog_login (U"to the oak tree you","aaaaaa") Self.username=self.driver.find_elements_by_link_text (U"to the oak tree you") self.asserttrue (self.username,msg="Successful logon test failed")    deftest_login_2 (self): self.cnblog_login (U"to the oak tree you","bbbbbb") Self.username=self.driver.find_elements_by_link_text (U"to the oak tree you") Self.assertfalse (self.username,msg="Failed Login test failed")    defTearDown (self): Self.driver.quit ()if __name__=="__main__": Unittest.main ()

#Coding:utf-8 fromSeleniumImportWebdriver fromTimeImportSleepImportUnitTestclassCnblog (unittest. TestCase): @classmethoddefSetupClass (CLS): Cls.driver=Webdriver. Firefox () Cls.url="Https://passport.cnblogs.com/user/signin"Cls.sucurl="https://home.cnblogs.com/"Cls.failurl="https://passport.cnblogs.com/user/signin?AspxAutoDetectCookieSupport=1"cls.driver.get (Cls.url) Cls.driver.maximize_window ()deftest_login_1 (CLS): cls.driver.find_element_by_id ("INPUT1"). Clear () cls.driver.find_element_by_id ("INPUT1"). Send_keys (U"to the oak tree you") cls.driver.find_element_by_id ("Input2"). Send_keys ("aaaaaaaaa") cls.driver.find_element_by_id ("signin"). Click () Sleep (5) Cururl=cls.driver.current_url cls.assertequal (cururl,cls.sucurl)Print "successful login succeeded."    deftest_login_2 (CLS): cls.driver.find_element_by_id ("INPUT1"). Clear () cls.driver.find_element_by_id ("INPUT1"). Send_keys (U"to the oak tree you") cls.driver.find_element_by_id ("Input2"). Send_keys ("bbbbbbb") cls.driver.find_element_by_id ("signin"). Click () Cururl=cls.driver.current_url cls.assertequal (cururl,cls.failurl)Print "failed Login succeeded"@classmethoddefTeardownclass (CLS): Cls.driver.quit ()if __name__=="__main__": Unittest.main ()
#Coding:utf-8 fromSeleniumImportWebdriverImportUnitTestclassCnblog (unittest. TestCase):defsetUp (self): Self.driver=Webdriver. Firefox () Self.url="Https://passport.cnblogs.com/user/signin"self.driver.get (Self.url) Self.driver.maximize_window () self.driver.implicitly_wait (10)    deftest_login_1 (self): Self.driver.execute_script ("$ (' #input1 '). Val (' You to the Oak tree ')") Self.driver.execute_script ("$ (' #input2 '). Val (' aaaaaa ')") Self.driver.execute_script ("$ (' #signin '). Click ()") Self.username=self.driver.find_elements_by_link_text (U"to the oak tree you") self.asserttrue (self.username,msg="Successful logon test failed")    deftest_login_2 (self): Self.driver.execute_script ("$ (' #input1 '). Val (' You to the Oak tree ')") Self.driver.execute_script ("$ (' #input2 '). Val (' bbbbbb ')") Self.driver.execute_script ("$ (' #signin '). Click ()") Self.username=self.driver.find_elements_by_link_text (U"to the oak tree you") Self.assertfalse (self.username,msg="Successful logon test failed")    defTearDown (self): Self.driver.quit ()if __name__=="__main__": Unittest.main ()

Blog Park Login--selenium+python

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.