pwd-login.test.js 2.1 KB
Newer Older
study夏羽's avatar
study夏羽 已提交
1 2 3 4 5 6 7
// jest官方文档: https://www.jestjs.cn/
// uniapp自动化测试教程: https://uniapp.dcloud.io/collocation/auto/quick-start

describe('pages/ucenter/login-page/pwd-login/pwd-login.vue', () => {

	let page
	beforeAll(async () => {
study夏羽's avatar
测试  
study夏羽 已提交
8
		page = await program.redirectTo('/pages/ucenter/login-page/pwd-login/pwd-login')
study夏羽's avatar
study夏羽 已提交
9 10 11 12 13 14 15 16 17
		await page.waitFor(500)
	})

	it('前往注册页', async () => {
		// expect.assertions(2);
		const resReg = await page.callMethod('toRegister')
		await page.waitFor(300)
		expect((await program.currentPage()).path).toBe(
			'pages/ucenter/login-page/register/register')
study夏羽's avatar
测试  
study夏羽 已提交
18 19 20 21 22
			console.log(await program.currentPage(),"111111111");
		// await page.waitFor(500)
		// 执行 navigateBack 验证是否返回navigateTo
		// expect((await program.navigateBack()).path).toBe(
		// 	'pages/ucenter/login-page/pwd-login/pwd-login')
study夏羽's avatar
study夏羽 已提交
23 24 25 26 27 28 29 30
	})

	it('跳转到忘记密码页', async () => {
		const resPwd = await page.callMethod('toRetrievePwd')

		await page.waitFor(300)
		expect((await program.currentPage()).path).toBe(
			'pages/ucenter/login-page/pwd-retrieve/pwd-retrieve')
study夏羽's avatar
测试  
study夏羽 已提交
31 32
		console.log(await program.currentPage(),"222222");
		// await page.waitFor(500)
study夏羽's avatar
study夏羽 已提交
33
		// 执行 navigateBack 验证是否返回
study夏羽's avatar
测试  
study夏羽 已提交
34 35
		// expect((await program.navigateBack()).path).toBe(
		// 	'pages/ucenter/login-page/pwd-login/pwd-login')
study夏羽's avatar
study夏羽 已提交
36 37 38 39 40 41 42 43 44 45 46
	})

	it('用户名密码登录', async () => {
		// expect.assertions(1);
		const setForm = await page.setData({
			"password": "111111",
			"username": "数字天堂",
			"agree": true,
		})
		const resLogin = await page.callMethod('pwdLogin')
		console.log("resLogin: ", resLogin.msg);
study夏羽's avatar
study夏羽 已提交
47 48 49 50
		
		switch (resLogin.msg){
			case 10102:
				expect(resLogin.msg).toBe("密码错误");
study夏羽's avatar
测试  
study夏羽 已提交
51
				await page.setData({
study夏羽's avatar
study夏羽 已提交
52 53 54 55
					"password": "222222",
					"username": "数字天堂",
					"agree": true,
				})
study夏羽's avatar
测试  
study夏羽 已提交
56
				await page.callMethod('pwdLogin')
study夏羽's avatar
study夏羽 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69
				break;
			case 10103:
				expect(resLogin.msg).toBe("密码错误次数过多");
				break;
			case 10002:
				expect(resLogin.msg).toBe("验证码不可为空");
				break;
			case 0:
				expect(resLogin.msg).toBe("登录成功");
				break;
			default:
				break;
		}
study夏羽's avatar
study夏羽 已提交
70 71 72
	})

})