Appium 003--Script Development: Official Demo Demo android_contacts.py

Source: Internet
Author: User
Tags appium

Premise: According to the previous environment construction introduction, install the relevant environment

Step1: Launch Android emulator

Step2: Start the Appium server

Step3: Demo Code execution

Here is the official Demo code: Address Book Management app, install Open app, and add a contact saved action

A. First go to download contactmanager.apk put to E disk E:\ContactManager.apk

https://github.com/appium/sample-code/blob/master/sample-code/apps/ContactManager/ContactManager.apk

B. Sample code for the android_contact.py download down in the Python directory

https://github.com/appium/sample-code/blob/master/sample-code/examples/python/android_contacts.py

C. Partial modification of Python code

#!/usr/bin/env python#-*-coding:utf-8-*-ImportOSImportUnitTest fromAppiumImportWebdriver fromTimeImportSleep#Returns ABS Path relative to this file and not CWDPATH =LambdaP:os.path.abspath (Os.path.join (Os.path.dirname (__file__), p))classcontactsandroidtests (unittest. TestCase):defsetUp (self): Desired_caps={} desired_caps['PlatformName'] ='Android'desired_caps['platformversion'] ='4.4.2'desired_caps['devicename'] ='Android Emulator'desired_caps['app'] =PATH ('E:\ContactManager.apk') desired_caps['Apppackage'] ='Com.example.android.contactmanager'desired_caps['appactivity'] ='. Contactmanager'Self.driver= Webdriver. Remote ('Http://localhost:4723/wd/hub', Desired_caps)defTearDown (self): Self.driver.quit ()deftest_add_contacts (self): El= self.driver.find_element_by_accessibility_id ("ADD Contact") El.click () Textfields= Self.driver.find_elements_by_class_name ("Android.widget.EditText") Textfields[0].send_keys ("Appium User") textfields[2].send_keys ("[email protected]") self.assertequal ('Appium User', Textfields[0].text) self.assertequal ('[email protected]', textfields[2].text) self.driver.find_element_by_accessibility_id ("Save"). Click ()#For some reason "save" breaks thingsAlert =Self.driver.switch_to_alert ()#No-to- handle alerts in AndroidSelf.driver.find_element_by_android_uiautomator ('new Uiselector (). Clickable (True)'). Click () Self.driver.press_keycode (3)if __name__=='__main__': Suite=UnitTest. Testloader (). Loadtestsfromtestcase (contactsandroidtests) unittest. Texttestrunner (verbosity=2). Run (Suite)

Appium 003--Script Development: Official Demo Demo android_contacts.py

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.