ImportUnitTest fromAppium.webdriverImportWebdriver fromDdtImportData,ddt,unpackclassmytestcase (unittest. TestCase):defSetUp (self):#the process of preparationDesired_caps ={} desired_caps["PlatformName"] ="Android"desired_caps["platformversion"] ="4.3"desired_caps["devicename"] ="127.0.0.1:62001"desired_caps["Apppackage"] ="Com.syswin.baijingtoon"desired_caps["appactivity"] =""desired_caps["Unicodekeyboard"] ="Ture" #Support Chinese charactersdesired_caps["Resetkeyboard"] ="Ture"Self.driver= Webdriver. Remote ("Http://localhost:4723/wd/hub", Desired_caps)Print("setUp") #using the data annotations of DDT, write the parameters of the test case, which is a case of multiple parameters, each of which is a test case@data (("[email protected]","111111", False), ("lsy.com","1111112", True), ("l%$%$","111111", False)) @unpackdefTest_login (Self,username,password,expectedresult):#The procedure to execute, the test case that begins with testSELF.DRIVER.FIND_ELEMENT_BY_ID ("Email"). Send_keys (username)#fill in the emailSELF.DRIVER.FIND_ELEMENT_BY_ID ("pwd"). Send_keys (password)#fill in the passwordSELF.DRIVER.FIND_ELEMENT_BY_ID ("btn"). Click ()#Click the login button Try: ifSELF.DRIVER.FIND_ELEMENT_BY_ID ("btn"). Is_displayed ():#determine if there is a login button, if there is a result of false otherwise tureresult=FalseexceptException:result=True self.assertequal (result, Expectedresult) #断言defTearDown (self):#the process of cleaning upSelf.driver.quit ()#resource release, do not release the next execution will be error new session can not be established, can not be established when the need to restart Appiumif __name__=='__main__': Unittest.main ()
Test Case Execution Layer
ImportUnitTestImportunittestdemocases=unittest. Testloader.loadtestsfromtestcase (Unittestdemo. Mytestcase)#Load Test CasesMysuit=unittest. TestSuite ([cases])#using use case suite to run a use case#use case suite, want to add a use case need#Note that if you use DDT data driven, the name of each use case is automatically generated, not a fixed test_login, so you cannot add a single use case in the following ways, only to say that all csaes add to suitMysuit.addtest (Unittestdemo. Mytestcase ("Test_login"))#verbosity Log Level#0 (silent mode): Only the total number of test cases and results can be obtained#1 (default mode): Very similar to silent mode there is only one "." in front of each successful use case. There is a "F" in front of each failed use case#2 (verbose mode): test results show all relevant information for each test caseMyrunner=unittest. Texttestrunner (verbosity=2) Myrunner.run (mysuit)
Python unittest Framework for Appium Login