RobotFramework AppiumLibrary 用户关键字
RobotFramework AppiumLibrary 用户关键字
- 最近在用robotframework搞安卓app 的自动化,其中用到了 AppiumLlibrary 的关键字,我都映射成了用户关键字,需要的自取。
- 把页面内容copy 到你本地的txt 文件中,然后导入到你自己的RobotFramewrk 工程中,就可以使用了,注意你需要先导入AppiumLlibrary 关键字哟~
*** Settings ***
Library AppiumLibrary
Library AutoItLibrary
Library os
*** Keywords ***
xpath应该匹配次数
[Arguments] ${xpath} ${count}
Xpath Should Match X Times ${xpath} ${count}
上传文件
[Arguments] ${path} ${data} ${encode}=base64
Push File ${path} ${data} ${encode}
元素不应该包含文本
[Arguments] ${locator} ${expected} ${msg}=
Element Should not Contain Text ${locator} ${expected} ${msg}
元素值应该是
[Arguments] ${locator} ${expected}
Element Value Should Be ${locator} ${expected}
元素名应该是
[Arguments] ${path} ${name}
Element Name Should Be ${path} ${name}
元素属性应该匹配
[Arguments] ${locator} ${attr_name} ${match_pattern} ${regx}=False
Element Attribute Should Match ${locator} ${attr_name} ${match_pattern} ${regx}
元素应该包含文本
[Arguments] ${locator} ${expected} ${msg}=None
Element Should Contain Text ${locator} ${expected} ${msg}
元素应该失效
[Arguments] ${locator} ${level}=INFO
Element should be disabled ${locator} ${level}
元素应该有效
[Arguments] ${locator} ${level}=INFO
Element should be enabled ${locator} ${level}
元素文本应该是
[Arguments] ${locator} ${expected} ${msg}=None
Element Text Should Be ${locator} ${expected} ${msg}
关闭当前应用
Close Application
关闭所有应用
Close All Applications
切换应用
[Arguments] ${index_or_alias}
Switch Application ${index_or_alias}
切换页面内容
[Arguments] ${webview}
Switch To Context ${webview}
卸载应用
[Arguments] ${application_id}
Remove Application ${application_id}
后台运行
[Arguments] ${sec}
Background App ${sec}
向上滚动
[Arguments] ${locator}
Scroll Up ${locator}
向下滚动
[Arguments] ${locator}
Scroll Down ${locator}
失败后运行关键字
[Arguments] ${keyword}
[Documentation] Example: # Disables run-on-failure functionality and stores the previous kw name in a variable. # Restore to the previous keyword.
...
... Register Keyword To Run On Failure \ \ \ Log Source
... \ \ \ \ \ \ \ # Run `Log Source` on failure.
...
... ${previous kw}=
... Register Keyword To Run On Failure \ \ Nothing
...
...
... Register Keyword To Run On Failure \ \ \ \ ${previous kw} \ \ \ \
Register Keyword To Run On Failure ${keyword}
打印资源
[Arguments] ${level}
Log Source ${level}
打开URL
[Arguments] ${url}
[Documentation] Example:
...
... 打开应用
... http://localhost:4755/wd/hub \ platformName=iOS \ platformVersion=7.0
... deviceName='iPhone Simulator'
... browserName=Safari
...
... 打开URL \ http://m.webapp.com
Go To URL ${url}
打开应用
[Arguments] ${url} ${platformName} ${version} ${deviceName} ${app}
[Documentation] 打开应用 ${url} ${platformName} ${version} \ \ ${devicename} ${app} @{args}
...
... 例如:
...
... 打开应用 http://localhost:4723/wd/hub Android 5.1.1 5e25d20d ${CURDIR}${/}app${/}fft.apk
...
... ${url} 是用于访问应用的地址,一般是固定的。 url 和 端口可以根据具体地址修改。
... ${version} \ 是安卓的版本
... ${devicename} 是手机的UDID, 可以打开cmd 然后用 adb devices -l \ 看到设备列表。
... UDID 是看到的第一列的内容,真机是一串字符串,模拟器是 \ ip:port \ 的形式
... ${app} 是apk 存放的路径 ${CURDIR} 系统变量,取得当前脚本路径。 ${/} 系统变量 '/'
open application ${url} platformName=${platformName} platformVersion=${version} deviceName=${deviceName} app=${app}
按关键字
[Arguments] ${keycode} ${metastate}=None
Press Keycode ${keycode} ${metastate}
摇动手机
Shake
放大元素
[Arguments] ${locator} ${percent}=200% ${step}=1
Zoom ${locator} ${percent} ${step}
敲击元素
[Arguments] ${locator}
Tap ${locator}
横屏
[Documentation] 手机设置横屏
LANDSCAPE
清除文本
[Arguments] ${locator}
Clear Text ${locator}
滑动
[Arguments] ${start_x} ${start_y} ${end_x} ${end_y}
swipe ${start_x} ${start_y} ${end_x} ${end_y}
滚动
[Arguments] ${start_locator} ${end_locator}
[Documentation] 从一个元素滚动到另一个元素
Scroll ${start_locator} ${end_locator}
点击元素
[Arguments] ${locator}
Click Element ${locator}
点击元素坐标
[Arguments] ${coordinate_x} ${coordinate_y}
Click Element At Coordinates ${coordinate_x} ${coordinate_y}
点击固定点
[Arguments] ${x} ${y} @{args}
Click A Point ${x} ${y} @{args}
点击按钮
[Arguments] ${index_or_name}
Click Button ${index_or_name}
点击文本
[Arguments] ${text} ${exact_match}=false
[Documentation] 点击匹配到文本的元素:
...
... 点击文本 "text"
... 点击文本 "text" True
...
... 默认模糊匹配所有元素,可以设置成精确匹配。
... 如果可以匹配到两个或两个以上的元素,那么需要用 click Element 元素,去处理。
Click Text ${text} ${exact_match}
睡眠
[Arguments] ${sec}
sleep ${sec}
竖屏
PORTRAIT
等待页面元素出现
[Arguments] ${locator} ${timeout}=100 ${err}=None
Wait Until Page Contains Element ${locator} ${timeout} ${err}
等待元素出现文本
[Arguments] ${text} ${timeout}=10 ${err}=None
Wait Until Page Contains ${text} ${timeout} ${err}
等待页面不包含元素
[Arguments] ${locator} ${timeout}=10 ${err}=None
Wait Until Page Does Not Contain Element ${locator} ${timeout} ${err}
等待页面不包含文本
[Arguments] ${text} ${timeout}=10 ${err}=None
Wait Until Page Does Not Contain ${text} ${timeout} ${err}
缩小元素
[Arguments] ${locator} ${percent}=200% ${step}=1
Pinch ${locator} ${percent} ${step}
获取Appium超时时间
${timeout} Get Appium Timeout
[Return] ${timeout}
获取Web元素
[Arguments] ${locator}
[Documentation] 获取匹配的定位器的第一个元素:
...
... ${element} 获取Web元素 id=name
... 点击元素 ${element}
${element} Get Webelement ${locator}
[Return] ${element}
获取元素坐标
[Arguments] ${locator}
${location} Get Element Location ${locator}
[Return] ${location}
获取元素尺寸
[Arguments] ${locator}
${size} Get Element Size ${locator}
[Return] ${size}
获取元素属性
[Arguments] ${locator} ${name_or_value}
[Documentation] 获取元素属性:(name 或者 value)
... ${val} \ 获取元素属性 ${locator} ${name_or_value}
...
... 例如:
... ${val} 获取元素属性 id=xxxx name
... ${val} 获取元素属性 id=xxxx value
${val} Get Element Attribute ${locator} ${name_or_value}
[Return] ${val}
获取匹配xpath数
[Arguments] ${xpath}
[Documentation] 例如:
...
... ${count} \ \ \ 获取匹配xpath数 \ \ //android.view.View[@text='Test']
${count} Get Matching Xpath Count ${xpath}
[Return] ${count}
获取可见文本
${contents} Get Contexts
[Return] ${contents}
获取当前文本
${context} Get Current Context
[Return] ${context}
获取所有web元素
[Arguments] ${locator}
[Documentation] @{element} 获取所有web元素 id=my_element
... 点击元素 @{element}[2]
@{element} Get Webelements ${locator}
[Return] @{element}
获取文件
[Arguments] ${file_path} ${decode}=False
pull file ${file_path} ${decode}
获取文件夹
[Arguments] ${folder_path} ${decode}=False
Pull Folder ${folder_path} ${decode}
获取文本
[Arguments] ${locator}
[Documentation] 获取符合元素的文本:
... ${text} \ 获取文本 \ //*[contains(@text,'foo')]
${text} Get Text ${locator}
[Return] ${text}
获取网络连接情况
${stat} Get Network Connection Status
[Return] ${stat}
获取资源
${source} Get Source
[Return] ${source}
设置Appium超时
[Arguments] ${sec}
Set Appium Timeout ${sec}
设置网络连接状态
[Arguments] ${sec}
Set Network Connection Status ${sec}
输入值
[Arguments] ${locator} ${val}
Input Value ${locator} ${val}
输入密码
[Arguments] ${path} ${passwd}
Input Password ${path} ${passwd}
输入文本
[Arguments] ${path} ${text}
Input Text ${path} ${text}
返回
[Documentation] 浏览器返回上一个的页面
Go Back
重置应用
Reset Application
锁屏
[Arguments] ${sec}
[Documentation] 这个方法只使用于IOS
Lock ${sec}
长按元素
[Arguments] ${locator}
Long Press ${locator}
长按关键字
[Arguments] ${keycode} ${metastate}=None
[Documentation] keycode 可以在这个网址里面找到:
... http://developer.android.com/reference/android/view/KeyEvent.html.
...
... Args:
... \ \ \ \ - keycode - the keycode to be sent to the device
... \ \ - metastate - meta information about the keycode being sent
Long Press Keycode ${keycode} ${metastate}
隐藏键盘
Hide Keyboard
页面不应该包含元素
[Arguments] ${locator} ${lvl}=INFO
Page Should Not Contain Element ${locator} ${lvl}
页面不应该包含文本
[Arguments] ${locator} ${lvl}=INFO
Page Should Not Contain Text ${locator} ${lvl}
页面应该包含元素
[Arguments] ${locator} ${lvl}=INFO
Page Should Contain Element ${locator} ${lvl}
页面应该包含文本
[Arguments] ${locator} ${lvl}=INFO
Page Should Contain Text ${locator} ${lvl}
页面截图
[Arguments] ${filename}=
Capture Page Screenshot ${filename}
本文转自:<https://blog.csdn.net/jasonliujintao/article/details/53419258>
RobotFramework AppiumLibrary 用户关键字的更多相关文章
- robotframework之用户关键字的用法
robotframework是一个关键字驱动框架,核心在于关键字的应用 目录 1.如何创建用户关键字 2.调用用户关键字 3.用户关键字的使用场景 1.如何创建关键字 第一种:直接在项目上右键,添加用 ...
- AppiumLibrary用户关键字
*** Settings *** Library AppiumLibrary Library AutoItLibrary Library os *** Keywords *** xpath应该匹配次数 ...
- RobotFramework - AppiumLibrary 之关键字Open Application使用
- robotframework用户关键字创建过程
robotframework是一个关键字驱动框架,核心在于关键字的应用.系统本身通过各种库自带了大量关键字,同时支持用户自定义关键字.关键字可以简单理解为各种处理数据的方法. 关键字区别与用户参数. ...
- Robot Framework--06 用户关键字User Keyword
转自:http://blog.csdn.net/tulituqi/article/details/7906130 在我们做自动化案例的时候,用的最多的主要是用户关键字.说到关键字,大体上可以分为测试库 ...
- Robot Framework学习笔记(九)------创建资源和用户关键字
一.测试套件下创建用户关键字 1.创建关键字测试套件右击->点击new user keyword,然后输入name,点击OK保存. 2.在用户关键字的edit点击settings,然后输入Arg ...
- Robot framework(RF) 用户关键字
3.6 用户关键字 在Robot Framework 中关键字的创建分两种:系统关键字和用户关键字. 系统关键字是需要通过脚本开发相应的类和方法,从而实现某一逻辑功能. 用户关键字是根据业务的需求利 ...
- Robot Framework(用户关键字)
在 Robot Framework 中关键字的创建分两种:系统关键字和用户关键字.系统关键字需要通过脚本开发相应的类和方法,这个我们将在后面的章节介绍.用户关键字的创建就要简单得多,它主要利用现有的系 ...
- Robot Framework(七)创建用户关键字
2.6创建用户关键字 关键字表用于通过将现有关键字组合在一起来创建新的更高级别关键字.这些关键字称为用户关键字,以区别于 测试库中实现的最低级库关键字.创建用户关键字的语法与创建测试用例的语法非常接近 ...
随机推荐
- CF1063B Labyrinth
大家一起膜Rorshach. 一般的$bfs$会造成有一些点访问不到的情况,在$system\ test$的时候会$WA40$(比如我……). 发现这张地图其实是一个边权只有$0/1$的图,我们需要计 ...
- Java中常见设计模式面试
一.设计模式的分类 总体来说设计模式分为三大类: 创建型模式,共五种:工厂方法模式.抽象工厂模式.单例模式.建造者模式.原型模式. 结构型模式,共七种:适配器模式.装饰器模式.代理模式.外观模式.桥接 ...
- [坑]Linux MySQL环境表名默认区分大小写
不区分大小写设置 1.用ROOT登录,修改/etc/my.cnf 2.在[mysqld]下加入一行:lower_case_table_names=1 3.重新启动数据库即可 systemctl res ...
- c# 汉字换英文,英文转汉字
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- NHibernate NHibernate使用时误区
NHibernate使用时误区 一.异常: 出现org.hibernate.StaleStateException: Unexpected row count: 0 expected: 1异常的原因: ...
- c语言——数组指针和通过指针引用数组元素的方法总结
1.数组指针:即指向数组的指针 那么, 如何声明一个数组指针呢?int (* p)[10]; /*括号是必须写的,不然就是指针数组:10是数组的大小*/1拓展:有指针类型元素的数组称为指针数组. 2. ...
- 查看ip常见命令...
1.获取ip Unix用户可以在命令提示符中输入ifconfig来获取. 使用Windows的用户,请尝试使用 ipconfig 命令.
- P4177 [CEOI2008]order 最小割
\(\color{#0066ff}{ 题目描述 }\) 有N个工作,M种机器,每种机器你可以租或者买过来. 每个工作包括若干道工序,每道工序需要某种机器来完成,你可以通过购买或租用机器来完成. 现在给 ...
- P4213 【模板】杜教筛(Sum)
\(\color{#0066ff}{题 目 描 述}\) 给定一个正整数\(N(N\le2^{31}-1)\) 求 \(\begin{aligned} ans_1=\sum_{i=1}^n\varph ...
- NOIp 2018 货币系统 贪心
题目描述 在网友的国度中共有 nnn 种不同面额的货币,第 iii 种货币的面额为 a[i]a[i]a[i],你可以假设每一种货币都有无穷多张.为了方便,我们把货币种数为 nnn.面额数组为 a[1. ...