提交 7c30d1ad 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

test: 调整部分测试例,兼容跨平台截图对比

上级 3c6689b4
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/ // uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe('component-native-image', () => { describe('component-native-image', () => {
let page;
async function getWindowInfo() {
const windowInfoPage = await program.reLaunch('/pages/API/get-window-info/get-window-info')
await windowInfoPage.waitFor(600);
return await windowInfoPage.callMethod('jest_getWindowInfo')
}
const screenshotParams = { fullPage: true }
let windowInfo
beforeAll(async () => {
if (!process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
screenshotParams.fullPage = false
windowInfo = await getWindowInfo()
let offsetY = '0'
if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('android')) {
offsetY = `${windowInfo.statusBarHeight + 44}`
}
if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) {
offsetY = `${windowInfo.safeAreaInsets.top + 44}`
}
screenshotParams.offsetY = offsetY
}
page = await program.reLaunch('/pages/component/image/image');
await page.waitFor(600);
});
let page; it('check_image_load', async () => {
beforeAll(async () => { expect(await page.data('loadError')).toBe(false)
page = await program.reLaunch('/pages/component/image/image'); });
await page.waitFor(600);
});
it('check_image_load', async () => { it('check_image_load_url', async () => {
expect(await page.data('loadError')).toBe(false) await page.setData({
}); loadError: false,
imageSrc: 'https://request.dcloud.net.cn/api/http/contentType/image/png'
})
await page.waitFor(300);
expect(await page.data('loadError')).toBe(false)
})
it('check_image_load_url', async () => { it('check_image_load_error', async () => {
await page.setData({ await page.setData({
loadError: false, loadError: false,
imageSrc: 'https://request.dcloud.net.cn/api/http/contentType/image/png' imageSrc: 'testerror.jpg'
})
await page.waitFor(300);
expect(await page.data('loadError')).toBe(false)
}) })
await page.waitFor(300);
expect(await page.data('loadError')).toBe(true)
})
it('check_image_load_error', async () => { if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
it('check-cookie', async () => {
await page.setData({
autoTest: true,
setCookieImage: 'https://cdn.dcloud.net.cn/img/shadow-grey.png'
});
await page.waitFor(1000);
await page.setData({ await page.setData({
loadError: false, loadError: false,
imageSrc: 'testerror.jpg' verifyCookieImage: 'https://request.dcloud.net.cn/img/shadow-grey.png'
}) });
await page.waitFor(300); await page.waitFor(1000);
expect(await page.data('loadError')).toBe(true) expect(await page.data('loadError')).toBe(false);
await page.setData({
autoTest: false
});
}) })
}
if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) { it('path-screenshot', async () => {
it('check-cookie', async () => { const page = await program.navigateTo('/pages/component/image/image-path');
await page.setData({ await page.waitFor(3000);
autoTest: true, const image = await program.screenshot(screenshotParams)
setCookieImage: 'https://cdn.dcloud.net.cn/img/shadow-grey.png' expect(image).toSaveImageSnapshot()
}); });
await page.waitFor(1000);
await page.setData({
loadError: false,
verifyCookieImage: 'https://request.dcloud.net.cn/img/shadow-grey.png'
});
await page.waitFor(1000);
expect(await page.data('loadError')).toBe(false);
await page.setData({
autoTest: false
});
})
}
it('path-screenshot', async () => { it('mode-screenshot', async () => {
const page = await program.navigateTo('/pages/component/image/image-path'); if (process.env.android_cpu_type === 'x86_64') return
await page.waitFor(3000); const page = await program.navigateTo('/pages/component/image/image-mode');
const image = await program.screenshot({ await page.waitFor(1000);
fullPage: true const image = await program.screenshot(screenshotParams)
}) expect(image).toSaveImageSnapshot()
expect(image).toSaveImageSnapshot() });
});
it('mode-screenshot', async () => {
if (process.env.android_cpu_type === 'x86_64') return
const page = await program.navigateTo('/pages/component/image/image-mode');
await page.waitFor(1000);
const image = await program.screenshot({
fullPage: true
})
expect(image).toSaveImageSnapshot()
});
}); });
describe('component-native-sticky-header', () => { describe('component-native-sticky-header', () => {
let page let page
async function getWindowInfo() {
const windowInfoPage = await program.reLaunch('/pages/API/get-window-info/get-window-info')
await windowInfoPage.waitFor(600);
return await windowInfoPage.callMethod('jest_getWindowInfo')
}
const screenshotParams = { fullPage: true }
let windowInfo
beforeAll(async () => { beforeAll(async () => {
if (!process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
screenshotParams.fullPage = false
windowInfo = await getWindowInfo()
let offsetY = '0'
if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('android')) {
offsetY = `${windowInfo.statusBarHeight + 44}`
}
if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) {
offsetY = `${windowInfo.safeAreaInsets.top + 44}`
}
screenshotParams.offsetY = offsetY
}
page = await program.reLaunch('/pages/component/sticky-header/sticky-header') page = await program.reLaunch('/pages/component/sticky-header/sticky-header')
await page.waitFor('sticky-header') await page.waitFor('sticky-header')
}) })
...@@ -8,7 +28,7 @@ describe('component-native-sticky-header', () => { ...@@ -8,7 +28,7 @@ describe('component-native-sticky-header', () => {
//检测吸顶效果 //检测吸顶效果
it('check_sticky_header', async () => { it('check_sticky_header', async () => {
await page.callMethod('confirm_scroll_top_input', 600) await page.callMethod('confirm_scroll_top_input', 600)
const image = await program.screenshot({fullPage: true}); const image = await program.screenshot(screenshotParams);
expect(image).toSaveImageSnapshot(); expect(image).toSaveImageSnapshot();
}) })
}) })
...@@ -2,15 +2,33 @@ ...@@ -2,15 +2,33 @@
describe('template-list-news', () => { describe('template-list-news', () => {
let page; let page;
async function getWindowInfo() {
const windowInfoPage = await program.reLaunch('/pages/API/get-window-info/get-window-info')
await windowInfoPage.waitFor(600);
return await windowInfoPage.callMethod('jest_getWindowInfo')
}
const screenshotParams = { fullPage: true }
let windowInfo
beforeAll(async () => { beforeAll(async () => {
if (!process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
screenshotParams.fullPage = false
windowInfo = await getWindowInfo()
let offsetY = '0'
if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('android')) {
offsetY = `${windowInfo.statusBarHeight + 44}`
}
if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) {
offsetY = `${windowInfo.safeAreaInsets.top + 44}`
}
screenshotParams.offsetY = offsetY
}
page = await program.reLaunch('/pages/template/list-news/list-news'); page = await program.reLaunch('/pages/template/list-news/list-news');
await page.waitFor(3000); await page.waitFor(3000);
}); });
it('screenshot', async () => { it('screenshot', async () => {
const image = await program.screenshot({ const image = await program.screenshot(screenshotParams)
fullPage: true
})
expect(image).toSaveImageSnapshot() expect(image).toSaveImageSnapshot()
}); });
}); });
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册