Writing appium use cases using Python

Source: Internet
Author: User

Installing Python dependencies
pip3.4 install nosepip3.4 install seleniumpip3.4 install Appium-Python-Client
Run the test case android_contacts.py
Import osimport unittestfrom appium import webdriverfrom time import sleep# Returns abs path relative to this file and not Cwdpath = Lambda P:os.path.abspath (os.path.join (Os.path.dirname (__file__), p)) class Contactsandroidtests (UnitTest. TestCase): def setUp (self): Desired_caps = {} desired_caps[' platformname '] = ' Android ' Desired_cap            s[' platformversion ' = ' 4.4 ' desired_caps[' devicename '] = ' 192.168.56.111:5555 ' desired_caps[' app ' = PATH ( ‘.. /.. /.. /sample-code/apps/contactmanager/contactmanager.apk ') desired_caps[' apppackage '] = ' Com.example.android.con Tactmanager ' desired_caps[' appactivity '] = '. Contactmanager ' Self.driver = webdriver. Remote (' Http://0.0.0.0:4723/wd/hub ', desired_caps) def tearDown (self): Self.driver.quit () def TEST_ADD_CONTAC TS (self): el = Self.driver.find_element_by_name ("Add Contact") El.click () Textfields = self.driver.fi Nd_elements_by_class_name ("anDroid.widget.EditText ") Textfields[0].send_keys (" Appium User ") Textfields[2].send_keys (" [Email protecte D] ") self.assertequal (' Appium User ', Textfields[0].text) self.assertequal (' [email protected] ', Textfiel Ds[2].text) Self.driver.find_element_by_name ("Save"). Click () # for some reason "save" breaks things A Lert = Self.driver.switch_to_alert () # no-to-handle alerts in Android Self.driver.find_element_by_androi D_uiautomator (' New Uiselector (). Clickable (True) '). Click () self.driver.keyevent (3) if __name__ = = ' __main__ ': Suit E = UnitTest. Testloader (). Loadtestsfromtestcase (contactsandroidtests) unittest. Texttestrunner (verbosity=2). Run (Suite)
To run a use case result:
[email protected] python$ python3.4 android_contacts.py test_add_contacts (__main__.ContactsAndroidTests) ... ok----------------------------------------------------------------------Ran 1 test in 17.214sOK
Public account: WIRELESSQA

About

Author: Bi Xiaobong | Old bi e-mail: [email protected]

Weibo: @WirelessQA Blog: HTTP://BLOG.CSDN.NET/WIRELESSQA

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.