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

test:screenshot

上级 17bff4fc
const path = require('path');
module.exports = {
testTimeout: 50000,
reporters: [
'default'
],
reporters: ['default'],
watchPathIgnorePatterns: ['/node_modules/', '/dist/', '/.git/'],
moduleFileExtensions: ['js', 'json'],
rootDir: __dirname,
......
// 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)
......
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
// 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 () => {
......
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,12 +26,7 @@ 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
});
const image = await program.screenshot({deviceShot:true,fullPage:true});
expect(image).toSaveImageSnapshot();
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', () => {
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 () => {
......
// 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('退出登录')
......
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
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) {
// 测试例排序
......
......@@ -29,11 +29,10 @@ describe('userinfo', () => {
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 = [
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册