提交 b951fed7 编写于 作者: zhaofengliang920817's avatar zhaofengliang920817

增加getLocation示例的自动化脚本测试。

上级 46d418ce
const PAGE_PATH = "/pages/API/get-location/get-location";
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isIos = platformInfo.startsWith('ios')
const isApp = isAndroid || isIos
const isWeb = platformInfo.startsWith('web')
describe("get-location", () => {
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600)
});
//system 定位
it("system+type=wgs84+success", async () => {
await page.setData({
jest_provider: 'system',
jest_type: 'wgs84',
jest_isAltitude: true,
jest_isGeocode: false,
jest_isHighAccuracy: false
})
await page.callMethod('jestGetLocation')
await page.waitFor(async () => {
return await page.data('jest_complete') === true;
});
const data = await page.data()
const jest_errCode = data['jest_errCode']
if (jest_errCode > 0) {
expect((await page.data())['jest_errCode']).toEqual(expect.any(Number));
} else {
//判断经纬度是否在正常范围
expect((await page.data())['jest_longitude']).toBeGreaterThanOrEqual(-180);
expect((await page.data())['jest_longitude']).toBeLessThanOrEqual(180);
expect((await page.data())['jest_latitude']).toBeGreaterThanOrEqual(-90);
expect((await page.data())['jest_latitude']).toBeLessThanOrEqual(90);
//判断海拔是否正确
expect((await page.data())['jest_altitude']).toEqual(expect.any(Number));
expect((await page.data())['jest_altitude']).not.toEqual('0');
}
});
//system 定位
it("system+type=wgs84+success+geocode=true", async () => {
await page.setData({
jest_provider: 'system',
jest_type: 'wgs84',
jest_isAltitude: true,
jest_isGeocode: true,
jest_isHighAccuracy: false
})
await page.callMethod('jestGetLocation')
await page.waitFor(async () => {
return await page.data('jest_complete') === true;
});
const data = await page.data()
const jest_errCode = data['jest_errCode']
if (jest_errCode > 0) {
if (isIos) {
expect((await page.data())['jest_errCode']).toEqual(1505603);
} else if (isAndroid) {
expect((await page.data())['jest_errCode']).toEqual(1505700);
} else {
expect((await page.data())['jest_errCode']).toEqual(expect.any(Number));
}
}
});
//system 定位
it("system+type=wgs84+success+altitude=false", async () => {
await page.setData({
jest_provider: 'system',
jest_type: 'wgs84',
jest_isAltitude: false,
jest_isGeocode: true,
jest_isHighAccuracy: false
})
await page.callMethod('jestGetLocation')
await page.waitFor(async () => {
return await page.data('jest_complete') === true;
});
const data = await page.data()
const jest_errCode = data['jest_errCode']
if (jest_errCode > 0) {
//如果定位出错
expect((await page.data())['jest_errCode']).toEqual(expect.any(Number));
} else {
expect((await page.data())['jest_altitude']).toEqual('0');
}
});
//system 定位
it("system+type=gcj02+fail", async () => {
await page.setData({
jest_provider: 'system',
jest_type: 'gcj02',
jest_isAltitude: true,
jest_isGeocode: true,
jest_isHighAccuracy: false
})
await page.callMethod('jestGetLocation')
await page.waitFor(async () => {
return await page.data('jest_complete') === true;
});
expect((await page.data())['jest_errCode']).toEqual(1505601);
});
//tencent 定位
it("tencent+type=gcj02+success", async () => {
await page.setData({
jest_provider: 'tencent',
jest_type: 'gcj02',
jest_isAltitude: true,
jest_isGeocode: true,
jest_isHighAccuracy: true
})
await page.callMethod('jestGetLocation')
await page.waitFor(async () => {
return await page.data('jest_complete') === true;
});
const data = await page.data()
const jest_errCode = data['jest_errCode']
if (jest_errCode > 0) {
//如果定位出错
expect((await page.data())['jest_errCode']).toEqual(expect.any(Number));
} else {
//判断逆地理编码是否正确
expect((await page.data())['jest_address']).toEqual(expect.any(String));
//判断经纬度是否在正常范围
expect((await page.data())['jest_longitude']).toBeGreaterThanOrEqual(-180);
expect((await page.data())['jest_longitude']).toBeLessThanOrEqual(180);
expect((await page.data())['jest_latitude']).toBeGreaterThanOrEqual(-90);
expect((await page.data())['jest_latitude']).toBeLessThanOrEqual(90);
//判断海拔是否正确
expect((await page.data())['jest_altitude']).toEqual(expect.any(Number));
expect((await page.data())['jest_altitude']).not.toEqual('0');
}
});
//tencent 定位
it("tencent+type=wgs84+fail", async () => {
await page.setData({
jest_provider: 'tencent',
jest_type: 'wgs84',
jest_isAltitude: true,
jest_isGeocode: true,
jest_isHighAccuracy: true
})
await page.callMethod('jestGetLocation')
await page.waitFor(async () => {
return await page.data('jest_complete') === true;
});
if (isApp) {
expect((await page.data())['jest_errCode']).toEqual(1505607);
}
});
});
......@@ -79,7 +79,18 @@
] as ItemType[],
providerList: [] as LocationItem[],
current: 0,
currentProvider: 0
currentProvider: 0,
jest_provider: String,
jest_type: String,
jest_isAltitude: Boolean,
jest_isGeocode: Boolean,
jest_isHighAccuracy: Boolean,
jest_altitude: Number,
jest_longitude: Number,
jest_latitude: Number,
jest_address: String,
jest_errCode: Number,
jest_complete: Boolean
}
},
onLoad: function () {
......@@ -177,24 +188,44 @@
geocode: this.geocodeSelect,
success: (res : any) => {
uni.hideLoading()
console.log(res);
this.exeRet = JSON.stringify(res)
},
fail: (res : any) => {
uni.hideLoading()
console.log(res);
this.exeRet = JSON.stringify(res)
},
complete: (res : any) => {
uni.hideLoading()
console.log(res);
this.exeRet = JSON.stringify(res)
}
}));
},
// 仅用于自动化测试
jestGetLocation() {
this.jest_complete = false
this.jest_errCode = 0
uni.getLocation(({
// #ifdef APP
provider: this.jest_provider,
// #endif
type: this.jest_type,
altitude: this.jest_isAltitude,
isHighAccuracy: this.jest_isHighAccuracy,
geocode: this.jest_isGeocode,
success: (res : any) => {
this.jest_address = res.address
this.jest_longitude = res.longitude
this.jest_latitude = res.latitude
this.jest_altitude = res.altitude
this.jest_complete = true
},
fail: (err : any) => {
this.jest_errCode = err.errCode
this.jest_complete = true
}
}));
}
}
}
</script>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册