Python+selenium+unittest Test Framework 2-Adorner @classmethod

Source: Internet
Author: User

Adorner @classmethod

First, the adorner @classmethod

Multiple use cases may require the browser to be opened multiple times, and the adorner @classmethod only open once. Classmethod is a class method in Python, and @ is a modifier symbol.

1, SetupClass ():

    @classmethod    def setupclass (CLS):

2, Teardownclass ():

    @classmethod    def teardownclass (CLS):

Example:

From seleniumImportWebdriverFrom timeImportSleepImportUnitTestClassLogin (unittest. TestCase): @classmethodDefSetupClass (CLS): Cls.driver =Webdriver. Chrome () Cls.driver.get ("Http://www.anenda.com") Cls.driver.implicitly_wait (30) Cls.driver.maximize_window () Sleep (2) cls.driver.find_element_by_id ("Liger-textbox-user"). Send_keys ("Chen") cls.driver.find_element_by_id ("Liger-textbox-pwd_old"). Clear () cls.driver.find_element_by_id ("Liger-textbox-pwd"). Send_keys ("Chen") cls.driver.find_element_by_id ("Go"). Click () Sleep (3)DefTest01 (self): RESULT1 = Self.driver.find_element_by_xpath (".//*[@id = ' L-topmenu-r-bottm ']/span[2]"). TextPrint(RESULT1) Result2 ="Anda, you are welcome."Self.assertin (result2,result1,msg="Reason for failure:%s not found in%s"%(RESULT1,RESULT2)) Sleep (2)DefTest02 (self): RESULT1 = self.driver.find_element_by_id ("Hour "). Text print (RESULT1) result2 =  " 2018 "  Self.assertin (Result2,result1,msg= " Span style= "COLOR: #800000" > failure reason:%s "%) @classmethod def Teardownclass (CLS): Cls.driver.quit () if __name __ = =  ' __main__ ": Unittest.main ()           

Python+selenium+unittest Test Framework 2-Adorner @classmethod

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.