#Coding=utf-8 fromAppiumImportWebdriverImport TimeImportUnitTestImportOSImportHtmltestrunnerclassLogintestlizi (unittest. TestCase):defsetUp (self): Desired_caps={} desired_caps['PlatformName'] ='Android' #Equipment Systemdesired_caps['platformversion'] ='6.0.1' #Device System versiondesired_caps['devicename'] ='270f2988' #Device Namedesired_caps['Apppackage'] ='Com.lizi.app' #Test App Package namedesired_caps['appactivity'] ='. Activity. Mainactivity' #Test appactivitySelf.driver = Webdriver. Remote ('Http://localhost:4723/wd/hub', Desired_caps)#Launch App defTest_login (self): driver=Self.driver#Click on the ' my ' button after entering the homepageDriver.find_element_by_name (U'my own'). Click () time.sleep (2) #Click the login Avatar button to log in and jump to the login screenDRIVER.FIND_ELEMENT_BY_ID ('Com.lizi.app:id/user_login_iv'). Click () time.sleep (2) #Enter user nameDRIVER.FIND_ELEMENT_BY_ID ('Com.lizi.app:id/zhanghao_edittext'). Send_keys ('18267200735') #Enter PasswordDRIVER.FIND_ELEMENT_BY_ID ('Com.lizi.app:id/password_edittext'). Send_keys ('Password') #Click the Confirm login buttonDRIVER.FIND_ELEMENT_BY_ID ('Com.lizi.app:id/login_button'). Click () time.sleep (3) #login is successful, the page slides, otherwise you can't click the Settings buttonDriver.swipe (500, 200, 500, 800, 0) time.sleep (2) #get the nickname after loginName = driver.find_element_by_id ('COM.LIZI.APP:ID/LOGIN_USERNAME_TV'). Text#add an assertion that prints an error message if the nickname is incorrect Try: assert 'No_matter' inchnamePrint 'Loginuser is right' exceptAssertionerror as E:Print 'Loginuser is Error' #Click the Settings button to go to the Settings pageDRIVER.FIND_ELEMENT_BY_ID ('Com.lizi.app:id/setting_imageview'). Click ()#Click the Exit buttonDRIVER.FIND_ELEMENT_BY_ID ('Com.lizi.app:id/exit_button'). Click ()defTearDown (self): Self.driver.quit ()if __name__=='__main__': Suite=UnitTest. TestSuite () suite.addtest (Logintestlizi ('Test_login')) FileName='c:\\temp\\app.html'FB= File (filename,'WB') Runner= Htmltestrunner.htmltestrunner (STREAM=FB, title='Liziapptestreport', description='Liziapp') Runner.run (Suite) fb.close ()
Appium+python a simple login test