提交 cf2f542e 编写于 作者: 杜庆泉's avatar 杜庆泉

获取电量/storage 增加自动化测试示例

上级 96f630a6
const PAGE_PATH = '/pages/API/get-battery-info/get-battery-info'
describe('ExtApi-GetBatteryInfo', () => {
let page;
let res;
const numberProperties = [
'level'
]
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
res = await uni.getBatteryInfo();
});
it('Check properties', async () => {
for (const key in res) {
const value = res[key];
expect(value).not.toBeNull();
if (numberProperties.indexOf(key) != -1) {
expect(value).toBeGreaterThanOrEqual(0.1);
}
}
});
});
const PAGE_PATH = '/pages/API/storage/storage'
describe('ExtApi-StorageInfoTest', () => {
let page;
function getData(key = '') {
return new Promise(async (resolve, reject) => {
const data = await page.data()
resolve(key ? data[key] : data)
})
}
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
});
it('Check properties', async () => {
await page.setData({
key: "autotest_key_mock",
data:"长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。"
})
await page.waitFor(600)
const btnSetStorageButtonInfo = await page.$('.btn-setstorageAsync')
await btnSetStorageButtonInfo.tap()
await page.waitFor(600)
const btnGetStorageButtonInfo = await page.$('.btn-getstorageAsync')
await btnGetStorageButtonInfo.tap()
await page.waitFor(600)
expect(await getData('apiGetData')).toEqual("长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。")
});
});
......@@ -84,12 +84,12 @@
<view class="uni-btn-v">
<button
type="primary"
class="uni-btn btn-setstorage"
class="uni-btn btn-setstorageAsync"
@tap="setStorage"
>
存储数据-异步
</button>
<button class="uni-btn" @tap="getStorage">读取数据-异步</button>
<button class="uni-btn btn-getstorageAsync" @tap="getStorage">读取数据-异步</button>
<button class="uni-btn" @tap="removeStorage">移除数据-异步</button>
<button class="uni-btn" @tap="clearStorage">清理数据-异步</button>
</view>
......@@ -124,6 +124,7 @@ export default {
title: 'get/set/clearStorage',
key: '',
data: '' as any,
apiGetData:'' as any|null,
storageInfo: '',
}
},
......@@ -190,12 +191,14 @@ export default {
showCancel: false,
})
} else {
let that = this
uni.getStorage({
key: key,
success: (res) => {
that.apiGetData = res.data
uni.showModal({
title: '读取数据成功',
content: "data: '" + JSON.stringify(res.data) + "'",
content: "data: '" + JSON.stringify(that.apiGetData) + "'",
showCancel: false,
})
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册