后悔也要看Maestro教程


一 首先 maestro 是什么?

maestro 是, Appium, Espresso, UIAutomator, XCTest)

用什么作用呢 可以查看 maestro简介

二 maestro 功能/使用

点击事件

断言

滑动/滚动

后退事件

输入文本

键盘

截屏

打开链接

应用命令

应用声明周期

进阶内容-嵌套

进阶内容-等待

进阶内容-循环

进阶内容-条件

进阶内容-参数/常量



三 maestro 实例案例

场景的手机屏幕的操作

点击,输入, 滑动, 后退, 系统自带的事件(HOME Back...)

常见的点击操作
	点击一下
		- tapOn
	长按
		- longPressOn
	试图切换
		找到hello 试图,点击到第二个图层
		- tapOn:
		text: Hello
		index: 2

处理同一个/试图切换 假设条件只允许点击一次
- tapOn:
text: "Something"
retryTapIfNoChange: false

点击操作 通用的事件背后的实施

	text: "Text"# (optional) Finds text that matches regexp
  id: "id"# (optional) Finds id that matches regexp
  index: 0# (optional) 0-based index of the view to select among those that 
  width: 100# (optional) Finds element of a given width
  height: 100# (optional) Finds element of a given height
  tolerance: 10# (optional) Tolerance to apply when comparing width and height
  enabled: true# (optional) Searches for view with a given "enabled" state
  optional: false# (default: false) If set to true, test won't fail if view 
--------------------------------------------------------------------------		
- tapOn:
below: "View above that has this text"# This will match view *above* that has 
above:
id: "view_below_id"# This will match a view *below* that has the 
leftOf: "View to the right has this text"
rightOf: "View to the left has this text"
containsChild: "Text in a child view"# This will match a view that has a 
---------------------------------------------------------
- tapOn:
point: 100,200# This command will tap on point x:100 y:200 on the screen (in 

长长的按住

- longPressOn: Text
- longPressOn:
id: view_id
- longPressOn:
point: 100,200

断言

	assertVisible
- assertVisible:
# Same exact parameters as in Tap On View
	assertNotVisible	
- assertNotVisible:
# Same exact parameters as in Tap On View

滚动/滑动

- scroll	
- swipe:
start: 100, 200
end: 300, 400

输入文本

	Input text 输入文字
	- inputText: "Hello World"
	- inputRandomEmail输入随机邮箱
	- inputRandomPersonName随机人名字/字符串
	- inputRandomNumber随机整数
	- inputRandomText随机非结构化文本
	- eraseText 删除文字
		- eraseText: 100
打开键盘
	- hideKeyboard
隐藏键盘
	- clipboardPaste

手机系统默认-按钮

- pressKey: Enter确定/输入
- pressKey:home - 主页按钮
- pressKey:lock -锁屏按钮
- pressKey:enter -回车按钮
- pressKey:backspace -退格键/删除文字
- pressKey:volume up / volume down 控制音量
- pressKey:back -后退

录像/截屏

	- takeScreenshot: MainScreen储存为图片-
打开地址
	- openLink: https://example.com

四 maestro 上手

可见断言

appId: com.example.app
---
-assertVisible:
id: "element_id"
- assertVisible:
  text: "Element Text"
- assertVisible:
  width: 100
  height: 100
- assertVisible:
  id: "element_id"
- assertVisible:
  text: "Element Text"

top_on

appId: com.example.app
---
-tapOn:
text: ".*button.*"

skip

appId: com.example.app
---
- tapOn:
  text: "Optional Element"
  optional: true
- assertVisible:
  text: "Non Optional"
  optional: false

scroll

appId: com.example.app
---
- action: scroll

back

appId: com.example.app
---
- action: back

inputText

appId: com.example.app
---
- inputText: "Hello World"
- inputText: user@example.com

launchApp

appId: com.example.app
---
- launchApp








文章为作者独立观点,不代表BOSS直聘立场。未经账号授权,禁止随意转载。