Last active
January 9, 2024 07:05
-
-
Save ManfredHu/4f7ad639816296bf5e263e961bb00494 to your computer and use it in GitHub Desktop.
小程序自动化获取所有pages截图
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 获取所有pages的截图以便确认是否页面还有用 | |
// 1. 安装 npm i miniprogram-automator jest -D | |
// 2. 项目根目录 node跑本文件 | |
// 3. 最好package.json加入test命令 | |
/* eslint-env jest */ | |
const automator = require('miniprogram-automator'); | |
const path = require('path'); | |
const appJson = require('../src/app.json'); | |
// console.log('appJson', appJson); | |
// console.log('appJson pages', appJson.pages); | |
const pwd = process.cwd(); | |
console.log('current path', pwd); | |
jest.setTimeout(99999999); | |
describe('index', () => { | |
let miniProgram; | |
let page; | |
it('title', async () => { | |
for (let i = 0; i < appJson.pages.length; i++) { | |
console.log(`登录页面${appJson.pages[i]}`); | |
page = await miniProgram.reLaunch('/' + appJson.pages[i]); | |
await page.waitFor(500); | |
const picPaht = appJson.pages[i].replace(/\//g, '-') + '.png'; | |
console.log(`图片保存路径${path.resolve(__dirname, './screenshot/', picPaht)}`); | |
await miniProgram.screenshot({ | |
path: path.resolve(__dirname, './screenshot/', picPaht), | |
}); | |
console.log(`截图${picPaht}成功`); | |
} | |
}); | |
beforeAll(async () => { | |
miniProgram = await automator.launch({ | |
projectPath: pwd, | |
}); | |
}, 30000); | |
afterAll(async () => { | |
await miniProgram.close(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment