程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Using python/appium to realize automatic login of app

編輯:Python
from appium import webdriver
import time,traceback
desired_caps = {
}
# Test platform , Can't write wrong 
desired_caps['platformName'] = 'Android'
# Platform version , Can't write wrong 
desired_caps['platformVersion'] = '8.1.0'
# Equipment name ,android Fill in any value on the 
desired_caps['deviceName'] = 'test'
# apk File pathname , If the device does not already have this app , Will install .
desired_caps['app'] = r'd:\apk\toutiao.apk'
# app package name , Be sure to have , The developer gave app Take the name , Can uniquely identify this app.
desired_caps['appPackage'] = 'io.manong.developerdaily'
# app start-up Activity, It is also a required parameter . An android app Activity As the corresponding 
# A user interface 
desired_caps['appActivity'] = 'io.toutiao.android.ui.activity.LaunchActivity'
# If we automate , There are Chinese characters in the information to be input , I need this parameter , Otherwise, we can not 
# Adding this parameter will add a new unicode typewriting 
desired_caps['unicodeKeyboard'] = True
# After the test , The input method should be restored to the original , For example, it was Sogou input method 
desired_caps['resetKeyboard'] = True
# This noReset Parameters , It's very important !!
# To ensure the app The data will not be cleared before the test , By default, the data will be cleared 
desired_caps['noReset'] = True
# Our test program is connected to appium server after ,appium server Have been waiting for client The order of .
# If more than a certain time , No order , such as debug When , It will assume that the client has exited . Will disconnect 
# This parameter specifies how long ,appium
#erver It can be considered that the connection has been disconnected 
desired_caps['newCommandTimeout'] = 6000
# start-up Remote RPC, take capability Parameters of the incoming ,
# Create a 
#webdriver object , and Selenium
# similar .
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
try:
# and Selenium Same meaning 
driver.implicitly_wait(10)
# The following code , It is based on id Element found , And operate , For example, click on 、 Input text , Or get the text , Judge whether it is the same as expected .
driver.find_element_by_id(
"io.manong.developerdaily:id/tab_bar_plus").click()
time.sleep(1)
driver.find_element_by_id(
"io.manong.developerdaily:id/btn_email").click()
time.sleep(1)
# enter one user name 、 password 
ele = driver.find_element_by_id("io.manong.developerdaily:id/edt_email")
ele.send_keys('XXXXXXXXX')
ele = driver.find_element_by_id("io.manong.developerdaily:id/edt_password")
ele.send_keys('XXXXXXXXXXXXX')
time.sleep(2)
# Click login 
driver.find_element_by_id(
'io.manong.developerdaily:id/btn_login').click()
except:
print
traceback.format_exc()
input('**** Press to quit..')
driver.quit()

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved