提交 b8557693 编写于 作者: taohebin@dcloud.io's avatar taohebin@dcloud.io

update: 补充部分ext-api的自动化测试

上级 8f325407
const PAGE_PATH = '/pages/API/download-file/download-file'
describe('ExtApi-DownloadFile', () => {
let page;
let res;
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
await page.callMethod('jest_downloadFile');
await page.waitFor(500);
res = await page.data('jest_result');
});
it('Check ', async () => {
expect(res).toBe(true);
});
});
......@@ -27,7 +27,9 @@ export default {
title: 'downloadFile',
imageSrc: '',
task: null as DownloadTask | null,
pageVisible: false
pageVisible: false,
//自动化测试例专用
jest_result: false
}
},
onLoad() {
......@@ -66,6 +68,18 @@ export default {
console.log("progress : ", update.progress);
}
})
},
//自动化测试例专用
jest_downloadFile(){
uni.downloadFile({
url: "https://web-assets.dcloud.net.cn/unidoc/zh/uni-app.png",
success() {
this.jest_result = true
},
fail: () => {
this.jest_result = false
}
});
}
}
}
......
const PAGE_PATH = '/pages/API/get-app-authorize-setting/get-app-authorize-setting'
describe('ExtApi-GetAppAuthorizeSetting', () => {
let page;
let res;
let commonSupportList = [
'authorized', 'denied', 'not determined', 'config error'
]
let locationAccuracySupportList = [
'reduced', 'full', 'unsupported'
]
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
res = await uni.getAppAuthorizeSetting();
});
it('Check cameraAuthorized', async () => {
expect(commonSupportList).toContain(res.cameraAuthorized)
});
it('Check locationAuthorized', async () => {
expect(commonSupportList).toContain(res.locationAuthorized)
});
it('Check locationAccuracy', async () => {
expect(locationAccuracySupportList).toContain(res.locationAccuracy)
});
it('Check microphoneAuthorized', async () => {
expect(commonSupportList).toContain(res.microphoneAuthorized)
});
it('Check notificationAuthorized', async () => {
expect(commonSupportList).toContain(res.notificationAuthorized)
});
});
const PAGE_PATH = '/pages/API/get-app-base-info/get-app-base-info'
describe('ExtApi-GetAppBaseInfo', () => {
let page;
let res;
const stringProperties = [
'appId', 'appName', 'appVersion', 'appVersionCode', 'appLanguage',
'language', 'version', 'uniCompileVersion', 'uniPlatform', 'uniRuntimeVersion',
]
const numberProperties = [
'uniCompileVersionCode', 'uniRuntimeVersionCode'
]
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
res = await uni.getAppBaseInfo();
});
it('Check properties', async () => {
for (const key in res) {
const value = res[key];
expect(value).not.toBeNull();
if (stringProperties.indexOf(key) != -1) {
expect(value).not.toBe("");
}
if (numberProperties.indexOf(key) != -1) {
expect(value).toBeGreaterThanOrEqual(3.90);
}
}
});
});
const PAGE_PATH = '/pages/API/get-device-info/get-device-info'
describe('ExtApi-GetDeviceInfo', () => {
let page;
let res;
const stringProperties = [
'brand', 'deviceBrand', 'deviceId', 'model', 'deviceModel',
'deviceType', 'devicePixelRatio', 'system', 'platform', 'uniRuntimeVersion',
]
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
res = await uni.getDeviceInfo();
});
it('Check properties', async () => {
for (const key in res) {
const value = res[key];
expect(value).not.toBeNull();
if (stringProperties.indexOf(key) != -1) {
expect(value).not.toBe("");
}
if (key == 'deviceOrientation') {
expect(['portrait', 'landscape']).toContain(value);
}
}
});
});
const PAGE_PATH = '/pages/API/get-network-type/get-network-type'
describe('ExtApi-GetNetworkType', () => {
let page;
let res;
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
await page.callMethod('jest_getNetworkType');
await page.waitFor(200);
res = await page.data('jest_result');
});
it('Check ', async () => {
expect(res).toBe(true);
});
});
......@@ -27,7 +27,9 @@
hasNetworkType: false,
networkType: '',
connectedWifi: '',
pageVisible: false
pageVisible: false,
//自动化测试例专用
jest_result:false,
}
},
onLoad() {
......@@ -61,6 +63,17 @@
this.networkType = '';
this.connectedWifi = '';
},
//自动化测试例专用
jest_getNetworkType(){
uni.getNetworkType({
success: () => {
this.jest_result = true;
},
fail: () => {
this.jest_result = false;
}
})
}
}
}
</script>
......
const PAGE_PATH = '/pages/API/get-system-info/get-system-info'
describe('ExtApi-GetSystemInfo', () => {
let page;
let res;
const stringProperties = [
'appId', 'appLanguage', 'appName', 'appVersion', 'appVersionCode',
'brand', 'deviceId', 'deviceBrand', 'deviceModel', 'deviceType', 'language',
'model', 'version', 'osName', 'osVersion', 'osLanguage', 'platform', 'system', 'ua', 'uniCompileVersion',
'uniPlatform', 'uniRuntimeVersion', 'romName', 'romVersion',
]
const numberProperties = [
'osAndroidAPILevel', 'devicePixelRatio', 'pixelRatio', 'screenWidth', 'screenHeight', 'statusBarHeight',
'windowWidth',
'windowHeight', 'windowTop', 'windowBottom', 'screenTop',
'uniCompileVersionCode', 'uniRuntimeVersionCode'
]
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
res = await page.callMethod('jest_getSystemInfo')
});
it('Check GetSystemInfoSync', async () => {
for (const key in res) {
const value = res[key];
expect(value).not.toBeNull();
if (stringProperties.indexOf(key) != -1) {
expect(value).not.toBe("");
}
if (numberProperties.indexOf(key) != -1) {
expect(value).toBeGreaterThanOrEqual(0);
}
if (key == 'deviceOrientation') {
expect(['portrait', 'landscape']).toContain(value);
}
}
});
});
\ No newline at end of file
......@@ -69,7 +69,11 @@ export default {
}
},
})
}
},
//自动化测试例专用
jest_getSystemInfo():GetSystemInfoResult{
return uni.getSystemInfoSync();
},
}
}
</script>
......
const PAGE_PATH = '/pages/API/get-system-setting/get-system-setting'
describe('ExtApi-GetSystemSetting', () => {
let page;
let res;
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
res = await uni.getSystemSetting()
});
it('Check GetSystemSetting', async () => {
for (const key in res) {
const value = res[key];
if (res['bluetoothEnabled'] == undefined) {
expect(res['bluetoothError']).not.toBe("")
} else {
expect(res['bluetoothError'] == undefined).toBe(true)
}
if (res['wifiEnabled'] == undefined) {
expect(res['wifiError']).not.toBe("")
} else {
expect(res['wifiError'] == undefined).toBe(true)
}
if (key == 'deviceOrientation') {
expect(['portrait', 'landscape']).toContain(value);
}
}
});
});
const PAGE_PATH = '/pages/API/get-window-info/get-window-info'
describe('ExtApi-GetWindowInfo', () => {
let page;
let res;
const numberProperties = [
'pixelRatio', 'screenWidth', 'screenHeight', 'statusBarHeight',
'windowWidth',
'windowHeight', 'windowTop', 'windowBottom', 'screenTop'
]
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
res = await page.callMethod('jest_getWindowInfo')
});
it('Check GetWindowInfo', async () => {
for (const key in res) {
const value = res[key];
expect(value).not.toBeNull();
if (numberProperties.indexOf(key) != -1) {
expect(value).toBeGreaterThanOrEqual(0);
}
}
});
});
......@@ -47,7 +47,11 @@
this.items.push(item);
}
}
}
},
//自动化测试例专用
jest_getWindowInfo():GetWindowInfoResult{
return uni.getWindowInfo();
},
}
}
</script>
......
const PAGE_PATH = '/pages/API/request/request'
const methodMap = {
"GET": "/api/http/method/get",
"POST": "/api/http/method/post",
"PUT": "/api/http/method/put",
"DELETE": "/api/http/method/delete",
"PATCH": "/api/http/method/patch",
"OPTIONS": "/api/http/method/options",
"HEAD": "/api/http/method/head"
}
async function request(page, method, header, data, url) {
if (url == null) {
url = methodMap[method]
}
await page.setData({
url: url,
method: method,
data: data,
header: header
})
res = await page.callMethod('jest_request')
await page.waitFor(200);
res = await page.data('jest_result');
expect(res).toBe(true)
}
describe('ExtApi-Request', () => {
let page;
let res;
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
});
beforeEach(async () => {
await page.setData({
jest_result: false,
data: null,
header: null
})
});
it('Check GET', async () => {
await request(page, 'GET');
});
it('Check POST ContentType Json', async () => {
await request(page, 'POST', {
"Content-Type": "application/json"
}, {
"hello": "world"
}, "/api/http/contentType/json");
});
it('Check POST ContentType Form', async () => {
await request(page, 'POST', {
"Content-Type": "application/x-www-form-urlencoded"
}, "hello=world", "/api/http/contentType/xWwwFormUrlencoded");
});
it('Check PUT', async () => {
await request(page, 'PUT');
});
it('Check DELETE', async () => {
await request(page, 'DELETE');
});
it('Check PATCH', async () => {
await request(page, 'PATCH');
});
it('Check OPTIONS', async () => {
await request(page, 'OPTIONS');
});
it('Check HEAD', async () => {
await request(page, 'HEAD');
});
});
......@@ -29,24 +29,23 @@
@click="changeMethod('PATCH')">PATCH</button>
<button style="padding: 5rpx;margin-right: 10rpx;" type="primary" size="mini"
@click="changeMethod('OPTIONS')">OPTIONS</button>
<button style="padding: 5rpx;" type="primary" size="mini"
@click="changeMethod('HEAD')">HEAD</button>
<button style="padding: 5rpx;" type="primary" size="mini" @click="changeMethod('HEAD')">HEAD</button>
</view>
</view>
<view style="padding: 20rpx;">
<text>请求返回错误码的接口(默认为GET)</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in errorCodeUrls"
:key="index" @click="changeUrl(item)">{{item}}</button>
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in errorCodeUrls" :key="index"
@click="changeUrl(item)">{{item}}</button>
</view>
</view>
<view style="padding: 20rpx;">
<text>请求不同header的接口(默认为GET)</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in headerUrls"
:key="index" @click="changeUrl(item)">{{item}}</button>
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in headerUrls" :key="index"
@click="changeUrl(item)">{{item}}</button>
</view>
</view>
<view style="padding: 20rpx;">
......@@ -62,8 +61,8 @@
<text>POST请求(有body)</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in postUrls"
:key="index" @click="changeUrlFromPost(item)">{{item}}</button>
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in postUrls" :key="index"
@click="changeUrlFromPost(item)">{{item}}</button>
</view>
</view>
</scroll-view>
......@@ -131,6 +130,8 @@
"/api/http/contentType/json",
"/api/http/contentType/xWwwFormUrlencoded",
],
//自动化测试例专用
jest_result: false
}
},
onLoad() {
......@@ -214,6 +215,27 @@
uni.hideLoading()
},
});
},
//自动化测试例专用
jest_request() {
uni.request({
url: this.host + this.url,
// dataType: "json",
// responseType: "json",
method: this.method,
data: this.data,
header: this.header,
timeout: 6000,
sslVerify: false,
withCredentials: false,
firstIpv4: false,
success() {
this.jest_result = true;
},
fail() {
this.jest_result = false;
},
});
}
}
}
......
const PAGE_PATH = '/pages/API/upload-file/upload-file'
describe('ExtApi-UploadFile', () => {
let page;
let res;
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
await page.callMethod('jest_uploadFile');
await page.waitFor(500);
res = await page.data('jest_result');
});
it('Check ', async () => {
expect(res).toBe(true);
});
});
......@@ -29,7 +29,9 @@ export default {
title: 'uploadFile',
imageSrc: '',
task: null as UploadTask | null,
pageVisible: false
pageVisible: false,
//自动化测试例专用
jest_result:false,
}
},
onLoad() {
......@@ -88,6 +90,24 @@ export default {
console.log('chooseImage fail', err)
}
})
},
//自动化测试例专用
jest_uploadFile(){
const imageSrc = "/static/uni.png";
this.task = uni.uploadFile({
url: 'https://unidemo.dcloud.net.cn/upload', //仅为示例,非真实的接口地址
filePath: imageSrc,
name: 'file',
formData: {
'user': 'test'
},
success: () => {
this.jest_result = true;
},
fail: () => {
this.jest_result = false;
},
})
}
}
}
......
const PAGE_PATH = '/pages/API/websocket-socketTask/websocket-socketTask'
describe('ExtApi-WebSocket', () => {
let page;
let res;
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
await page.callMethod('jest_connectSocket');
await page.waitFor(500);
res = await page.data('jest_result');
});
it('Check ', async () => {
expect(res).toBe(2);
});
});
......@@ -36,6 +36,8 @@ export default {
msg: '',
platform: '',
pageVisible: false,
//自动化测试例专用
jest_result: 0,
}
},
computed: {
......@@ -163,6 +165,37 @@ export default {
},
} as CloseSocketOptions)
},
//自动化测试例专用
jest_connectSocket(){
this.socketTask = uni.connectSocket({
url: 'ws://websocket.dcloud.net.cn',
success:(_) => {
this.jest_result++
},
fail:(_) => {
this.jest_result = 0
},
})
this.socketTask?.onOpen((_) => {
const data =
'from ' +
this.platform +
' : ' +
parseInt(Math.random() * 10000 + '').toString()
this.socketTask?.send({
data,
success(_) {
this.jest_result++
},
fail(_) {
this.jest_result = 0
},
} as SendSocketMessageOptions)
})
this.socketTask?.onError((_) => {
this.jest_result = 0;
})
}
},
}
</script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册