提交 6e1e078f 编写于 作者: W wan201809

update docs/collocation/auto/quick-start.md

上级 f39734b7
......@@ -15,10 +15,11 @@
1. 本插件支持`uni-app普通项目``uniapp-cli项目`。uniapp-cli项目,运行自动化测试,需要在当前项目下安装自动化测试依赖。
2. Windows电脑不支持运行测试到`ios手机`
3. MacOSX电脑,仅支持运行测试到`ios模拟器`,不支持ios真机
3. MacOSX电脑,仅支持运行测试到`iOS模拟器`,不支持ios真机,测试iOS模拟器,需要电脑装安装XCode
4. 运行测试到H5,仅支持`chrome`浏览器,不支持其它浏览器。
5. 运行测试到Android手机,如果HBuilderX仅检测到一个android设备,直接运行测试到当前已连接设备。多个设备时,会弹窗要求选择手机。
5. 运行测试到Android手机,如果HBuilderX仅检测到一个android设备,`直接`运行测试到当前已连接设备。`多个`设备时,会弹窗要求选择手机。
6. node: 当本机未安装node时,将使用HBuilderX`内置node`运行测试。反之,本机安装了node,则使用本机的node。
7. 运行测试到微信小程序,必须在manifest.json内,配置微信小程序 appid。如果微信开发者工具无法成功打开项目,首次请手动打开。
## 插件安装@test-install
......
......@@ -33,3 +33,100 @@ uni-app提供了一批[API](/collocation/auto/api),这些API可以操控uni-ap
插件简化了测试环境安装、测试用例创建、测试运行、测试设备选择等步骤。[插件使用文档](/collocation/auto/hbuilderx-extension/index)
### jest.config.js@jestconfigjs
jest.config.js文件,为测试配置文件,详细内容如下:
```
module.exports = {
globalTeardown: '@dcloudio/uni-automator/dist/teardown.js',
testEnvironment: '@dcloudio/uni-automator/dist/environment.js',
testEnvironmentOptions: {
compile: true,
h5: { // 为了节省测试时间,可以指定一个 H5 的 url 地址,若不指定,每次运行测试,会先 npm run dev:h5
url: "http://192.168.x.x:8080/h5/",
options: {
headless: false // 配置是否显示 puppeteer 测试窗口
}
},
"app-plus": { // 需要安装 HBuilderX
android: {
executablePath: "HBuilderX/plugins/launcher/base/android_base.apk" // apk 目录
},
ios: {
// uuid 必须配置,目前仅支持模拟器,可以(xcrun simctl list)查看要使用的模拟器 uuid
id: "",
executablePath: "HBuilderX/plugins/launcher/base/Pandora_simulator.app" // ipa 目录
}
},
"mp-weixin": {
port: 9420, // 默认 9420
account: "", // 测试账号
args: "", // 指定开发者工具参数
cwd: "", // 指定开发者工具工作目录
launch: true, // 是否主动拉起开发者工具
teardown: "disconnect", // 可选值 "disconnect"|"close" 运行测试结束后,断开开发者工具或关闭开发者工具
remote: false, // 是否真机自动化测试
executablePath: "", // 开发者工具cli路径,默认会自动查找, windows: C:/Program Files (x86)/Tencent/微信web开发者工具/cli.bat", mac: /Applications/wechatwebdevtools.app/Contents/MacOS/cli
},
"mp-baidu": {
port: 9430, // 默认 9430
args: "", // 指定开发者工具参数
cwd: "", // 指定开发者工具工作目录
launch: true, // 是否主动拉起开发者工具
teardown: "disconnect", // 可选值 "disconnect"|"close" 运行测试结束后,断开开发者工具或关闭开发者工具
remote: false, // 是否真机自动化测试
executablePath: "", // 开发者工具cli路径,默认会自动查找
}
},
testTimeout: 15000,
reporters: [
'default'
],
watchPathIgnorePatterns: ['/node_modules/', '/dist/', '/.git/'],
moduleFileExtensions: ['js', 'json'],
rootDir: __dirname,
testMatch: ['<rootDir>/src/**/*test.[jt]s?(x)'], // 测试文件目录
testPathIgnorePatterns: ['/node_modules/']
}
```
**注意事项**
1. 如果页面涉及到分包加载问题,`reLaunch` 获取的页面路径可能会出现问题 ,解决方案如下 :
```javascript
// 重新 reLaunch至首页,并获取 page 对象(其中 program 是 uni-automator 自动注入的全局对象)
page = await program.reLaunch('/pages/extUI/calendar/calendar')
// 微信小程序如果是分包页面,需要延迟大概 7s 以上,保证可以正确获取page对象
await page.waitFor(7000)
page = await program.currentPage()
```
2. 微信小程序 element 不能跨组件选择元素,首先要先获取当前组件,再继续查找
```html
<uni-tag>
<view class="test"></view>
</uni-tag>
```
```javascript
// 错误,取不到元素
await page.$('.test')
// 可以取到元素
let tag = await page.$('uni-tag')
await tag.$('.test')
```
3. 微信小程序暂不支持父子选择器
4. 百度小程序选择元素必须有事件的元素才能被选中,否则提示元素不存在
5. 分包中的页面,打开之后要延迟时间长一点,否则不能正确获取到页面信息
### 测试示例
GitHub: [https://github.com/dcloudio/hello-uniapp](https://github.com/dcloudio/hello-uniapp)
\ No newline at end of file
......@@ -239,97 +239,4 @@ describe('pages/API/set-navigation-bar-title/set-navigation-bar-title.vue', () =
更多测试示例见: hello uni-app
GitHub: [https://github.com/dcloudio/hello-uniapp](https://github.com/dcloudio/hello-uniapp)
#### jest.config.js
```
module.exports = {
globalTeardown: '@dcloudio/uni-automator/dist/teardown.js',
testEnvironment: '@dcloudio/uni-automator/dist/environment.js',
testEnvironmentOptions: {
compile: true,
h5: { // 为了节省测试时间,可以指定一个 H5 的 url 地址,若不指定,每次运行测试,会先 npm run dev:h5
url: "http://192.168.x.x:8080/h5/",
options: {
headless: false // 配置是否显示 puppeteer 测试窗口
}
},
"app-plus": { // 需要安装 HBuilderX
android: {
executablePath: "HBuilderX/plugins/launcher/base/android_base.apk" // apk 目录
},
ios: {
// uuid 必须配置,目前仅支持模拟器,可以(xcrun simctl list)查看要使用的模拟器 uuid
id: "",
executablePath: "HBuilderX/plugins/launcher/base/Pandora_simulator.app" // ipa 目录
}
},
"mp-weixin": {
port: 9420, // 默认 9420
account: "", // 测试账号
args: "", // 指定开发者工具参数
cwd: "", // 指定开发者工具工作目录
launch: true, // 是否主动拉起开发者工具
teardown: "disconnect", // 可选值 "disconnect"|"close" 运行测试结束后,断开开发者工具或关闭开发者工具
remote: false, // 是否真机自动化测试
executablePath: "", // 开发者工具cli路径,默认会自动查找, windows: C:/Program Files (x86)/Tencent/微信web开发者工具/cli.bat", mac: /Applications/wechatwebdevtools.app/Contents/MacOS/cli
},
"mp-baidu": {
port: 9430, // 默认 9430
args: "", // 指定开发者工具参数
cwd: "", // 指定开发者工具工作目录
launch: true, // 是否主动拉起开发者工具
teardown: "disconnect", // 可选值 "disconnect"|"close" 运行测试结束后,断开开发者工具或关闭开发者工具
remote: false, // 是否真机自动化测试
executablePath: "", // 开发者工具cli路径,默认会自动查找
}
},
testTimeout: 15000,
reporters: [
'default'
],
watchPathIgnorePatterns: ['/node_modules/', '/dist/', '/.git/'],
moduleFileExtensions: ['js', 'json'],
rootDir: __dirname,
testMatch: ['<rootDir>/src/**/*test.[jt]s?(x)'], // 测试文件目录
testPathIgnorePatterns: ['/node_modules/']
}
```
**注意事项**
1. 如果页面涉及到分包加载问题,`reLaunch` 获取的页面路径可能会出现问题 ,解决方案如下 :
```javascript
// 重新 reLaunch至首页,并获取 page 对象(其中 program 是 uni-automator 自动注入的全局对象)
page = await program.reLaunch('/pages/extUI/calendar/calendar')
// 微信小程序如果是分包页面,需要延迟大概 7s 以上,保证可以正确获取page对象
await page.waitFor(7000)
page = await program.currentPage()
```
2. 微信小程序 element 不能跨组件选择元素,首先要先获取当前组件,再继续查找
```html
<uni-tag>
<view class="test"></view>
</uni-tag>
```
```javascript
// 错误,取不到元素
await page.$('.test')
// 可以取到元素
let tag = await page.$('uni-tag')
await tag.$('.test')
```
3. 微信小程序暂不支持父子选择器
4. 百度小程序选择元素必须有事件的元素才能被选中,否则提示元素不存在
5. 分包中的页面,打开之后要延迟时间长一点,否则不能正确获取到页面信息
GitHub: [https://github.com/dcloudio/hello-uniapp](https://github.com/dcloudio/hello-uniapp)
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册