coding=utf-8
import time
from appium import webdriver
desired_caps = {'platformName': 'Android',
'platformVersion': '6.0.1',
'deviceName': 'device',
'appPackage': 'com.okyuyin',
'appActivity': 'com.okyuyin.login.LoadingActivity',
'automationName': 'uiautomator1',
'resetKeyboard': 'true'}
远程连接到devices
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
关闭会话
driver.quit()
====================Seeion====================
获取会话的功能
'''
desired_caps = driver.session
print(desired_caps)
time.sleep(2)
'''
返回
'''
driver.back()
time.sleep(2)
'''
屏幕截图并保存
'''
screenshotBase64 = driver.get_screenshot_as_file("D:\SDK\1.png")
'''
获取Source(页面源文件)
'''
page_source = driver.page_source
print(page_source)
'''
设置页面加载超时时间
'''
driver.set_page_load_timeout(5000)
'''
设置隐式等待
'''
driver.implicitly_wait(5)
'''
脚本执行超时时间
'''
driver.set_script_timeout(5000)
'''
获取Orientation(就是切换横屏竖屏:"LANDSCAPE"--横屏 “PORTRAIT”--竖屏)
'''
get
direction = driver.orientation
print(direction)
set
driver.orientation = "PORTRAIT"
'''
获取定位(经纬度和海拔)
'''
local = driver.location
print(local)
set local
driver.set_location(49, 123, 10)
'''
获取日志类型
'''
log_type = driver.log_types
print(log_type)
['logcat', 'bugreport', 'server']
'''
get_log
'''
logs = driver.get_log('server')
print(logs)
'''
set用户自定义日志事件
'''
driver.log_event('appium', 'funEvent')
'''
get用户自定义日志事件
'''
funEvent = driver.get_events()
funEvent = driver.get_events(['funEvent'])
print(funEvent)
'''
获取、更新设置
'''
setting = driver.get_settings()
driver.update_settings({"sample": "value"}))
print(setting)
'''
====================Device-Activity====================
start activity(启动activity)
'''
driver.start_activity('com.okyuyin', 'com.okyuyin.login.ui.main.MainActivity')
'''
Current Activity获取当前活动--activity name
'''
current = driver.current_activity
print(current)
'''
Current Package获取当前包
'''
cur_pack = driver.current_package
print(cur_pack+current)
'''
====================Device-App====================
安装app
'''
driver.install_app('path')
'''
判断指定包名的App是否已安装
'''
print(driver.is_app_installed('com.okyuyin'))
'''
对正在调试的应用(App)进行:启动或者重启
'''
driver.launch_app()
'''
将应用置于后台并在一定时候后返回,或者直接停用(部分模拟器三方可能出现无法返回的情况)
'''
driver.background_app(5)
'''
关闭 重置 删除 App
'''
Close App
driver.close_app()
reset App
driver.reset()
remove App
driver.remove_app()
'''
激活 App (打开应用程序)
'''
driver.activate_app('com.android.settings')
time.sleep(2)
'''
终止 App (关闭应用程序)
'''
driver.terminate_app('com.android.settings')
'''
查看应用程序状态 (运行状态)
'''
返回参数:
【0】 is not installed.
【1】 is not running.
【2】 is running in background or suspended.
【3】 is running in background.
【4】 is running in foreground. (number)
print(driver.query_app_state('com.android.settings'))
print(driver.query_app_state('com.okyuyin'))
'''
Get App Strings
'''
appStrings = driver.app_strings('en', 'path to file')
print(appStrings)
'''
End Test Coverage(暂时不懂啥意思,没懂起)
'''
driver.end_test_coverage('intent', 'path')
'''