Appium+python a simple login test

Source: Internet
Author: User

#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

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.