One, the mobile phone USB connection computer (mobile phone open debug mode)
Verify: Cmd--enter ADB devices to see the udid of your phone. The connection is displayed as follows
Second, start Appium service
1. Start Appium, click the triangle in the upper right corner
2. Start the Appium server successfully
Third, run the logon script
#-*-Encoding:utf-8-*-
Import UnitTest
From Appium import Webdriver
Import OS
Import time
Class Login (UnitTest. TestCase):
def setUp (self):
Desired_cups = {}
#设备平台
desired_cups[' platformname ' = ' Android '
#设备系统版本
desired_cups[' platformversion '] = ' 5.0.2 '
#设备名称
desired_cups[' devicename ' = ' HuaWei '
#apk安装包路径
#PATH = Lambda P:os.path.abspath (os.path.join (Os.path.dirname (__file__), p))
#desired_cups [' app '] = PATH (' e:\\2017\\app-debug.apk ')
desired_cups[' apppackage '] = ' com.grandsoft.intercom '
desired_cups[' appactivity '] = ' com.grandsoft.intercom.SplashActivity '
#如果设置的是app在电脑上的路径, you do not need to match apppackage and appactivity, and conversely
#启动app
Self.driver = Webdriver. Remote (' Http://localhost:4723/wd/hub ', desired_cups)
#启动app时, it takes a certain amount of time to enter the boot page, so you must set the wait time, or the following will always be error locating element
Time.sleep (5)
def tearDown (self):
Self.driver.find_element_by_xpath ('//android.widget.linerlayout[@id = ' com.grandsoft.intercom:id/mainlayout ']/ View[1]/imagebutton ')
self.driver.find_element_by_id (' Com.grandsoft.intercom:id/tv_left_menu_title '). Click ()
self.driver.find_element_by_id (' Com.grandsoft.intercom:id/account_edit '). Clear ()
self.driver.find_element_by_id (' Com.grandsoft.intercom:id/key_edit '). Clear ()
Self.driver.quit ()
def test_login (self):
Username = self.driver.find_element_by_id (' Com.grandsoft.intercom:id/account_edit ')
#username. Clear ()
Username.send_keys (' 13417842429 ')
Password = self.driver.find_element_by_id (' Com.grandsoft.intercom:id/key_edit ')
#password. Clear ()
Password.send_keys (' 123456789 ')
self.driver.find_element_by_id (' Com.grandsoft.intercom:id/login_button '). Click ()
title = self.driver.find_element_by_id (' Com.grandsoft.intercom:id/tooltitle ')
If title is not None:
print ' Login is success '
Else
print ' Login is False '
if __name__ = = ' __main__ ':
Unittest.main ()
Python+appium Real-Computer Run login Example