提交 0e868417 编写于 作者: 雪洛's avatar 雪洛

test: 测试与示例适配微信小程序

上级 230d88b1
......@@ -54,12 +54,15 @@ describe('nodes-info', () => {
expect(Math.round(nodeInfo2.width)).toBe(RECT_WIDTH)
expect(Math.round(nodeInfo2.height)).toBe(RECT_HEIGHT)
})
if(!isMP) {
// 小程序端启用了虚拟host,无法获取到子组件
it('get-node-info-child', async () => {
const child = await page.$('.node-child')
const childData = await child.data()
console.log('get-node-info-child.childData.top', childData.top);
expect(childData.top > 100).toBe(true)
})
}
it('multi-child', async () => {
const pageData = await page.data()
......
......@@ -2,6 +2,11 @@ const PAGE_PATH = "/pages/API/get-element-by-id/get-element-by-id";
let page;
describe("getElementById", () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isIOS = platformInfo.startsWith('ios')
const isMP = platformInfo.startsWith('mp')
const isWeb = platformInfo.startsWith('web')
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH);
await page.waitFor('view');
......@@ -11,7 +16,7 @@ describe("getElementById", () => {
expect(res).toBe(null);
});
it("changeStyle", async () => {
if (!process.env.uniTestPlatformInfo.startsWith('mp')) {
if (!isMP) {
await page.callMethod("changePageHeadBackgroundColor");
}
await page.callMethod("changeTextColor");
......@@ -20,6 +25,10 @@ describe("getElementById", () => {
const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot();
});
if(isMP) {
return
}
/**
* 检测元素offsetLeft属性值域
*/
......
......@@ -3,9 +3,12 @@ const PAGE_PATH = '/pages/API/get-file-system-manager/get-file-system-manager'
describe('ExtApi-FileManagerTest', () => {
if (process.env.uniTestPlatformInfo.indexOf('web') > -1 || process.env.UNI_AUTOMATOR_APP_WEBVIEW ==
'true') {
it('dummyTest', () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isIOS = platformInfo.startsWith('ios')
const isMP = platformInfo.startsWith('mp')
const isWeb = platformInfo.startsWith('web')
if (isWeb || process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true') {
it('not support', () => {
expect(1).toBe(1)
})
return
......@@ -91,7 +94,7 @@ describe('ExtApi-FileManagerTest', () => {
mkdirFile: 'a/b/c'
})
if (!isMP) {
await btnMkdDirButton.tap()
await isDone()
......@@ -102,6 +105,7 @@ describe('ExtApi-FileManagerTest', () => {
let lastCompleteError = await getData('lastCompleteError')
expect(lastCompleteError.errCode).toEqual(1300002)
expect(lastCompleteError.errMsg).toEqual('no such file or directory')
}
// 测试 recursive = true 期望文件夹创建成功
......@@ -220,6 +224,10 @@ describe('ExtApi-FileManagerTest', () => {
expect(JSON.stringify(fileListSuccess)).toEqual("[\"1.txt\",\"3.txt\",\"b\"]")
});
if (isMP) {
// 如下大量测试是对非USER_DATA_PATH的测试,后续有机会再行整理
return
}
it('TEMP_PATH test', async () => {
// 测试 TEMP_PATH
let globalTempPath = await getData('globalTempPath')
......@@ -385,7 +393,7 @@ describe('ExtApi-FileManagerTest', () => {
await page.setData({
getFileInfoAlgorithm: "sha256"
})
if (!isMP) {
await btnGetFileInfoButton.tap()
await isDone()
......@@ -393,6 +401,7 @@ describe('ExtApi-FileManagerTest', () => {
expect(lastFailError.errCode).toEqual(1300022)
let lastCompleteError = await getData('lastCompleteError')
expect(lastCompleteError.errCode).toEqual(1300022)
}
// rename 到一个没有提前创建过的目录,期望返回错误
......@@ -401,6 +410,7 @@ describe('ExtApi-FileManagerTest', () => {
renameToFile: "a/没有提前创建的目录/3.txt"
})
if (!isMP) {
const btnRenameFileButton = await page.$('#btn-rename-file')
await btnRenameFileButton.tap()
await isDone()
......@@ -409,6 +419,7 @@ describe('ExtApi-FileManagerTest', () => {
expect(lastFailError.errCode).toEqual(1300002)
lastCompleteError = await getData('lastCompleteError')
expect(lastCompleteError.errCode).toEqual(1300002)
}
// 非递归创建一级目录。期望成功
await page.setData({
......@@ -474,8 +485,6 @@ describe('ExtApi-FileManagerTest', () => {
});
it('CROSS DIR test', async () => {
/**
* 跨越用户目录和代码资源目录
......@@ -1145,7 +1154,7 @@ describe('ExtApi-FileManagerTest', () => {
}
function isAndroid() {
if (process.env.uniTestPlatformInfo.indexOf('web') > -1 || process.env.UNI_AUTOMATOR_APP_WEBVIEW ===
if (isWeb || isMP || process.env.UNI_AUTOMATOR_APP_WEBVIEW ===
'true') {
expect(1).toBe(1)
return false
......@@ -1499,6 +1508,6 @@ describe('ExtApi-FileManagerTest', () => {
await btnReadFileButton.tap()
await isDone()
let readFileRet = await getData('readFileRet')
expect(readFileRet.length>0).toBe(true)
expect(readFileRet.length > 0).toBe(true)
});
});
......@@ -28,7 +28,7 @@
<button class="btnstyle" type="primary" @tap="rmdirTest" id="btn-remove-dir">删除文件夹{{rmDirFile}}</button>
<!-- #ifdef APP-ANDROID -->
<!-- #ifdef APP-ANDROID || MP -->
<button class="btnstyle" type="primary" @tap="statFileInfoSyncTest"
id="btn-stat-file-sync">同步递归获取目录files的Stats对象{{statFile}}</button>
<button class="btnstyle" type="primary" @tap="appendFileTest"
......@@ -164,11 +164,20 @@
/**
* 待测试的全局环境变量
*/
// #ifdef MP
basePath: uni.env.USER_DATA_PATH + '/',
copyToBasePath: uni.env.USER_DATA_PATH + '/',
globalTempPath: uni.env.CACHE_PATH,
globalRootPath: uni.env.SANDBOX_PATH,
globalUserDataPath: uni.env.USER_DATA_PATH + '/',
// #endif
// #ifndef MP
basePath: uni.env.USER_DATA_PATH,
copyToBasePath: uni.env.USER_DATA_PATH,
globalTempPath: uni.env.CACHE_PATH,
globalRootPath: uni.env.SANDBOX_PATH,
globalUserDataPath: uni.env.USER_DATA_PATH
globalUserDataPath: uni.env.USER_DATA_PATH,
// #endif
}
},
onLoad() {
......
......@@ -2,7 +2,7 @@ jest.setTimeout(50000);
const PAGE_PATH = '/pages/API/storage/storage'
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isIos = platformInfo.startsWith('ios')
const isIOS = platformInfo.startsWith('ios')
describe('ExtApi-StorageInfoTest', () => {
if(
......@@ -144,7 +144,7 @@ describe('ExtApi-StorageInfoTest', () => {
let btnComplexStaticTest = await page.$('.btn-complexStaticTest')
await btnComplexStaticTest.tap()
await page.waitFor(600)
if(process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios') == false) {
if(!isIOS) {
expect(await getData('staticComplexRet')).toEqual(true)
}
await page.setData({
......@@ -302,6 +302,7 @@ describe('ExtApi-StorageInfoTest', () => {
it('saveUTSJSONObject', async () => {
await page.callMethod('jest_saveUTSJSONObject')
await page.waitFor(600)
const {
jest_saveUTSJSONObjectSyncResult,
jest_saveUTSJSONObjectAsyncResult
......
......@@ -24,6 +24,7 @@ describe('unicloud-import-object', () => {
genericDemoReturnTodoTitle,
genericDemoReturnTodoContent,
failErrCode,
failErrSubject,
failErrDetailTips,
failNumberErrCode,
successErrCode,
......
const PAGE_PATH = '/pages/API/upload-file/upload-file'
describe('ExtApi-UploadFile', () => {
if (process.env.uniTestPlatformInfo.startsWith('web')) {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isIOS = platformInfo.startsWith('ios')
const isMP = platformInfo.startsWith('mp')
const isWeb = platformInfo.startsWith('web')
if (isWeb) {
// TODO: web 端暂不支持测试
it('web', async () => {
expect(1).toBe(1)
......@@ -42,16 +47,20 @@ describe('ExtApi-UploadFile', () => {
it('Check uni.env', async () => {
await page.callMethod('jest_uploadFile_with_uni_env');
await page.waitFor(2000);
await page.waitFor(3000);
res = await page.data('jest_result');
expect(res).toBe(true);
});
if(isMP) {
return
}
// 15以下的模拟器所对应的xcode不能编译自定义插件,大于15是因为某台设备,会用xcode14.1跑15.5的设备
let version = process.env.uniTestPlatformInfo
let split = version.split(" ")
version = parseInt(split[split.length - 1])
if(!process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios') || version > 15) {
if(!isIOS || version > 15) {
it('Check Upload File In UTS Module', async () => {
res = await page.callMethod('jest_uts_module_invoked')
await page.waitFor(2000);
......
......@@ -95,6 +95,8 @@
context.toBlob((blob : Blob) => {
this.testToBlobResult = (blob.size > 0 && blob.type == 'image/jpeg')
}, 'image/jpeg', 0.95);
// #endif
// #ifdef WEB || MP
this.testToDataURLResult = this.canvasContext!.toDataURL().startsWith('data:image/png;base64')
// #endif
this.testCanvasContext = true
......
......@@ -70,6 +70,8 @@ describe('Checkbox.uvue', () => {
expect(disabled2).toBe(false + '')
})
}
if(!isMP) {
// 自动化测试获取的property checked在app、web和微信小程序之间有差异。微信小程序获取的和显示效果一致,app、web获取的是绑定值
it('checked', async () => {
const cb = await page.$('.cb')
// TODO
......@@ -82,6 +84,7 @@ describe('Checkbox.uvue', () => {
const newValue2 = await cb.property('checked')
expect(newValue2.toString()).toBe(false + '')
})
}
if(!isMP) {
it('color', async () => {
const cb = await page.$('.cb')
......
const PAGE_PATH = '/pages/component/global-events/touch-events-bubbles'
describe('touch-events-test', () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isIOS = platformInfo.startsWith('ios')
const isMP = platformInfo.startsWith('mp')
const isWeb = platformInfo.startsWith('web')
// 先屏蔽 android 及 web 平台
if (
process.env.uniTestPlatformInfo.startsWith('android') ||
process.env.uniTestPlatformInfo.startsWith('web') ||
process.env.uniTestPlatformInfo.startsWith('mp')
isAndroid ||
isWeb ||
isMP
) {
it('other platform', () => {
expect(1).toBe(1)
......
......@@ -75,7 +75,7 @@ describe('PickerView.uvue', () => {
indicatorStyle: "", //清空indicatorStyle
indicatorClass: "indicator-test", //设置indicatorClass为indicator-test
})
expect(await pickerViewEl.attribute('indicatorClass')).toBe("indicator-test")
expect(await pickerViewEl.attribute(isMP ? 'indicator-class': 'indicatorClass')).toBe("indicator-test")
await toScreenshot('picker-view-web-indicator-class')
await page.setData({
indicatorClass: "", //清空indicatorClass
......@@ -86,14 +86,14 @@ describe('PickerView.uvue', () => {
await page.setData({
maskStyle
})
expect(await pickerViewEl.attribute('maskStyle')).toBe(maskStyle)
expect(await pickerViewEl.attribute(isMP ? 'mask-style' : 'maskStyle')).toBe(maskStyle)
await toScreenshot('picker-view-web-mask-style')
})
it('mask-class', async () => {
await page.setData({
maskClass: "mask-test"
})
expect(await pickerViewEl.attribute('maskClass')).toBe("mask-test")
expect(await pickerViewEl.attribute(isMP ? 'mask-class' : maskClass)).toBe("mask-test")
await toScreenshot('picker-view-web-mask-class')
})
return
......
......@@ -70,6 +70,9 @@ describe('component-native-scroll-view-props', () => {
//检测横向scrollLeft属性赋值
it('check_scroll_left', async () => {
await page.setData({
scrollX: true
})
await page.setData({
scrollLeft: 600
})
......@@ -82,6 +85,9 @@ describe('component-native-scroll-view-props', () => {
//检测横向scroll_into_view属性赋值
it('check_scroll_into_view_left', async () => {
await page.setData({
scrollX: true
})
await page.setData({
scrollIntoView: "horizontal_item3"
})
......
const PAGE_PATH = '/pages/component/swiper/swiper'
describe('swiper-touch-test', () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isWeb = platformInfo.startsWith('web')
const isMP = platformInfo.startsWith('mp')
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isWeb = platformInfo.startsWith('web')
const isMP = platformInfo.startsWith('mp')
// 屏蔽 web * android 平台, 需要针对调整坐标
// 屏蔽 小程序,不支持 program.swipe
if (isWeb || isAndroid || isMP) {
......
......@@ -5,7 +5,7 @@ describe('component-native-video', () => {
const isIOS = platformInfo.startsWith('ios')
const isMP = platformInfo.startsWith('mp')
const isWeb = platformInfo.startsWith('web')
if(isWeb){
if (isWeb) {
// TODO: web 端暂不支持测试
it('web', async () => {
expect(1).toBe(1)
......@@ -16,7 +16,7 @@ describe('component-native-video', () => {
let start = 0;
beforeAll(async () => {
page = await program.reLaunch('/pages/component/video/video');
if(process.env.uniTestPlatformInfo.startsWith('web')){
if (process.env.uniTestPlatformInfo.startsWith('web')) {
await page.setData({
muted: true
});
......@@ -36,7 +36,7 @@ describe('component-native-video', () => {
expect(await page.data('isPause')).toBe(true);
});
if(!isMP) {
if (!isMP) {
it('test local source', async () => {
await page.setData({
autoTest: true,
......@@ -83,7 +83,7 @@ describe('component-native-video', () => {
// expect(await page.data('eventPlay')).toEqual({
// type: 'play'
// });
}else {
} else {
expect(await page.data('eventPlay')).toEqual({
tagName: isMP ? undefined : 'VIDEO',
type: 'play'
......@@ -104,7 +104,7 @@ describe('component-native-video', () => {
type: 'pause'
});
}
if(!isMP && !isWeb) {
if (!isMP && !isWeb) {
/**
* app端video组件controlstoggle事件会在controls显示和隐藏触发(播放、暂停等操作都会触发)。
* 微信小程序和web播放暂停或者一些其他的操作也会影响controls的显隐,但是不会触发controlstoggle, 只有controls属性变化的时候才会触发
......@@ -131,14 +131,14 @@ describe('component-native-video', () => {
});
if (isAndroid) {
it('test event waiting progress', async () => {
if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) {
return
}
await page.callMethod('seek', 10);
start = Date.now();
await page.waitFor(async () => {
return (await page.data('eventWaiting')) && (await page.data('eventProgress')) || (Date.now() - start > 1000);
return (await page.data('eventWaiting')) && (await page.data('eventProgress')) || (Date.now() -
start > 1000);
});
expect(await page.data('eventWaiting')).toEqual({
tagName: isMP ? undefined : 'VIDEO',
......@@ -151,7 +151,6 @@ describe('component-native-video', () => {
});
});
if (isAndroid) {
it('test event fullscreenchange fullscreenclick', async () => {
await page.callMethod('requestFullScreen');
start = Date.now();
......@@ -166,7 +165,8 @@ describe('component-native-video', () => {
});
const infos = process.env.uniTestPlatformInfo.split(' ');
const version = parseInt(infos[infos.length - 1]);
if (process.env.uniTestPlatformInfo.startsWith('android') && version > 5) { // android5.1模拟器全屏时会弹出系统提示框,无法响应adb tap命令
if (process.env.uniTestPlatformInfo.startsWith('android') && version >
5) { // android5.1模拟器全屏时会弹出系统提示框,无法响应adb tap命令
await page.waitFor(5000);
await program.adbCommand('input tap 10 10');
start = Date.now();
......@@ -189,12 +189,8 @@ describe('component-native-video', () => {
}
await page.callMethod('exitFullScreen');
});
}
it('test event ended timeupdate', async () => {
if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) {
return
}
await page.callMethod('seek', 120);
start = Date.now();
await page.waitFor(async () => {
......@@ -221,9 +217,6 @@ describe('component-native-video', () => {
});
it('test event error', async () => {
if (isIOS || isMP) {
return
}
const oldSrc = await page.data('src');
await page.setData({
src: 'invalid url'
......@@ -244,9 +237,6 @@ describe('component-native-video', () => {
});
it('test sub component', async () => {
if (isIOS || isMP) {
return
}
await page.setData({
subCompEnable: true,
subCompShow: true
......@@ -254,6 +244,7 @@ describe('component-native-video', () => {
await page.waitFor(100);
expect(await page.callMethod('hasSubComponent')).toBe(true);
});
}
it('test format', async () => {
page = await program.navigateTo('/pages/component/video/video-format');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册