提交 351f872b 编写于 作者: Anne_LXM's avatar Anne_LXM

test:screenshot

上级 17bff4fc
const path = require('path'); const path = require('path');
module.exports = { module.exports = {
testTimeout: 50000, testTimeout: 50000,
reporters: [ reporters: ['default'],
'default'
],
watchPathIgnorePatterns: ['/node_modules/', '/dist/', '/.git/'], watchPathIgnorePatterns: ['/node_modules/', '/dist/', '/.git/'],
moduleFileExtensions: ['js', 'json'], moduleFileExtensions: ['js', 'json'],
rootDir: __dirname, rootDir: __dirname,
......
// jest官方文档: https://www.jestjs.cn/ jest.setTimeout(20000)
// uniapp自动化测试教程: https://uniapp.dcloud.io/collocation/auto/quick-start
const PAGE_PATH = '/pages/grid/grid'
jest.setTimeout(15000)
describe('grid', () => { describe('grid', () => {
let page, hasLogin; let page, hasLogin;
beforeAll(async () => { beforeAll(async () => {
page = await program.switchTab(PAGE_PATH) page = await program.switchTab('/pages/grid/grid')
await page.waitFor('view') await page.waitFor('view')
}) console.log("page", page)
it('检测宫格', async () => {
if(process.env.UNI_PLATFORM === "mp-weixin"){ if(process.env.UNI_PLATFORM === "mp-weixin"){
await page.waitFor(5000) await page.waitFor(5000)
}else{ }else{
await page.waitFor(2000) await page.waitFor(2000)
} }
})
it('检测宫格', async () => {
hasLogin = await page.data('hasLogin') hasLogin = await page.data('hasLogin')
let gridList = await page.data('gridList') let gridList = await page.data('gridList')
console.log("gridList", gridList.length,hasLogin) console.log("gridList", gridList.length,hasLogin)
......
const PAGE_PATH = '/pages/list/list'
describe('list', () => { describe('list', () => {
let page, containsVite, isApp, currentPage; let page, containsVite, isApp;
containsVite = process.env.UNI_CLI_PATH.includes('uniapp-cli-vite') containsVite = process.env.UNI_CLI_PATH.includes('uniapp-cli-vite')
isApp = process.env.UNI_PLATFORM.includes('app') isApp = process.env.UNI_PLATFORM.includes('app')
if (containsVite && isApp) { if (containsVite && isApp) {
...@@ -10,7 +9,7 @@ describe('list', () => { ...@@ -10,7 +9,7 @@ describe('list', () => {
return return
} }
beforeAll(async () => { beforeAll(async () => {
page = await program.switchTab(PAGE_PATH) page = await program.switchTab('/pages/list/list')
await page.waitFor('view') await page.waitFor('view')
await page.setData({ await page.setData({
'isTest': true 'isTest': true
...@@ -23,13 +22,13 @@ describe('list', () => { ...@@ -23,13 +22,13 @@ describe('list', () => {
console.log('getTitle: ', getTitle); console.log('getTitle: ', getTitle);
expect(getTitle.title).toBe('阿里小程序IDE官方内嵌uni-app,为开发者提供多端开发服务') expect(getTitle.title).toBe('阿里小程序IDE官方内嵌uni-app,为开发者提供多端开发服务')
}) })
it('点击搜索跳转详情页', async () => { // it('点击搜索跳转详情页', async () => {
const items = await page.$('.uni-list-item') // const items = await page.$('.uni-list-item')
await items.tap() // await items.tap()
await page.waitFor(3000) // await page.waitFor(3000)
await page.waitFor('view') // await page.waitFor('view')
currentPage = await program.currentPage() // currentPage = await program.currentPage()
console.log('currentPage: ', currentPage); // console.log('currentPage: ', currentPage);
expect(currentPage.path).toBe('pages/list/detail') // expect(currentPage.path).toBe('pages/list/detail')
}) // })
}) })
\ No newline at end of file
// jest官方文档: https://www.jestjs.cn/
// uniapp自动化测试教程: https://uniapp.dcloud.io/collocation/auto/quick-start
const PAGE_PATH = '/pages/list/search/search'
describe('search', () => { describe('search', () => {
let page, containsVite, isApp; let page, containsVite, isApp;
containsVite = process.env.UNI_CLI_PATH.includes('uniapp-cli-vite') containsVite = process.env.UNI_CLI_PATH.includes('uniapp-cli-vite')
...@@ -12,8 +9,7 @@ describe('search', () => { ...@@ -12,8 +9,7 @@ describe('search', () => {
return return
} }
beforeAll(async () => { beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH) page = await program.reLaunch('/pages/list/search/search')
console.log('pageStack', await program.pageStack())
await page.waitFor('view') await page.waitFor('view')
}) })
it('搜索发现-显示-隐藏', async () => { it('搜索发现-显示-隐藏', async () => {
......
let pageIndex = 0 let pageIndex = 0
const pages = [ 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; let page;
...@@ -25,12 +26,7 @@ describe('page screenshot test', () => { ...@@ -25,12 +26,7 @@ describe('page screenshot test', () => {
console.log("page screenshot test finish"); console.log("page screenshot test finish");
}); });
test.each(pages)('%s', async () => { test.each(pages)('%s', async () => {
// const image = await program.screenshot(); const image = await program.screenshot({deviceShot:true,fullPage:true});
// expect(image).toMatchImageSnapshot();
// await page.waitFor(500);
const image = await program.screenshot({
fullPage: true
});
expect(image).toSaveImageSnapshot(); expect(image).toSaveImageSnapshot();
await page.waitFor(500); await page.waitFor(500);
}) })
......
// jest官方文档: https://www.jestjs.cn/
// uniapp自动化测试教程: https://uniapp.dcloud.io/collocation/auto/quick-start
const PAGE_PATH = '/pages/ucenter/about/about'
describe('about', () => { describe('about', () => {
let page; let page;
if(process.env.UNI_PLATFORM === "mp-weixin"){ if(process.env.UNI_PLATFORM === "mp-weixin"){
...@@ -10,7 +7,7 @@ describe('about', () => { ...@@ -10,7 +7,7 @@ describe('about', () => {
return return
} }
beforeAll(async () => { beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH) page = await program.reLaunch('/pages/ucenter/about/about')
await page.waitFor('view') await page.waitFor('view')
}) })
it('appName', async () => { it('appName', async () => {
......
// uniapp自动化测试教程: https://uniapp-test.dcloud.net.cn/docs/testcase/start
jest.setTimeout(30000); jest.setTimeout(30000);
const PAGE_PATH = '/pages/ucenter/settings/settings'
describe('settings', () => { describe('settings', () => {
let page, hasLogin; let page, hasLogin;
if (process.env.uniTestPlatformInfo == 'ios_simulator 13.7') { if (process.env.uniTestPlatformInfo == 'ios_simulator 13.7') {
...@@ -10,7 +8,7 @@ describe('settings', () => { ...@@ -10,7 +8,7 @@ describe('settings', () => {
return return
} }
beforeAll(async () => { beforeAll(async () => {
page = await program.navigateTo(PAGE_PATH) page = await program.navigateTo('/pages/ucenter/settings/settings')
await page.waitFor('view') await page.waitFor('view')
hasLogin = await page.callMethod('hasLoginTest') hasLogin = await page.callMethod('hasLoginTest')
console.log("登录状态", hasLogin) console.log("登录状态", hasLogin)
...@@ -33,6 +31,11 @@ describe('settings', () => { ...@@ -33,6 +31,11 @@ describe('settings', () => {
expect((await el.$$('.mt10')).length).toBe(2) 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 () => { it('退出登录', async () => {
const bottomEl = await page.$('.bottom-back-text') const bottomEl = await page.$('.bottom-back-text')
expect(await bottomEl.text()).toBe('退出登录') expect(await bottomEl.text()).toBe('退出登录')
......
jest.setTimeout(30000); jest.setTimeout(30000);
const PAGE_PATH = '/pages/ucenter/ucenter'
describe('ucenter', () => { describe('ucenter', () => {
let page, platform, hasLogin; let page, platform, hasLogin;
platform = process.env.UNI_PLATFORM platform = process.env.UNI_PLATFORM
...@@ -11,7 +10,7 @@ describe('ucenter', () => { ...@@ -11,7 +10,7 @@ describe('ucenter', () => {
return return
} }
beforeAll(async () => { beforeAll(async () => {
page = await program.switchTab(PAGE_PATH) page = await program.switchTab('/pages/ucenter/ucenter')
await page.waitFor('view') await page.waitFor('view')
hasLogin = await page.callMethod('hasLoginTest') hasLogin = await page.callMethod('hasLoginTest')
console.log("登录状态", hasLogin, platform) console.log("登录状态", hasLogin, platform)
...@@ -57,14 +56,9 @@ describe('ucenter', () => { ...@@ -57,14 +56,9 @@ describe('ucenter', () => {
console.log("签到失败"); console.log("签到失败");
} }
}) })
// it('screenshot',async()=>{ it('screenshot', async () => {
// await program.screenshot({ const image = await program.screenshot({deviceShot:true,fullPage:true});
// path: "static/screenshot/ucenter.png" expect(image).toSaveImageSnapshot();
// }) await page.waitFor(500);
// const image = await program.screenshot({ })
// fullPage: true
// })
// expect(image).toSaveImageSnapshot();
// await page.waitFor(500);
// })
}) })
\ No newline at end of file
const Sequencer = require("@jest/test-sequencer").default; 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 { class CustomSequencer extends Sequencer {
sort(tests) { sort(tests) {
// 测试例排序 // 测试例排序
......
...@@ -29,11 +29,10 @@ describe('userinfo', () => { ...@@ -29,11 +29,10 @@ describe('userinfo', () => {
console.log("update--nickname---2", userInfo.nickname) console.log("update--nickname---2", userInfo.nickname)
expect(userInfo.nickname).toBe(nickname) expect(userInfo.nickname).toBe(nickname)
}) })
it("screenshot", async () => { it('screenshot', async () => {
await program.screenshot({ const image = await program.screenshot({deviceShot:true,fullPage:true});
path: "static/screenshot/userinfo.png" // 默认项目根目录 expect(image).toSaveImageSnapshot();
}) await page.waitFor(500);
await page.waitFor(500)
}) })
// it("头像", async () => { // it("头像", async () => {
// const imgs = [ // const imgs = [
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册