提交 d036fe46 编写于 作者: A Anne_LXM

update test

上级 22c3df46
......@@ -7,22 +7,18 @@ describe('pages/grid/grid.vue', () => {
page = await program.switchTab('/pages/grid/grid')
await page.waitFor('view')
})
it('检测宫格', async () => {
expect.assertions(1);
expect.assertions(2);
expect((await page.data('gridList')).length).toBe(9)
expect(await page.data('hasLogin')).toBeFalsy()
})
it('点击宫格', async () => {
if (process.env.UNI_PLATFORM === "h5" || process.env.UNI_PLATFORM.startsWith("app")) {
const perPage = await page.$('.uni-grid-wrap')
await perPage.callMethod('change')
const perPage = await page.$$('.grid-item-box')
// console.log('perPage: ',perPage);
expect(perPage.length).toBe(3)
for (var i = 0; i < perPage.length; i++) {
await perPage[i].tap()
await page.waitFor(300)
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
await page.waitFor('uni-grid')
const uniGrid = await page.$('uni-grid')
await uniGrid.callMethod('change')
}
await page.waitFor(500)
})
});
\ No newline at end of file
describe('pages/list/list.vue', () => {
let page
beforeAll(async () => {
page = await program.switchTab('/pages/list/list')
await page.waitFor('view')
if(process.env.UNI_PLATFORM === "mp-weixin"){await page.waitFor(2000)}
})
it('检测标题', async () => {
// expect.assertions(1);
......
let pageIndex = 0
const pages = [
'/pages/ucenter/settings/settings',
'/pages/ucenter/ucenter',
'/uni_modules/uni-id-pages/pages/login/login-withoutpwd'
]
let page;
describe('page screenshot test', () => {
beforeAll(async () => {
console.log("page screenshot test start");
});
beforeEach(async () => {
page = await program.reLaunch(pages[pageIndex]);
await page.waitFor(1000);
});
afterEach(() => {
pageIndex++;
});
afterAll(() => {
console.log("page screenshot test finish");
});
test.each(pages)('%s', async () => {
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
await page.waitFor(500);
})
})
\ No newline at end of file
......@@ -6,7 +6,9 @@ describe('pages/ucenter/settings/settings', () => {
try {
page = await program.navigateTo('/pages/ucenter/settings/settings')
await page.waitFor('view')
uniToken = await page.data('uniToken')
uniToken = await program.callUniMethod('getStorageSync', 'uni_id_token')
// console.log("uniToken: ",uniToken);
if(!uniToken)return;
} catch (err) {
console.log("err: ",err);
}
......@@ -20,11 +22,20 @@ describe('pages/ucenter/settings/settings', () => {
const el = await page.$('.content')
await page.waitFor('view')
expect.assertions(1);
let res = await el.$$('.mt10')
expect((await el.$$('.mt10')).length).toBe(2)
}
})
it('screenshot',async()=>{
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
await page.waitFor(500);
})
it('退出登录', async () => {
if(uniToken){await page.callMethod('changeLoginState')}
const bottomEl = await page.$('.bottom-back-text')
expect(await bottomEl.text()).toBe('退出登录')
await page.callMethod('changeLoginState')
await page.waitFor(500)
console.log(await program.currentPage());
})
......
......@@ -39,8 +39,7 @@
supportMode:[],
pushIsOn:"wait",
currentLanguage:"",
userInfo:{},
uniToken:''
userInfo:{}
}
},
computed: {
......@@ -69,10 +68,6 @@
})
// #endif
},
onReady() {
this.uniToken = uni.getStorageSync('uni_id_token')
console.log("uniToken: ",this.uniToken);
},
onShow() {
// 检查手机端获取推送是否开启
//#ifdef APP-PLUS
......
jest.setTimeout(20000);
describe('pages/ucenter/ucenter.vue', () => {
let page,uniToken,platform;
beforeAll(async () => {
try{
page = await program.switchTab('/pages/ucenter/ucenter')
await page.waitFor('view')
uniToken = await page.data('uniToken')
uniToken = await program.callUniMethod('getStorageSync', 'uni_id_token')
platform = process.env.UNI_PLATFORM
console.log("uniToken: ",platform,uniToken);
if(!uniToken){
......@@ -16,16 +16,9 @@ describe('pages/ucenter/ucenter.vue', () => {
console.log("err: ",err);
}
})
beforeEach(async () => {
console.log('beforeEach')
jest.setTimeout(10000);
return;
});
it('宫格', async () => {
expect.assertions(1);
const getGrid = await page.data('gridList')
console.log('getGrid: ',getGrid);
// await page.waitFor(300)
expect(getGrid.length).toBe(4)
})
it('列表', async () => {
......@@ -39,48 +32,48 @@ describe('pages/ucenter/ucenter.vue', () => {
it('普通签到', async () => {
console.log("普通签到");
// await page.waitFor('uni-sign-in')
if(uniToken && platform.startsWith("app")){
await page.callMethod('signInByAd')
await page.waitFor(500)
await page.callMethod('share')
await program.screenshot({
path: "static/screenshot/sign-app.png"
})
}else if(uniToken && platform === "h5"){
await page.callMethod('signIn')
if(!uniToken)return;
if(platform.startsWith("app")){
await page.callMethod('signInByAd')
await page.waitFor(500)
await program.screenshot({
path: "static/screenshot/sign-h5.png"
})
await page.callMethod('share')
// await program.screenshot({
// path: "static/screenshot/sign-app.png"
// })
}else if(platform === "h5"){
await page.callMethod('signIn')
// await page.waitFor(500)
// await program.screenshot({
// path: "static/screenshot/sign-h5.png"
// })
}else{
await page.callMethod('signIn')
await page.waitFor(500)
await program.screenshot({
path: "static/screenshot/sign-weixin.png"
})
// await page.waitFor(500)
// await program.screenshot({
// path: "static/screenshot/sign-weixin.png"
// })
}
})
it('我的积分', async () => {
if(uniToken){
const getScoreRes = await page.callMethod('getScore')
let scoreInfo = getScoreRes && getScoreRes.result.data[0]
console.log('scoreInfo: ',scoreInfo);
await page.waitFor(500)
if (scoreInfo) {
expect.assertions(2);
expect(scoreInfo.score).not.toBeUndefined();
expect(scoreInfo.balance).toBeGreaterThanOrEqual(scoreInfo.score);
} else {
console.log("签到失败");
}
}else{
console.log("getScoreRes: 未登录");
try{
await program.navigateTo('/uni_modules/uni-id-pages/pages/login/login-withpwd')
}catch(e){
console.log("e: ",e);
}
if(!uniToken)return;
const getScoreRes = await page.callMethod('getScore')
let scoreInfo = getScoreRes && getScoreRes.result.data[0]
console.log('scoreInfo: ',scoreInfo);
await page.waitFor(500)
if (scoreInfo) {
expect.assertions(2);
expect(scoreInfo.score).not.toBeUndefined();
expect(scoreInfo.balance).toBeGreaterThanOrEqual(scoreInfo.score);
} else {
console.log("签到失败");
}
})
it('screenshot',async()=>{
await program.screenshot({
path: "static/screenshot/ucenter.png"
})
await page.waitFor(500);
})
})
......@@ -142,8 +142,7 @@
"style": "solid", // 边框样式
"radius": "100%" // 边框圆角,支持百分比
}
},
uniToken:''
}
}
},
onLoad() {
......@@ -158,10 +157,6 @@
//#endif
},
onShow() {},
onReady() {
this.uniToken = uni.getStorageSync('uni_id_token')
console.log("uniToken: ----", this.uniToken);
},
computed: {
userInfo() {
return store.userInfo
......
const Sequencer = require("@jest/test-sequencer").default;
const sortTestFilenames = ["list.test.js","grid.test.js","search.test.js","about.test.js","register.test.js","login-withpwd.test.js","ucenter.test.js","userinfo.test.js","settings.test.js"];
const sortTestFilenames = ["list.test.js","search.test.js","grid.test.js","about.test.js","register.test.js","login-withpwd.test.js","ucenter.test.js","userinfo.test.js","settings.test.js"];
class CustomSequencer extends Sequencer {
sort(tests) {
// 测试例排序
......@@ -13,4 +13,4 @@ class CustomSequencer extends Sequencer {
return [...new Set([...sortTests, ...copyTests])];
}
}
module.exports = CustomSequencer;
module.exports = CustomSequencer;
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.io/collocation/auto/hbuilderx-extension/index
describe('uni_modules/uni-id-pages/pages/login/login-withpwd.vue', () => {
let page;
beforeAll(async () => {
page = await program.navigateTo('/uni_modules/uni-id-pages/pages/login/login-withpwd')
await page.waitFor('view')
page = await program.currentPage()
});
it('screenshot',async()=>{
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
await page.waitFor(500);
})
it('账号密码登录', async () => {
await page.setData({
"username": "DCloud",
......@@ -17,18 +19,17 @@ describe('uni_modules/uni-id-pages/pages/login/login-withpwd.vue', () => {
// "captcha":"1234",
"agree": true
})
const needCaptcha = await page.data('needCaptcha')
if(needCaptcha){
await page.setData({
"captcha":"1234"
})
}
const resLogin = await page.callMethod('pwdLogin')
console.log("resLogin: ", resLogin);
switch (resLogin.errCode){
case 0:
console.log('登录成功')
......@@ -86,5 +87,4 @@ describe('uni_modules/uni-id-pages/pages/login/login-withpwd.vue', () => {
break;
}
})
});
......@@ -6,52 +6,42 @@ describe('uni_modules/uni-id-pages/pages/userinfo/bind-mobile/bind-mobile.vue',
beforeAll(async () => {
try {
isWX = process.env.UNI_PLATFORM === "mp-weixin"
if(!isWX){
page = await program.reLaunch('/uni_modules/uni-id-pages/pages/userinfo/bind-mobile/bind-mobile')
await page.waitFor(500)
uniToken = await page.data('uniToken')
uniToken = await program.callUniMethod('getStorageSync', 'uni_id_token')
console.log("uniToken: ",uniToken);
console.log("await program.pageStack(): ", await program.pageStack());
}
} catch (e) {
console.log("e: ",e);
}
})
it('绑定手机号', async () => {
if(!isWX && uniToken){
await page.setData({
formData: {
mobile: "17769516019",
code: "123456",
captcha: "1234"
},
})
await page.waitFor(300)
const submitRes = await page.callMethod('submit')
console.log("submitRes: ",submitRes);
switch (submitRes.errCode){
case "uni-id-mobile-verify-code-error":
expect(submitRes.errMsg).toBe("手机验证码错误或已过期");
break;
case "uni-captcha-verify-fail":
expect(submitRes.errMsg).toBe("验证码错误");
break;
case "uni-id-param-required":
expect(submitRes.errMsg).toBe("缺少参数: token");
break;
default:
console.log(await program.currentPage(),"currentPage---------");
break;
}
if(!uniToken)return;
await page.setData({
formData: {
mobile: "17769516019",
code: "123456",
captcha: "1234"
},
})
await page.waitFor(300)
const submitRes = await page.callMethod('submit')
console.log("submitRes: ",submitRes);
switch (submitRes.errCode){
case "uni-id-mobile-verify-code-error":
expect(submitRes.errMsg).toBe("手机验证码错误或已过期");
break;
case "uni-captcha-verify-fail":
expect(submitRes.errMsg).toBe("验证码错误");
break;
case "uni-id-param-required":
expect(submitRes.errMsg).toBe("缺少参数: token");
break;
default:
console.log(await program.currentPage(),"currentPage---------");
break;
}
})
});
......@@ -11,9 +11,7 @@ describe('uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd.vue', ()
} catch (e) {
console.log("e: ",e);
}
})
it('修改密码', async () => {
await page.setData({
formData: {
......@@ -26,7 +24,6 @@ describe('uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd.vue', ()
await page.waitFor(300)
const submitRes = await page.callMethod('submit')
console.log("submitRes: ",submitRes);
switch (submitRes.errCode){
case 0:
console.log('修改成功')
......@@ -41,8 +38,5 @@ describe('uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd.vue', ()
console.log(await program.currentPage(),"currentPage---------");
break;
}
})
});
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.io/collocation/auto/hbuilderx-extension/index
describe('uni_modules/uni-id-pages/pages/userinfo/userinfo.vue', () => {
let page,uniToken;
beforeAll(async () => {
page = await program.navigateTo('/uni_modules/uni-id-pages/pages/userinfo/userinfo')
await page.waitFor(500)
console.log(await program.pageStack());
uniToken = await page.data('uniToken')
await page.waitFor("view")
uniToken = await program.callUniMethod('getStorageSync', 'uni_id_token')
console.log("uniToken: ",uniToken);
console.log("pageStack: ",await program.pageStack());
});
it("昵称", async () => {
if(uniToken){
const nickname = "数字天堂DCloud" + Math.round(Math.random() * 10);
await page.waitFor(300)
await page.callMethod("setNickname", nickname)
}
if(!uniToken)return;
const nickname = "数字天堂DCloud" + Math.round(Math.random() * 10);
await page.waitFor(300)
await page.callMethod("setNickname", nickname)
})
it("头像", async () => {
if(!uniToken)return;
const imgs = [
"https://vkceyugu.cdn.bspapp.com/VKCEYUGU-52b18b34-3a3e-4861-89a0-c362c7634787/5105c383-8d83-4f40-938e-7c32c5983f8d.png",
"https://vkceyugu.cdn.bspapp.com/VKCEYUGU-52b18b34-3a3e-4861-89a0-c362c7634787/61869c72-3117-4ea4-8d6d-ebb67617c7d9.jpg",
......@@ -31,25 +27,19 @@ describe('uni_modules/uni-id-pages/pages/userinfo/userinfo.vue', () => {
url:imgs[Math.floor(Math.random()*imgs.length)]
}
console.log("avatar_file: ",avatar_file);
if (uniToken && process.env.UNI_PLATFORM != "mp-weixin") {
if (process.env.UNI_PLATFORM != "mp-weixin") {
const elBox = await page.$('.box')
// console.log("elBox: ",elBox);
await elBox.callMethod('setAvatarFile',avatar_file)
}else{
await page.waitFor(500)
await program.screenshot({
path: "static/screenshot/userinfo.png" // 默认项目根目录
})
}else{
await page.waitFor(500)
await program.screenshot({
path: "static/screenshot/userinfo-mp.png" // 默认项目根目录
})
}
// if (process.env.UNI_PLATFORM != "mp-weixin") {
// await program.screenshot({
// path: "static/screenshot/userinfo.png" // 默认项目根目录
// })
// }
})
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册