標籤:deb one sleep desire account web 指令碼 進入 rem
一、手機USB串連電腦(手機開啟偵錯模式)
驗證:cmd -> 輸入adb devices,查看手機的UDID.顯示如下表示 串連成功
二、啟動Appium服務
1. 啟動Appium,點擊 右上方的三角形
2. 啟動Appium伺服器成功
三、運行登入指令檔
# -*- 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在電腦上的路徑,則不需要配appPackage和appActivity,同理反之
#啟動app
self.driver = webdriver.Remote(‘http://localhost:4723/wd/hub‘,desired_cups)
#啟動app時,需要一定時間進入引導頁,所以必須設定等待時間,不然下面會一直報錯定位不到元素
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真機運行登入例子