From 351f872b75ccefd75c134441595d62e849511cb7 Mon Sep 17 00:00:00 2001 From: Anne_LXM Date: Wed, 29 May 2024 14:49:24 +0800 Subject: [PATCH] test:screenshot --- jest.config.js | 4 +--- pages/grid/grid.test.js | 12 ++++------ pages/list/list.test.js | 23 +++++++++---------- pages/list/search/search.test.js | 6 +---- pages/pages.test.js | 14 ++++------- pages/ucenter/about/about.test.js | 5 +--- pages/ucenter/settings/settings.test.js | 9 +++++--- pages/ucenter/ucenter.test.js | 18 +++++---------- testSequencer.js | 2 +- .../pages/userinfo/userinfo.test.js | 13 +++++------ 10 files changed, 43 insertions(+), 63 deletions(-) diff --git a/jest.config.js b/jest.config.js index ed01f40..624aae5 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,9 +1,7 @@ const path = require('path'); module.exports = { testTimeout: 50000, - reporters: [ - 'default' - ], + reporters: ['default'], watchPathIgnorePatterns: ['/node_modules/', '/dist/', '/.git/'], moduleFileExtensions: ['js', 'json'], rootDir: __dirname, diff --git a/pages/grid/grid.test.js b/pages/grid/grid.test.js index 8078ab9..b17b992 100644 --- a/pages/grid/grid.test.js +++ b/pages/grid/grid.test.js @@ -1,19 +1,17 @@ -// jest官方文档: https://www.jestjs.cn/ -// uniapp自动化测试教程: https://uniapp.dcloud.io/collocation/auto/quick-start -const PAGE_PATH = '/pages/grid/grid' -jest.setTimeout(15000) +jest.setTimeout(20000) describe('grid', () => { let page, hasLogin; beforeAll(async () => { - page = await program.switchTab(PAGE_PATH) + page = await program.switchTab('/pages/grid/grid') await page.waitFor('view') - }) - it('检测宫格', async () => { + console.log("page", page) if(process.env.UNI_PLATFORM === "mp-weixin"){ await page.waitFor(5000) }else{ await page.waitFor(2000) } + }) + it('检测宫格', async () => { hasLogin = await page.data('hasLogin') let gridList = await page.data('gridList') console.log("gridList", gridList.length,hasLogin) diff --git a/pages/list/list.test.js b/pages/list/list.test.js index fd36354..9423526 100644 --- a/pages/list/list.test.js +++ b/pages/list/list.test.js @@ -1,6 +1,5 @@ -const PAGE_PATH = '/pages/list/list' describe('list', () => { - let page, containsVite, isApp, currentPage; + let page, containsVite, isApp; containsVite = process.env.UNI_CLI_PATH.includes('uniapp-cli-vite') isApp = process.env.UNI_PLATFORM.includes('app') if (containsVite && isApp) { @@ -10,7 +9,7 @@ describe('list', () => { return } beforeAll(async () => { - page = await program.switchTab(PAGE_PATH) + page = await program.switchTab('/pages/list/list') await page.waitFor('view') await page.setData({ 'isTest': true @@ -23,13 +22,13 @@ describe('list', () => { console.log('getTitle: ', getTitle); expect(getTitle.title).toBe('阿里小程序IDE官方内嵌uni-app,为开发者提供多端开发服务') }) - it('点击搜索跳转详情页', async () => { - const items = await page.$('.uni-list-item') - await items.tap() - await page.waitFor(3000) - await page.waitFor('view') - currentPage = await program.currentPage() - console.log('currentPage: ', currentPage); - expect(currentPage.path).toBe('pages/list/detail') - }) + // it('点击搜索跳转详情页', async () => { + // const items = await page.$('.uni-list-item') + // await items.tap() + // await page.waitFor(3000) + // await page.waitFor('view') + // currentPage = await program.currentPage() + // console.log('currentPage: ', currentPage); + // expect(currentPage.path).toBe('pages/list/detail') + // }) }) \ No newline at end of file diff --git a/pages/list/search/search.test.js b/pages/list/search/search.test.js index dd4714f..9816a26 100644 --- a/pages/list/search/search.test.js +++ b/pages/list/search/search.test.js @@ -1,6 +1,3 @@ -// jest官方文档: https://www.jestjs.cn/ -// uniapp自动化测试教程: https://uniapp.dcloud.io/collocation/auto/quick-start -const PAGE_PATH = '/pages/list/search/search' describe('search', () => { let page, containsVite, isApp; containsVite = process.env.UNI_CLI_PATH.includes('uniapp-cli-vite') @@ -12,8 +9,7 @@ describe('search', () => { return } beforeAll(async () => { - page = await program.reLaunch(PAGE_PATH) - console.log('pageStack', await program.pageStack()) + page = await program.reLaunch('/pages/list/search/search') await page.waitFor('view') }) it('搜索发现-显示-隐藏', async () => { diff --git a/pages/pages.test.js b/pages/pages.test.js index 8d9e847..fb045e4 100644 --- a/pages/pages.test.js +++ b/pages/pages.test.js @@ -1,6 +1,7 @@ let pageIndex = 0 const pages = [ - '/uni_modules/uni-id-pages/pages/login/login-withpwd' + '/uni_modules/uni-id-pages/pages/login/login-withpwd', + '/pages/grid/grid' ] let page; @@ -25,13 +26,8 @@ describe('page screenshot test', () => { console.log("page screenshot test finish"); }); test.each(pages)('%s', async () => { - // const image = await program.screenshot(); - // expect(image).toMatchImageSnapshot(); - // await page.waitFor(500); - const image = await program.screenshot({ - fullPage: true - }); - expect(image).toSaveImageSnapshot(); - await page.waitFor(500); + const image = await program.screenshot({deviceShot:true,fullPage:true}); + expect(image).toSaveImageSnapshot(); + await page.waitFor(500); }) }) \ No newline at end of file diff --git a/pages/ucenter/about/about.test.js b/pages/ucenter/about/about.test.js index 531ae58..19a8faa 100644 --- a/pages/ucenter/about/about.test.js +++ b/pages/ucenter/about/about.test.js @@ -1,6 +1,3 @@ -// jest官方文档: https://www.jestjs.cn/ -// uniapp自动化测试教程: https://uniapp.dcloud.io/collocation/auto/quick-start -const PAGE_PATH = '/pages/ucenter/about/about' describe('about', () => { let page; if(process.env.UNI_PLATFORM === "mp-weixin"){ @@ -10,7 +7,7 @@ describe('about', () => { return } beforeAll(async () => { - page = await program.reLaunch(PAGE_PATH) + page = await program.reLaunch('/pages/ucenter/about/about') await page.waitFor('view') }) it('appName', async () => { diff --git a/pages/ucenter/settings/settings.test.js b/pages/ucenter/settings/settings.test.js index 09ebc04..8c1eb4d 100644 --- a/pages/ucenter/settings/settings.test.js +++ b/pages/ucenter/settings/settings.test.js @@ -1,6 +1,4 @@ -// uniapp自动化测试教程: https://uniapp-test.dcloud.net.cn/docs/testcase/start jest.setTimeout(30000); -const PAGE_PATH = '/pages/ucenter/settings/settings' describe('settings', () => { let page, hasLogin; if (process.env.uniTestPlatformInfo == 'ios_simulator 13.7') { @@ -10,7 +8,7 @@ describe('settings', () => { return } beforeAll(async () => { - page = await program.navigateTo(PAGE_PATH) + page = await program.navigateTo('/pages/ucenter/settings/settings') await page.waitFor('view') hasLogin = await page.callMethod('hasLoginTest') console.log("登录状态", hasLogin) @@ -33,6 +31,11 @@ describe('settings', () => { expect((await el.$$('.mt10')).length).toBe(2) } }) + it('screenshot', async () => { + const image = await program.screenshot({deviceShot:true,fullPage:true}); + expect(image).toSaveImageSnapshot(); + await page.waitFor(500); + }) it('退出登录', async () => { const bottomEl = await page.$('.bottom-back-text') expect(await bottomEl.text()).toBe('退出登录') diff --git a/pages/ucenter/ucenter.test.js b/pages/ucenter/ucenter.test.js index 3c41745..5cf1e11 100644 --- a/pages/ucenter/ucenter.test.js +++ b/pages/ucenter/ucenter.test.js @@ -1,5 +1,4 @@ jest.setTimeout(30000); -const PAGE_PATH = '/pages/ucenter/ucenter' describe('ucenter', () => { let page, platform, hasLogin; platform = process.env.UNI_PLATFORM @@ -11,7 +10,7 @@ describe('ucenter', () => { return } beforeAll(async () => { - page = await program.switchTab(PAGE_PATH) + page = await program.switchTab('/pages/ucenter/ucenter') await page.waitFor('view') hasLogin = await page.callMethod('hasLoginTest') console.log("登录状态", hasLogin, platform) @@ -57,14 +56,9 @@ describe('ucenter', () => { console.log("签到失败"); } }) - // it('screenshot',async()=>{ - // await program.screenshot({ - // path: "static/screenshot/ucenter.png" - // }) - // const image = await program.screenshot({ - // fullPage: true - // }) - // expect(image).toSaveImageSnapshot(); - // await page.waitFor(500); - // }) + it('screenshot', async () => { + const image = await program.screenshot({deviceShot:true,fullPage:true}); + expect(image).toSaveImageSnapshot(); + await page.waitFor(500); + }) }) \ No newline at end of file diff --git a/testSequencer.js b/testSequencer.js index 0f98e18..204b300 100644 --- a/testSequencer.js +++ b/testSequencer.js @@ -1,5 +1,5 @@ const Sequencer = require("@jest/test-sequencer").default; -const sortTestFilenames = ["list.test.js","search.test.js","grid.test.js","about.test.js","register.test.js","login-withpwd.test.js","userinfo.test.js","ucenter.test.js","settings.test.js","pages.test.js"]; +const sortTestFilenames = ["grid.test.js","list.test.js","search.test.js","about.test.js","register.test.js","login-withpwd.test.js","userinfo.test.js","ucenter.test.js","settings.test.js","pages.test.js"]; class CustomSequencer extends Sequencer { sort(tests) { // 测试例排序 diff --git a/uni_modules/uni-id-pages/pages/userinfo/userinfo.test.js b/uni_modules/uni-id-pages/pages/userinfo/userinfo.test.js index 61acf72..f2b1f3f 100644 --- a/uni_modules/uni-id-pages/pages/userinfo/userinfo.test.js +++ b/uni_modules/uni-id-pages/pages/userinfo/userinfo.test.js @@ -28,13 +28,12 @@ describe('userinfo', () => { userInfo = await page.callMethod('userInfoTest') console.log("update--nickname---2", userInfo.nickname) expect(userInfo.nickname).toBe(nickname) - }) - it("screenshot", async () => { - await program.screenshot({ - path: "static/screenshot/userinfo.png" // 默认项目根目录 - }) - await page.waitFor(500) - }) + }) + it('screenshot', async () => { + const image = await program.screenshot({deviceShot:true,fullPage:true}); + expect(image).toSaveImageSnapshot(); + await page.waitFor(500); + }) // it("头像", async () => { // const imgs = [ // "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-52b18b34-3a3e-4861-89a0-c362c7634787/5105c383-8d83-4f40-938e-7c32c5983f8d.png", -- GitLab