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