2021-09-23 Appium方法记录文档(持续更新)

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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 知识概览 一、 移动端测试是什么 移动端测试是指对移动应用进行的测试,即实体的特性满足需求的程度。 二、 移动端测...
    __65a0阅读 6,148评论 1 10
  • 移动端测试 知识概览 一、 移动端测试是什么 移动端测试是指对移动应用进行的测试,即实体的特性满足需求的程度。 二...
    G_eebd阅读 5,182评论 0 0
  • 一、Appium介绍 Appium是一个移动端的自动化框架,可用于测试原生应用、移动网页应用和混合型应用,且是跨平...
    Anwfly阅读 7,631评论 2 7
  • 一、Appium介绍 Appium是一个移动端的自动化框架,可用于测试原生应用、移动网页应用和混合型应用,且是跨平...
    小何今天学习了吗阅读 4,097评论 0 0
  • 一、Appium介绍 Appium是一个移动端的自动化框架,可用于测试原生应用、移动网页应用和混合型应用,且是跨平...
    九樱MOL阅读 4,461评论 0 0