From 8ddf83f2f29e43138b4ffad3ed5771b025098d1d Mon Sep 17 00:00:00 2001 From: Anne_LXM Date: Fri, 2 Aug 2024 22:59:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0showToast=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/API/show-toast/show-toast.test.js | 188 +++++------------------- pages/API/show-toast/show-toast.uvue | 185 +++++++++++++++-------- 2 files changed, 156 insertions(+), 217 deletions(-) diff --git a/pages/API/show-toast/show-toast.test.js b/pages/API/show-toast/show-toast.test.js index 4f86d4fa..43dada28 100644 --- a/pages/API/show-toast/show-toast.test.js +++ b/pages/API/show-toast/show-toast.test.js @@ -1,27 +1,19 @@ // uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/ describe('API-toast', () => { - let page; const isApp = process.env.UNI_OS_NAME === "android" || process.env.UNI_OS_NAME === "ios"; - - beforeAll(async () => { page = await program.reLaunch('/pages/API/show-toast/show-toast') - await page.waitFor(600); + await page.waitFor("view"); }); - - - it("onload-toast-test", async () => { - - + async function toScreenshot(imgName) { if (isApp) { await page.waitFor(500); const res = await page.callMethod('jest_getWindowInfo') const windowHeight = res.windowHeight * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio; - const image = await program.screenshot({ deviceShot: true, area: { @@ -31,163 +23,53 @@ describe('API-toast', () => { width:windowWidth }, }); - expect(image).toSaveImageSnapshot(); + expect(image).toSaveImageSnapshot({customSnapshotIdentifier() { + return imgName + }}) }else{ const image = await program.screenshot({ deviceShot: true, fullPage: true }); - expect(image).toSaveImageSnapshot() + expect(image).toSaveImageSnapshot({customSnapshotIdentifier() { + return imgName + }}) } - }) + await page.waitFor(500); + } - - - it("btn-toast-default-1", async () => { - const btnToastDefaultButton = await page.$('#btn-toast-default') - await btnToastDefaultButton.tap() - await page.waitFor(200) - if (isApp) { - - const res = await page.callMethod('jest_getWindowInfo') - const windowHeight = res.windowHeight * res.pixelRatio; - const windowWidth = res.windowWidth * res.pixelRatio; - - const image = await program.screenshot({ - deviceShot: true, - area: { - x: 0, - y: 200, - height: windowHeight - 200, - width:windowWidth - }, - }); - expect(image).toSaveImageSnapshot(); - }else{ - const image = await program.screenshot({ - deviceShot: true, - fullPage: true - }); - expect(image).toSaveImageSnapshot() - } + it("onload-toast-test", async () => { + await toScreenshot('toast-onload') }) - - - it("btn-toast-duration-1", async () => { - const btnToastDurationButton = await page.$('#btn-toast-duration') - await btnToastDurationButton.tap() - await page.waitFor(2000) - if (isApp) { - const res = await page.callMethod('jest_getWindowInfo') - const windowHeight = res.windowHeight * res.pixelRatio; - const windowWidth = res.windowWidth * res.pixelRatio; - const image = await program.screenshot({ - deviceShot: true, - area: { - x: 0, - y: 200, - height: windowHeight - 200, - width:windowWidth - }, - }); - expect(image).toSaveImageSnapshot(); - }else{ - const image = await program.screenshot({ - deviceShot: true, - fullPage: true - }); - expect(image).toSaveImageSnapshot() + it("icon-toast-test", async () => { + const icons = await page.$$('.radio-icon') + for (let i = 0; i < icons.length; i++) { + await icons[i].tap() + const iconText = await icons[i].text() + await page.callMethod('toast1Tap') + await page.waitFor(100); + await toScreenshot(`${iconText}`) } }) - it("btn-toast-errorIcon-1", async () => { - const btnToastErrorIconButton = await page.$('#btn-toast-errorIcon') - await btnToastErrorIconButton.tap() - await page.waitFor(200) - if (isApp) { - const res = await page.callMethod('jest_getWindowInfo') - const windowHeight = res.windowHeight * res.pixelRatio; - const windowWidth = res.windowWidth * res.pixelRatio; - const image = await program.screenshot({ - deviceShot: true, - area: { - x: 0, - y: 200, - height: windowHeight - 200, - width:windowWidth - }, - }); - expect(image).toSaveImageSnapshot(); - }else{ - const image = await program.screenshot({ - deviceShot: true, - fullPage: true - }); - expect(image).toSaveImageSnapshot() - } + it("image-toast-test", async () => { + await page.setData({imageSelect: true}) + await page.waitFor(300); + await page.callMethod('toast1Tap') + await page.waitFor(300); + await toScreenshot('toast-image') }) - - it("btn-toast-loading-1", async () => { - const btnToastLoadingButton = await page.$('#btn-toast-loading') - await btnToastLoadingButton.tap() - await page.waitFor(200) - - const btnToastHideButton = await page.$('#btn-toast-hide') - await btnToastHideButton.tap() - await page.waitFor(1000) - - if (isApp) { - const res = await page.callMethod('jest_getWindowInfo') - const windowHeight = res.windowHeight * res.pixelRatio; - const windowWidth = res.windowWidth * res.pixelRatio; - const image = await program.screenshot({ - deviceShot: true, - area: { - x: 0, - y: 200, - height: windowHeight - 200, - width:windowWidth - }, - }); - expect(image).toSaveImageSnapshot(); - }else{ - const image = await program.screenshot({ - deviceShot: true, - fullPage: true - }); - expect(image).toSaveImageSnapshot() - } + it("duration-toast-test", async () => { + await page.setData({intervalSelect: 4000}) + await page.callMethod('toast1Tap') + await page.waitFor(2000); + await toScreenshot('toast-duration-2000') + await page.waitFor(1000); + await page.callMethod('hideToast') + await page.waitFor(300); + await toScreenshot('toast-duration-end') }) - - // it("btn-toast-postion-bottom-1", async () => { - // const btnToastButton = await page.$('#btn-toast-postion-bottom') - // await btnToastButton.tap() - // await page.waitFor(200) - // if (isApp) { - // const windowHeight = uni.getWindowInfo().windowHeight; - // const windowWidth = uni.getWindowInfo().windowWidth; - // const image = await program.screenshot({ - // deviceShot: true, - // area: { - // x: 0, - // y: 200, - // height: windowHeight, - // width:windowWidth - // }, - // }); - // expect(image).toSaveImageSnapshot(); - // }else{ - // const image = await program.screenshot({ - // deviceShot: true, - // fullPage: true - // }); - // expect(image).toSaveImageSnapshot() - // } - // }) - - - }); diff --git a/pages/API/show-toast/show-toast.uvue b/pages/API/show-toast/show-toast.uvue index 3aa2c5b6..b8dc765e 100644 --- a/pages/API/show-toast/show-toast.uvue +++ b/pages/API/show-toast/show-toast.uvue @@ -1,31 +1,105 @@ - + -- GitLab