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()