使用方法
- 获取模拟器 1.3 版本
开启模拟器的 debug 功能
- 在 resources/cfg.json 中开启 debugger.enable true
"debugger": {
"enable": true,
"port_devtool": 9307,
"port_httpd": 5556
},
- 在 resources/cfg.json 中开启 debugger.enable true
准备示例程序
// 解压测试程序
cd test-engine-example
cnpm install
// 启动模拟器,配置模拟器请参考官方文档
aiot-cli simulator
- 使用 postman 发送测试请求
地址端口号 http://localhost:5566/TE/<方法名称>
所有请求均使用 POST JSON 格式,地址格式为 RESTful 形式
postman 下载 https://www.postman.com/downloads
通用P0
getElementById
功能:获取指定属性的对象,便于后续指令的操作,用于定位元素
入参:{“id”: “text-id0”}
出参:{“ref”: “2”, “ret”: 0, “type”: “text”}
isDisplayed
功能:是否显示,判断某个元素是否显示出来了
入参:{“ref”: “2”}
出参:{“ret”: 1}
如果ret == 0, 则是未显示,如果是1则是显示
isEnable
功能:是否可操作,比如文本框可以输入内容,选择框可以选择等
入参:{“ref”: “2”}
出参:{“ret”: 0}
如果ret==0 则是禁用状态,如果是1则是非禁用
shot
功能:截图功能,截取当前页面图片并且进行保存,返回图片地址
入参:
出参:
与HTTP attachment 协议传输文件相同
Content-Disposition: attachment; filename=shot.png
click
功能:点击组件,激活组件
入参:{“ref”: “2”}
出参:{“ret”: 0} //成功
衍生通用接口
getStyles
功能:获取某元素的样式集合
入参:{“ref”: “2”}
出参:{“styles”: {“color”: “#41b883”, “fontSize”: “50px”, “marginTop”: “20px”, “textAlign”: “center”}}
getAttrs
功能:获取某元素的属性集合
入参:{“ref”: “2”}
出参:{“attrs”: {“disabled”: “1”, “id”: “text-id0”, “value”: “Hello, falcon!”}}
hasFocus
功能:检查某元素是否是 focus 状态
入参:{“ref”: “4”}
出参:{“ret”: 0, “focus”: true}
requestFocus
功能:请求将某元素设置为 focus 状态,如果是 input 控件则会随之弹出系统内置键盘
入参:{“ref”: 4}
出参:{“ret”: 0} // 成功,其他失败
clearFocus
功能:请求将某元素清楚 focus 状态,如果是 input 控件则内置键盘会收起
入参:{“ref”: 4}
出参:{“ret”: 0} // 执行成功
getChildren
功能:获取某父元素的直接元素信息列表
入参:{“ref”: 2}
出参:{“children”: [{“attrs”: {“id”: “main_scroller_id”}, “ref”: “3”, “styles”: {“borderRadius”: “4px”, “boxShadow”: “0px 0px 5px #646566”, “color”: “#41b883”, “fontSize”: “36px”, “marginBottom”: “10px”, “marginLeft”: “10px”, “marginRight”: “10px”, “marginTop”: “10px”, “paddingBottom”: “10px”, “paddingLeft”: “40px”, “paddingRight”: “40px”, “paddingTop”: “10px”, “textAlign”: “center”}}, …], “ret”: 0}
页面接口
navToApp
功能:跳转到指定app
入参:{“appName”: “8001640835868573”, “pageName”: “index”, options: {}}
出参:{“ret”: 0} // 成功
navToPage
功能:跳转到当前app的指定页面
入参:{“pageName”: “index”, “pageOptions”: {}, options: {}}
pageOptions 是页面带参
options 为系统中页面切换的系统参数,比如过渡动画之类的
出参:{“ret”: 0} // 成功
getUrl
功能:获取当前页面信息
入参:无
出参:{“appName”: “8001640835868573”, “pageName”: “index”}
scroller控件接口
scrollToBegin
功能:滚动到开始(横竖)
入参:{“ref”: 3}
出参:{“ret”: 0} // 成功
scrollToEnd
功能:滚动到结束(横竖)
入参:{“ref”: 3}
出参:{“ret”: 0} // 成功
scrollLeft
功能:横向滚动,左偏移
入参:{“ref”: 3, “value”: 20}
出参:{“ret”: 0} // 成功
scrollTop
功能:竖向滚动,上偏移
入参:{“ref”: 3, “value”: 20}
出参:{“ret”: 0} // 成功
�getScrollXY
�功能:获取元素的滚动偏移
入参:{“ref”: 3}
出参:{“scrollX”: 200, “scrollY”: 0, ret: 0}
text 控件接口
getTextValue
功能:获取 text 控件的文字
入参:{“ref”: 2}
出参:{“ret”: 0, “value”: “Hello, falcon!”}
input 控件接口
getInputValue
功能:获取 input 值
入参:{“ref”: “4”}
出参:{“ret”: 0, “value”: “test text”}
setInputValue
功能:设置 input 值
入参:{“ref”: “4”, “value”: “changed text”}
出参:{“ret”: 0}
sendInputText
功能:向 focus 状态的 input 控件发送字符
准入:先调用 requestFocus 获取 input 控件的聚焦
入参:{“ref”: “4”, “text”: “abc”}
出参:{“ret”: 0}
image 控件接口
getImageSrc
功能:获取 image 控件的 src 值
入参:{“ref”: “5”}
出参:{“ret”: 0, “src”: “images/9b2da446feccf41249e6f57419dd9c74.png”}
slider 控件接口
getSliderLength
功能:获取 slider 控件的内容长度
入参:{“ref”: 6}
出参:{“ret”: 0, “length”: 5}
slideTo
功能:滑动 slider 控件到指定内容 index
入参:{“ref”: 6, “index”: 2}
出参:{“ret”: 0} // 成功