From febdb369e72bcc06c2755647c9ca3320fd6671f7 Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Wed, 25 Oct 2023 17:19:33 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E4=BC=98=E5=8C=96=E6=B5=8B=E8=AF=95=20?= =?UTF-8?q?waitFor=20=E7=AD=89=E5=BE=85=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...t-element-by-id-multiple-root-node.test.js | 2 +- .../get-element-by-id.test.js | 2 +- .../get-launch-options-sync.test.js | 2 +- .../load-font-face-child.test.js | 2 +- .../API/load-font-face/load-font-face.test.js | 2 +- pages/API/navigator/navigator.test.js | 34 +++++++------------ .../API/navigator/new-page/new-page-2.test.js | 18 +++++----- pages/API/navigator/new-page/onLoad.test.js | 30 ++++++++-------- .../general-attribute.test.js | 4 +-- .../general-event/general-event.test.js | 2 +- 10 files changed, 44 insertions(+), 54 deletions(-) diff --git a/pages/API/get-element-by-id/get-element-by-id-multiple-root-node.test.js b/pages/API/get-element-by-id/get-element-by-id-multiple-root-node.test.js index c7863eb9..7311bbde 100644 --- a/pages/API/get-element-by-id/get-element-by-id-multiple-root-node.test.js +++ b/pages/API/get-element-by-id/get-element-by-id-multiple-root-node.test.js @@ -5,7 +5,7 @@ let page; describe("getElementByIdForMultipleRootNode", () => { beforeAll(async () => { page = await program.reLaunch(PAGE_PATH); - await page.waitFor(1000); + await page.waitFor('view'); }); it("getElementByNotExistId", async () => { const res = await page.callMethod("getElementByNotExistId"); diff --git a/pages/API/get-element-by-id/get-element-by-id.test.js b/pages/API/get-element-by-id/get-element-by-id.test.js index 00a5f2e7..a04f1b1d 100644 --- a/pages/API/get-element-by-id/get-element-by-id.test.js +++ b/pages/API/get-element-by-id/get-element-by-id.test.js @@ -4,7 +4,7 @@ let page; describe("getElementById", () => { beforeAll(async () => { page = await program.reLaunch(PAGE_PATH); - await page.waitFor(1000); + await page.waitFor('view'); }); it("getElementByNotExistId", async () => { const res = await page.callMethod("getElementByNotExistId"); diff --git a/pages/API/get-launch-options-sync/get-launch-options-sync.test.js b/pages/API/get-launch-options-sync/get-launch-options-sync.test.js index 1c603c68..48027937 100644 --- a/pages/API/get-launch-options-sync/get-launch-options-sync.test.js +++ b/pages/API/get-launch-options-sync/get-launch-options-sync.test.js @@ -3,7 +3,7 @@ const PAGE_PATH = '/pages/API/get-launch-options-sync/get-launch-options-sync' describe('getLaunchOptionsSync', () => { it('getLaunchOptionsSync', async () => { const page = await program.navigateTo(PAGE_PATH) - await page.waitFor(1000) + await page.waitFor('view') await page.callMethod('getLaunchOptionsSync') const data = await page.data() expect(data.checked).toBe(true) diff --git a/pages/API/load-font-face/load-font-face-child.test.js b/pages/API/load-font-face/load-font-face-child.test.js index ad479f5b..602fb40f 100644 --- a/pages/API/load-font-face/load-font-face-child.test.js +++ b/pages/API/load-font-face/load-font-face-child.test.js @@ -3,7 +3,7 @@ const PAGE_PATH = '/pages/API/load-font-face/load-font-face-child' describe('loadFontFace global', () => { beforeAll(async () => { const page = await program.navigateTo(PAGE_PATH) - await page.waitFor(2000) + await page.waitFor('view') }) it('screenshot', async () => { const image = await program.screenshot() diff --git a/pages/API/load-font-face/load-font-face.test.js b/pages/API/load-font-face/load-font-face.test.js index 548343c0..826dabee 100644 --- a/pages/API/load-font-face/load-font-face.test.js +++ b/pages/API/load-font-face/load-font-face.test.js @@ -3,7 +3,7 @@ const PAGE_PATH = '/pages/API/load-font-face/load-font-face' describe('loadFontFace', () => { beforeAll(async () => { const page = await program.navigateTo(PAGE_PATH) - await page.waitFor(4000) + await page.waitFor(3000) }) it('screenshot', async () => { const image = await program.screenshot() diff --git a/pages/API/navigator/navigator.test.js b/pages/API/navigator/navigator.test.js index 45c4efc0..8005eabf 100644 --- a/pages/API/navigator/navigator.test.js +++ b/pages/API/navigator/navigator.test.js @@ -17,12 +17,12 @@ describe('navigator', () => { it('reLaunch', async () => { page = await program.navigateTo(CURRENT_PAGE_PATH) - await page.waitFor(500) + await page.waitFor('view') await page.callMethod('setLifeCycleNum', 0) await page.callMethod('reLaunch') await page.waitFor(500) page = await program.navigateTo(CURRENT_PAGE_PATH) - await page.waitFor(500) + await page.waitFor('view') lifeCycleNum = await page.callMethod('getLifeCycleNum') expect(lifeCycleNum).toBe(2) }) @@ -30,11 +30,11 @@ describe('navigator', () => { it('navigateTo', async () => { await page.callMethod('setLifeCycleNum', 0) await page.callMethod('navigateTo') - await page.waitFor(500) + await page.waitFor('view') lifeCycleNum = await page.callMethod('getLifeCycleNum') expect(lifeCycleNum).toBe(2) page = await program.navigateBack() - await page.waitFor(500) + await page.waitFor('view') }) it('navigateTo error page', async () => { @@ -52,45 +52,41 @@ describe('navigator', () => { lifeCycleNum = await page.callMethod('getLifeCycleNum') expect(lifeCycleNum).toBe(4) page = await program.navigateBack() - await page.waitFor(500) + await page.waitFor('view') }) it('navigateTo relative path', async () => { await page.callMethod('setLifeCycleNum', 0) await page.callMethod('navigateToRelativePath1') page = await program.navigateBack() - await page.waitFor(500) + await page.waitFor('view') lifeCycleNum = await page.callMethod('getLifeCycleNum') expect(lifeCycleNum).toBe(2) - await page.waitFor(500) }) it('navigateTo relative path ./', async () => { await page.callMethod('setLifeCycleNum', 0) await page.callMethod('navigateToRelativePath2') page = await program.navigateBack() - await page.waitFor(500) + await page.waitFor('view') lifeCycleNum = await page.callMethod('getLifeCycleNum') expect(lifeCycleNum).toBe(2) - await page.waitFor(500) }) it('navigateTo relative path ../', async () => { await page.callMethod('setLifeCycleNum', 0) await page.callMethod('navigateToRelativePath3') page = await program.navigateBack() - await page.waitFor(500) + await page.waitFor('view') lifeCycleNum = await page.callMethod('getLifeCycleNum') expect(lifeCycleNum).toBe(2) - await page.waitFor(500) }) it('navigateBack', async () => { await page.callMethod('setLifeCycleNum', 0) await page.callMethod('navigateBack') - await page.waitFor(500) page = await program.navigateTo(CURRENT_PAGE_PATH) - await page.waitFor(500) + await page.waitFor('view') lifeCycleNum = await page.callMethod('getLifeCycleNum') expect(lifeCycleNum).toBe(2) }) @@ -98,7 +94,6 @@ describe('navigator', () => { it('navigateBackWithDelta1', async () => { await page.callMethod('setLifeCycleNum', 0) await page.callMethod('navigateBackWithDelta1') - await page.waitFor(1000) page = await program.currentPage() expect(`/${page.path}`).toBe(CURRENT_PAGE_PATH) lifeCycleNum = await page.callMethod('getLifeCycleNum') @@ -108,11 +103,8 @@ describe('navigator', () => { it('navigateBackWithDelta2', async () => { await page.callMethod('setLifeCycleNum', 0) await program.navigateTo(CHILD2_PAGE_PATH) - await page.waitFor(500) page = await program.navigateTo(CHILD1_PAGE_PATH) - await page.waitFor(500) await page.callMethod('navigateBackWithDelta2') - await page.waitFor(500) page = await program.currentPage() expect(`/${page.path}`).toBe(CURRENT_PAGE_PATH) lifeCycleNum = await page.callMethod('getLifeCycleNum') @@ -123,8 +115,8 @@ describe('navigator', () => { page = await program.reLaunch(CURRENT_PAGE_PATH) await page.callMethod('setLifeCycleNum', 0) await page.callMethod('navigateBackWithDelta100') - await page.waitFor(1000) page = await program.currentPage() + await page.waitFor('view') expect(`/${page.path}`).toBe(CURRENT_PAGE_PATH) lifeCycleNum = await page.callMethod('getLifeCycleNum') expect(lifeCycleNum).toBe(2) @@ -133,9 +125,8 @@ describe('navigator', () => { it('redirectTo', async () => { await page.callMethod('setLifeCycleNum', 0) await page.callMethod('redirectTo') - await page.waitFor(500) page = await program.redirectTo(CURRENT_PAGE_PATH) - await page.waitFor(500) + await page.waitFor('view') lifeCycleNum = await page.callMethod('getLifeCycleNum') expect(lifeCycleNum).toBe(2) }) @@ -144,9 +135,8 @@ describe('navigator', () => { page = await program.reLaunch(CURRENT_PAGE_PATH) await page.callMethod('setLifeCycleNum', 0) await page.callMethod('switchTab') - await page.waitFor(500) page = await program.navigateTo(CURRENT_PAGE_PATH) - await page.waitFor(500) + await page.waitFor('view') lifeCycleNum = await page.callMethod('getLifeCycleNum') expect(lifeCycleNum).toBe(2) }) diff --git a/pages/API/navigator/new-page/new-page-2.test.js b/pages/API/navigator/new-page/new-page-2.test.js index 2ea7cadc..99fb3dd5 100644 --- a/pages/API/navigator/new-page/new-page-2.test.js +++ b/pages/API/navigator/new-page/new-page-2.test.js @@ -1,4 +1,4 @@ -jest.setTimeout(30000) +jest.setTimeout(20000) const PAGE_PATH = '/pages/API/navigator/new-page/new-page-2' const INTERMEDIATE_PAGE_PATH = '/pages/API/navigator/navigator' let page @@ -7,13 +7,13 @@ let lifeCycleNum describe('app-lifecycle', () => { it('onLaunch onShow', async () => { page = await program.reLaunch(INTERMEDIATE_PAGE_PATH) - await page.waitFor(1000) + await page.waitFor('view') lifeCycleNum = await page.callMethod('getLifeCycleNum') expect(lifeCycleNum).toBe(1100) }) it('onLastPageBackPress', async () => { page = await program.navigateBack() - await page.waitFor(1000) + await page.waitFor('view') lifeCycleNum = await page.callMethod('getLifeCycleNum') expect(lifeCycleNum).toBe(100) @@ -26,7 +26,7 @@ describe('app-lifecycle', () => { describe('page-lifecycle', () => { it('onLoad onShow onReady', async () => { page = await program.reLaunch(PAGE_PATH) - await page.waitFor(1000) + await page.waitFor('view') lifeCycleNum = await page.callMethod('getLifeCycleNum') expect(lifeCycleNum).toBe(120) await page.callMethod('setLifeCycleNum', 0) @@ -48,28 +48,28 @@ describe('page-lifecycle', () => { }) it('onHide', async () => { page = await program.navigateTo(INTERMEDIATE_PAGE_PATH) - await page.waitFor(1000) + await page.waitFor('view') lifeCycleNum = await page.callMethod('getLifeCycleNum') expect(lifeCycleNum).toBe(-10) page = await program.navigateBack() - await page.waitFor(1000) + await page.waitFor('view') lifeCycleNum = await page.callMethod('getLifeCycleNum') expect(lifeCycleNum).toBe(0) }) it('onUnload', async () => { page = await program.redirectTo(INTERMEDIATE_PAGE_PATH) - await page.waitFor(1000) + await page.waitFor('view') lifeCycleNum = await page.callMethod('getLifeCycleNum') expect(lifeCycleNum).toBe(-100) await page.callMethod('setLifeCycleNum', 0) }) it('onBackPress', async () => { page = await program.navigateTo(PAGE_PATH) - await page.waitFor(1000) + await page.waitFor('view') lifeCycleNum = await page.callMethod('getLifeCycleNum') expect(lifeCycleNum).toBe(120) page = await program.navigateBack() - await page.waitFor(1000) + await page.waitFor('view') lifeCycleNum = await page.callMethod('getLifeCycleNum') expect(lifeCycleNum).toBe(10) await page.callMethod('setLifeCycleNum', 0) diff --git a/pages/API/navigator/new-page/onLoad.test.js b/pages/API/navigator/new-page/onLoad.test.js index 933193ac..7708452b 100644 --- a/pages/API/navigator/new-page/onLoad.test.js +++ b/pages/API/navigator/new-page/onLoad.test.js @@ -7,50 +7,50 @@ let page; describe("onLoad", () => { it("adjustData", async () => { page = await program.reLaunch(INTERMEDIATE_PAGE_PATH); - await page.waitFor(500); + await page.waitFor('view'); await page.callMethod("navigateToOnLoadWithType", "adjustData"); - await page.waitFor(1000); + await page.waitFor(500); const image = await program.screenshot(); expect(image).toMatchImageSnapshot(); }); it("navigateTo", async () => { page = await program.reLaunch(INTERMEDIATE_PAGE_PATH); - await page.waitFor(500); + await page.waitFor('view'); await page.callMethod("navigateToOnLoadWithType", "navigateTo"); - await page.waitFor(1000); + await page.waitFor(500); page = await program.currentPage(); expect(page.path).toBe(TARGET_PAGE_PATH.substring(1)); }); it("navigateBack", async () => { page = await program.reLaunch(INTERMEDIATE_PAGE_PATH); - await page.waitFor(500); + await page.waitFor('view'); await page.callMethod("navigateToOnLoadWithType", "navigateBack"); - await page.waitFor(1000); page = await program.currentPage(); + await page.waitFor('view'); expect(page.path).toBe(INTERMEDIATE_PAGE_PATH.substring(1)); }); it("redirectTo", async () => { page = await program.reLaunch(INTERMEDIATE_PAGE_PATH); - await page.waitFor(500); + await page.waitFor('view'); await page.callMethod("navigateToOnLoadWithType", "redirectTo"); - await page.waitFor(1000); + await page.waitFor(500); page = await program.currentPage(); expect(page.path).toBe(TARGET_PAGE_PATH.substring(1)); }); it("reLaunch", async () => { page = await program.reLaunch(INTERMEDIATE_PAGE_PATH); - await page.waitFor(500); + await page.waitFor('view'); await page.callMethod("navigateToOnLoadWithType", "reLaunch"); - await page.waitFor(1000); + await page.waitFor(500); page = await program.currentPage(); expect(page.path).toBe(TARGET_PAGE_PATH.substring(1)); }); it("switchTab", async () => { page = await program.reLaunch(INTERMEDIATE_PAGE_PATH); - await page.waitFor(500); + await page.waitFor('view'); await page.callMethod("navigateToOnLoadWithType", "switchTab"); - await page.waitFor(1000); page = await program.currentPage(); + await page.waitFor('view'); expect(page.path).toBe("pages/tabBar/component"); }); // toast 出现在 INTERMEDIATE_PAGE_PATH 页面(非 onLoad 生命周期所在页面) @@ -66,7 +66,7 @@ describe("onLoad", () => { // 同 toast // it("showLoading", async () => { // page = await program.reLaunch(INTERMEDIATE_PAGE_PATH); - // await page.waitFor(500); + // await page.waitFor('view'); // await page.callMethod("navigateToOnLoadWithType", "showLoading"); // await page.waitFor(1000); // const image = await program.screenshot(); @@ -75,7 +75,7 @@ describe("onLoad", () => { // 同 toast // it("showModal", async () => { // page = await program.reLaunch(INTERMEDIATE_PAGE_PATH); - // await page.waitFor(500); + // await page.waitFor('view'); // await page.callMethod("navigateToOnLoadWithType", "showModal"); // await page.waitFor(1000); // const image = await program.screenshot(); @@ -84,7 +84,7 @@ describe("onLoad", () => { // 同 toast // it("showActionSheet", async () => { // page = await program.reLaunch(INTERMEDIATE_PAGE_PATH); - // await page.waitFor(500); + // await page.waitFor('view'); // await page.callMethod("navigateToOnLoadWithType", "showActionSheet"); // await page.waitFor(1000); // const image = await program.screenshot(); diff --git a/pages/component/general-attribute/general-attribute.test.js b/pages/component/general-attribute/general-attribute.test.js index 2b3d4698..290b16a5 100644 --- a/pages/component/general-attribute/general-attribute.test.js +++ b/pages/component/general-attribute/general-attribute.test.js @@ -5,7 +5,7 @@ describe('general attribute', () => { beforeAll(async () => { page = await program.navigateTo(PAGE_PATH) - await page.waitFor(1000) + await page.waitFor('view') }) it("class & style", async () => { const image = await program.screenshot(); @@ -20,7 +20,7 @@ describe('general attribute', () => { it("ref", async () => { const button = await page.$(".btn-ref"); await button.tap(); - await page.waitFor(1000); + await page.waitFor(500); const image = await program.screenshot(); expect(image).toMatchImageSnapshot(); }); diff --git a/pages/component/general-event/general-event.test.js b/pages/component/general-event/general-event.test.js index be05d489..ded3853e 100644 --- a/pages/component/general-event/general-event.test.js +++ b/pages/component/general-event/general-event.test.js @@ -5,7 +5,7 @@ describe('event trigger sequence', () => { let el beforeAll(async () => { page = await program.navigateTo(PAGE_PATH) - await page.waitFor(1000) + await page.waitFor('view') el = await page.$('.target') }) -- GitLab