提交 3e5dc43e 编写于 作者: 雪洛's avatar 雪洛

test: 低版本安卓不再进行截图对比

上级 bd6b3b80
...@@ -25,26 +25,23 @@ describe('ExtApi-DownloadFile', () => { ...@@ -25,26 +25,23 @@ describe('ExtApi-DownloadFile', () => {
let shouldTestCookie = false let shouldTestCookie = false
if (process.env.uniTestPlatformInfo.startsWith('android')) { if (process.env.uniTestPlatformInfo.startsWith('android')) {
let version = process.env.uniTestPlatformInfo let version = process.env.uniTestPlatformInfo
version = version.split(" ")[1] version = parseInt(version.split(" ")[1])
shouldTestCookie = version > 9 shouldTestCookie = version > 9
} else if (process.env.uniTestPlatformInfo.startsWith('web')) { } else if (process.env.uniTestPlatformInfo.startsWith('web')) {
// TODO 测试网址调整后放开此测试 // TODO 测试网址调整后放开此测试
shouldTestCookie = false shouldTestCookie = false
} }
if (!shouldTestCookie) {
return
}
it('Check Set Cookie', async () => { it('Check Set Cookie', async () => {
if (!shouldTestCookie) {
return
}
res = await page.callMethod('jest_set_cookie') res = await page.callMethod('jest_set_cookie')
await page.waitFor(2000); await page.waitFor(2000);
res = await page.data('jest_result'); res = await page.data('jest_result');
expect(res).toBe(true) expect(res).toBe(true)
}); });
it('Check Delete Cookie', async () => { it('Check Delete Cookie', async () => {
if (!shouldTestCookie) {
return
}
res = await page.callMethod('jest_delete_cookie') res = await page.callMethod('jest_delete_cookie')
await page.waitFor(2000); await page.waitFor(2000);
res = await page.data('jest_result'); res = await page.data('jest_result');
......
...@@ -39,8 +39,8 @@ describe('ExtApi-Request', () => { ...@@ -39,8 +39,8 @@ describe('ExtApi-Request', () => {
beforeEach(async () => { beforeEach(async () => {
await page.setData({ await page.setData({
jest_result: false, jest_result: false,
data: null, data: null,
header: null header: null
}) })
}); });
...@@ -69,41 +69,37 @@ describe('ExtApi-Request', () => { ...@@ -69,41 +69,37 @@ describe('ExtApi-Request', () => {
}); });
it('Check PATCH', async () => { it('Check PATCH', async () => {
await request(page, 'PATCH'); await request(page, 'PATCH');
}); });
if (process.env.uniTestPlatformInfo.indexOf('web') === -1) { if (process.env.uniTestPlatformInfo.indexOf('web') === -1) {
it('Check OPTIONS', async () => { it('Check OPTIONS', async () => {
await request(page, 'OPTIONS'); await request(page, 'OPTIONS');
}); });
} }
it('Check HEAD', async () => { it('Check HEAD', async () => {
await request(page, 'HEAD'); await request(page, 'HEAD');
}); });
let shouldTestCookie = false
if (process.env.uniTestPlatformInfo.indexOf('web') === -1) { if (process.env.uniTestPlatformInfo.startsWith('android')) {
it('Check Set Cookie', async () => { let version = process.env.uniTestPlatformInfo
if (process.env.uniTestPlatformInfo.startsWith('android')) { version = parseInt(version.split(" ")[1])
let version = process.env.uniTestPlatformInfo shouldTestCookie = version > 9
version = version.split(" ")[1] }
if(version > 9){
res = await page.callMethod('jest_set_cookie') if (!shouldTestCookie) {
await page.waitFor(2000); return
res = await page.data('jest_result');
expect(res).toBe(true)
}
}
});
it('Check Delete Cookie', async () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) {
let version = process.env.uniTestPlatformInfo
version = version.split(" ")[1]
if(version > 9){
res = await page.callMethod('jest_delete_cookie')
await page.waitFor(2000);
res = await page.data('jest_result');
expect(res).toBe(true)
}
}
});
} }
it('Check Set Cookie', async () => {
res = await page.callMethod('jest_set_cookie')
await page.waitFor(2000);
res = await page.data('jest_result');
expect(res).toBe(true)
});
it('Check Delete Cookie', async () => {
res = await page.callMethod('jest_delete_cookie')
await page.waitFor(2000);
res = await page.data('jest_result');
expect(res).toBe(true)
});
}); });
const PAGE_PATH = '/pages/API/upload-file/upload-file' const PAGE_PATH = '/pages/API/upload-file/upload-file'
describe('ExtApi-UploadFile', () => { describe('ExtApi-UploadFile', () => {
if(process.env.uniTestPlatformInfo.startsWith('web')){ if (process.env.uniTestPlatformInfo.startsWith('web')) {
// TODO: web 端暂不支持测试 // TODO: web 端暂不支持测试
it('web', async () => { it('web', async () => {
expect(1).toBe(1) expect(1).toBe(1)
}) })
return return
} }
...@@ -27,36 +27,36 @@ describe('ExtApi-UploadFile', () => { ...@@ -27,36 +27,36 @@ describe('ExtApi-UploadFile', () => {
it('Check ', async () => { it('Check ', async () => {
expect(res).toBe(true); expect(res).toBe(true);
});
it('Check files upload', async () => {
res = await page.callMethod('jest_files_upload')
await page.waitFor(2000);
res = await page.data('jest_result');
expect(res).toBe(true)
}); });
let shouldTestCookie = false
if (process.env.uniTestPlatformInfo.startsWith('android')) {
let version = process.env.uniTestPlatformInfo
version = parseInt(version.split(" ")[1])
shouldTestCookie = version > 9
}
if (!shouldTestCookie) {
return
}
it('Check Set Cookie', async () => { it('Check Set Cookie', async () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) { res = await page.callMethod('jest_set_cookie')
let version = process.env.uniTestPlatformInfo await page.waitFor(2000);
version = version.split(" ")[1] res = await page.data('jest_result');
if(version > 9){ expect(res).toBe(true)
res = await page.callMethod('jest_set_cookie')
await page.waitFor(2000);
res = await page.data('jest_result');
expect(res).toBe(true)
}
}
}); });
it('Check Delete Cookie', async () => { it('Check Delete Cookie', async () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) { res = await page.callMethod('jest_delete_cookie')
let version = process.env.uniTestPlatformInfo
version = version.split(" ")[1]
if(version > 9){
res = await page.callMethod('jest_delete_cookie')
await page.waitFor(2000);
res = await page.data('jest_result');
expect(res).toBe(true)
}
}
});
it('Check files upload', async () => {
res = await page.callMethod('jest_files_upload')
await page.waitFor(2000); await page.waitFor(2000);
res = await page.data('jest_result'); res = await page.data('jest_result');
expect(res).toBe(true) expect(res).toBe(true)
}); });
}); });
...@@ -193,8 +193,8 @@ const pages = [ ...@@ -193,8 +193,8 @@ const pages = [
// "pages/API/install-apk/install-apk", // "pages/API/install-apk/install-apk",
// "pages/template/scroll-sticky/scroll-sticky", // "pages/template/scroll-sticky/scroll-sticky",
// "pages/API/exit/exit", // "pages/API/exit/exit",
// "pages/API/element-takesnapshot/element-takesnapshot", // "pages/API/element-takesnapshot/element-takesnapshot",
// "pages/API/get-system-setting/get-system-setting", // "pages/API/get-system-setting/get-system-setting",
// "pages/API/get-app-authorize-setting/get-app-authorize-setting", // "pages/API/get-app-authorize-setting/get-app-authorize-setting",
// 仅 web // 仅 web
...@@ -223,7 +223,7 @@ const needAdbScreenshotPages = [ ...@@ -223,7 +223,7 @@ const needAdbScreenshotPages = [
"pages/API/action-sheet/action-sheet", "pages/API/action-sheet/action-sheet",
"pages/API/modal/modal", "pages/API/modal/modal",
"pages/API/loading/loading", "pages/API/loading/loading",
"pages/API/toast/toast", "pages/API/toast/toast",
"pages/API/pull-down-refresh/pull-down-refresh", "pages/API/pull-down-refresh/pull-down-refresh",
]; ];
...@@ -235,115 +235,123 @@ const PAGE_PATH = ...@@ -235,115 +235,123 @@ const PAGE_PATH =
"/pages/webview-screenshot-comparison/webview-screenshot-comparison"; "/pages/webview-screenshot-comparison/webview-screenshot-comparison";
describe("shot-compare", () => { describe("shot-compare", () => {
if (process.env.uniTestPlatformInfo.startsWith("android")) { let shouldCompareScreenShot = false
let page = null; if (process.env.uniTestPlatformInfo.startsWith('android')) {
let pageIndex = 0; let version = process.env.uniTestPlatformInfo
let baseSrc = ""; version = parseInt(version.split(" ")[1])
beforeAll(async () => { shouldCompareScreenShot = version > 9
// 获取导航栏+状态栏高度 }
page = await program.reLaunch('/pages/API/get-window-info/get-window-info')
await page.callMethod('getWindowInfo')
// 获取设备像素比
page = await program.reLaunch('/pages/API/get-device-info/get-device-info')
await page.callMethod('getDeviceInfo')
page = await program.reLaunch(PAGE_PATH);
await page.waitFor(500);
// set webview-screenshot-comparison page baseSrc if (!shouldCompareScreenShot) {
baseSrc = it("other platform not support", async () => {
process.env.UNI_WEB_SERVICE_URL ? `${process.env.UNI_WEB_SERVICE_URL}/#/` : expect(1).toBe(1);
"http://test.dcloud.io/unix_h5_build/98_dev_hello-uni-app-x/#/"; });
page.setData({ return
baseSrc, }
});
});
beforeEach(async () => { let page = null;
page = await program.reLaunch(PAGE_PATH); let pageIndex = 0;
await page.waitFor(500); let baseSrc = "";
}); beforeAll(async () => {
afterEach(() => { // 获取导航栏+状态栏高度
pageIndex++; page = await program.reLaunch('/pages/API/get-window-info/get-window-info')
await page.callMethod('getWindowInfo')
// 获取设备像素比
page = await program.reLaunch('/pages/API/get-device-info/get-device-info')
await page.callMethod('getDeviceInfo')
page = await program.reLaunch(PAGE_PATH);
await page.waitFor(500);
// set webview-screenshot-comparison page baseSrc
baseSrc =
process.env.UNI_WEB_SERVICE_URL ? `${process.env.UNI_WEB_SERVICE_URL}/#/` :
"http://test.dcloud.io/unix_h5_build/98_dev_hello-uni-app-x/#/";
page.setData({
baseSrc,
}); });
});
test.each(pages)("%s", async () => { beforeEach(async () => {
const isNeedAdbScreenshot = needAdbScreenshot(pages[pageIndex]); page = await program.reLaunch(PAGE_PATH);
const isCustomNavigationBar = customNavigationPages.includes(pages[pageIndex]); await page.waitFor(500);
const { });
statusBarHeight, afterEach(() => {
devicePixelRatio pageIndex++;
} = await page.data(); });
const screenshotParams = {
fullPage: true,
adb: isNeedAdbScreenshot,
// adb 截图时跳过状态栏
area: {
x: 0,
y: statusBarHeight * devicePixelRatio,
},
}
const screenshotPath = `__webview__${pages[pageIndex].replace(/\//g, "-")}`;
// web in webview screenshot test.each(pages)("%s", async () => {
// 加载依赖页面 const isNeedAdbScreenshot = needAdbScreenshot(pages[pageIndex]);
if (childToParentPagesMap.get(pages[pageIndex])) { const isCustomNavigationBar = customNavigationPages.includes(pages[pageIndex]);
await page.setData({ const {
src: `${baseSrc}${childToParentPagesMap.get(pages[pageIndex])}`, statusBarHeight,
isLoaded: false devicePixelRatio
}); } = await page.data();
await page.waitFor(async () => { const screenshotParams = {
const isLoaded = await page.data("isLoaded"); fullPage: true,
return isLoaded || Date.now() - startTime > 10000; adb: isNeedAdbScreenshot,
}); // adb 截图时跳过状态栏
await page.waitFor(200); area: {
} x: 0,
y: statusBarHeight * devicePixelRatio,
},
}
const screenshotPath = `__webview__${pages[pageIndex].replace(/\//g, "-")}`;
// web in webview screenshot
// 加载依赖页面
if (childToParentPagesMap.get(pages[pageIndex])) {
await page.setData({ await page.setData({
src: `${baseSrc}${pages[pageIndex]}`, src: `${baseSrc}${childToParentPagesMap.get(pages[pageIndex])}`,
isLoaded: false, isLoaded: false
isCustomNavigationBar,
}); });
const startTime = Date.now();
await page.waitFor(async () => { await page.waitFor(async () => {
const isLoaded = await page.data("isLoaded"); const isLoaded = await page.data("isLoaded");
return isLoaded || Date.now() - startTime > 3000; return isLoaded || Date.now() - startTime > 10000;
}); });
await page.waitFor(800); await page.waitFor(200);
if (pages[pageIndex].includes("load-font-face")) { }
await page.waitFor(3000); await page.setData({
} src: `${baseSrc}${pages[pageIndex]}`,
isLoaded: false,
isCustomNavigationBar,
});
// web 端非 adb 截图时设置 offsetY 移除导航栏 const startTime = Date.now();
const webSnapshot = await program.screenshot({ await page.waitFor(async () => {
...screenshotParams, const isLoaded = await page.data("isLoaded");
id: 'webview-screenshot-comparison', return isLoaded || Date.now() - startTime > 3000;
offsetY: `${isCustomNavigationBar ? 0 : 44}` });
}); await page.waitFor(800);
expect(webSnapshot).toMatchImageSnapshot({ if (pages[pageIndex].includes("load-font-face")) {
customSnapshotIdentifier() { await page.waitFor(3000);
return screenshotPath; }
},
});
// app-android page screenshot comparison // web 端非 adb 截图时设置 offsetY 移除导航栏
const navigateMethod = pages[pageIndex].startsWith("pages/tabBar") ? const webSnapshot = await program.screenshot({
"switchTab" : ...screenshotParams,
"navigateTo"; id: 'webview-screenshot-comparison',
page = await program[navigateMethod](`/${pages[pageIndex]}`); offsetY: `${isCustomNavigationBar ? 0 : 44}`
await page.waitFor(500);
if (pages[pageIndex].includes("load-font-face")) {
await page.waitFor(3000);
}
const appAndroidSnapshot = await program.screenshot(screenshotParams);
expect(appAndroidSnapshot).toMatchImageSnapshot({
customSnapshotIdentifier() {
return screenshotPath;
},
});
}); });
} else { expect(webSnapshot).toMatchImageSnapshot({
it("other platform not support", async () => { customSnapshotIdentifier() {
expect(1).toBe(1); return screenshotPath;
},
}); });
}
}); // app-android page screenshot comparison
const navigateMethod = pages[pageIndex].startsWith("pages/tabBar") ?
"switchTab" :
"navigateTo";
page = await program[navigateMethod](`/${pages[pageIndex]}`);
await page.waitFor(500);
if (pages[pageIndex].includes("load-font-face")) {
await page.waitFor(3000);
}
const appAndroidSnapshot = await program.screenshot(screenshotParams);
expect(appAndroidSnapshot).toMatchImageSnapshot({
customSnapshotIdentifier() {
return screenshotPath;
},
});
});
});
...@@ -223,7 +223,7 @@ const needAdbScreenshotPages = [ ...@@ -223,7 +223,7 @@ const needAdbScreenshotPages = [
"pages/API/action-sheet/action-sheet", "pages/API/action-sheet/action-sheet",
"pages/API/modal/modal", "pages/API/modal/modal",
"pages/API/loading/loading", "pages/API/loading/loading",
"pages/API/toast/toast", "pages/API/toast/toast",
"pages/API/pull-down-refresh/pull-down-refresh", "pages/API/pull-down-refresh/pull-down-refresh",
]; ];
...@@ -235,92 +235,99 @@ const PAGE_PATH = ...@@ -235,92 +235,99 @@ const PAGE_PATH =
"/pages/webview-screenshot/webview-screenshot"; "/pages/webview-screenshot/webview-screenshot";
describe("shot-compare", () => { describe("shot-compare", () => {
if (process.env.uniTestPlatformInfo.startsWith("android")) { let shouldCompareScreenShot = false
let page = null; if (process.env.uniTestPlatformInfo.startsWith('android')) {
let pageIndex = 0; let version = process.env.uniTestPlatformInfo
let baseSrc = ""; version = parseInt(version.split(" ")[1])
beforeAll(async () => { shouldCompareScreenShot = version > 9
page = await program.reLaunch(PAGE_PATH); }
await page.waitFor(500);
// set webview-screenshot page baseSrc if (!shouldCompareScreenShot) {
baseSrc = it("other platform not support", async () => {
process.env.UNI_WEB_SERVICE_URL ? `${process.env.UNI_WEB_SERVICE_URL}/#/` : expect(1).toBe(1);
"http://test.dcloud.io/unix_h5_build/98_dev_hello-uni-app-x/#/"; });
page.setData({ return
baseSrc, }
}); let page = null;
}); let pageIndex = 0;
let baseSrc = "";
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH);
await page.waitFor(500);
beforeEach(async () => { // set webview-screenshot page baseSrc
page = await program.reLaunch(PAGE_PATH); baseSrc =
await page.waitFor(500); process.env.UNI_WEB_SERVICE_URL ? `${process.env.UNI_WEB_SERVICE_URL}/#/` :
}); "http://test.dcloud.io/unix_h5_build/98_dev_hello-uni-app-x/#/";
afterEach(() => { page.setData({
pageIndex++; baseSrc,
}); });
});
beforeEach(async () => {
page = await program.reLaunch(PAGE_PATH);
await page.waitFor(500);
});
afterEach(() => {
pageIndex++;
});
test.each(pages)("%s", async () => { test.each(pages)("%s", async () => {
const isNeedAdbScreenshot = needAdbScreenshot(pages[pageIndex]); const isNeedAdbScreenshot = needAdbScreenshot(pages[pageIndex]);
const isCustomNavigation = customNavigationPages.includes(pages[pageIndex]); const isCustomNavigation = customNavigationPages.includes(pages[pageIndex]);
const { const {
headerHeight, headerHeight,
devicePixelRatio devicePixelRatio
} = await page.data(); } = await page.data();
const screenshotParams = { const screenshotParams = {
fullPage: true, fullPage: true,
adb: isNeedAdbScreenshot, adb: isNeedAdbScreenshot,
// adb 截图时跳过状态栏 // adb 截图时跳过状态栏
area: { area: {
x: 0, x: 0,
y: (headerHeight - 44) * devicePixelRatio, y: (headerHeight - 44) * devicePixelRatio,
}, },
} }
const screenshotPath = `webview-shot__${pages[pageIndex].replace(/\//g, "-")}`; const screenshotPath = `webview-shot__${pages[pageIndex].replace(/\//g, "-")}`;
// web in webview screenshot // web in webview screenshot
// 加载依赖页面 // 加载依赖页面
if (childToParentPagesMap.get(pages[pageIndex])) { if (childToParentPagesMap.get(pages[pageIndex])) {
await page.setData({
src: `${baseSrc}${childToParentPagesMap.get(pages[pageIndex])}`,
isLoaded: false
});
await page.waitFor(async () => {
const isLoaded = await page.data("isLoaded");
return isLoaded || Date.now() - startTime > 10000;
});
await page.waitFor(200);
}
await page.setData({ await page.setData({
src: `${baseSrc}${pages[pageIndex]}`, src: `${baseSrc}${childToParentPagesMap.get(pages[pageIndex])}`,
isLoaded: false, isLoaded: false
needRemoveWebHead: !isNeedAdbScreenshot,
}); });
const startTime = Date.now();
await page.waitFor(async () => { await page.waitFor(async () => {
const isLoaded = await page.data("isLoaded"); const isLoaded = await page.data("isLoaded");
return isLoaded || Date.now() - startTime > 3000; return isLoaded || Date.now() - startTime > 10000;
}); });
await page.waitFor(1000); await page.waitFor(200);
if (pages[pageIndex].includes("load-font-face")) { }
await page.waitFor(3000); await page.setData({
} src: `${baseSrc}${pages[pageIndex]}`,
isLoaded: false,
needRemoveWebHead: !isNeedAdbScreenshot,
});
// web 端非 adb 截图时设置 offsetY 移除导航栏 const startTime = Date.now();
const webSnapshot = await program.screenshot({ await page.waitFor(async () => {
...screenshotParams, const isLoaded = await page.data("isLoaded");
offsetY: `${isCustomNavigation ? 0 : headerHeight}` return isLoaded || Date.now() - startTime > 3000;
});
expect(webSnapshot).toMatchImageSnapshot({
customSnapshotIdentifier() {
return screenshotPath;
},
});
}); });
} else { await page.waitFor(1000);
it("other platform not support", async () => { if (pages[pageIndex].includes("load-font-face")) {
expect(1).toBe(1); await page.waitFor(3000);
}
// web 端非 adb 截图时设置 offsetY 移除导航栏
const webSnapshot = await program.screenshot({
...screenshotParams,
offsetY: `${isCustomNavigation ? 0 : headerHeight}`
}); });
} expect(webSnapshot).toMatchImageSnapshot({
}); customSnapshotIdentifier() {
return screenshotPath;
},
});
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册