python+appium真機運行登入例子

來源:互聯網
上載者:User

標籤: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真機運行登入例子

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.