login-withpwd.test.js 2.6 KB
Newer Older
study夏羽's avatar
study夏羽 已提交
1 2 3 4 5 6
// 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')
A
Anne_LXM 已提交
7
		await page.waitFor('view')
study夏羽's avatar
study夏羽 已提交
8
	});
A
Anne_LXM 已提交
9 10 11 12 13
	// it('screenshot',async()=>{
	// 	const image = await program.screenshot();
	// 	expect(image).toMatchImageSnapshot();
	// 	await page.waitFor(500);
	// })
study夏羽's avatar
study夏羽 已提交
14 15 16
	it('账号密码登录', async () => {
		await page.setData({
			"username": "DCloud",
study夏羽's avatar
study夏羽 已提交
17 18
			"password": "dcloud2022",
			// "password": "unistarter2022",
study夏羽's avatar
study夏羽 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
			// "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('登录成功')
				expect(resLogin.uid).toHaveLength(24);
				break;
			case "uni-id-account-not-exists":
study夏羽's avatar
study夏羽 已提交
37 38
				const expectAccountStr = ["此账号未注册","Account does not exists"]
				expect(expectAccountStr).toContain(resLogin.errMsg);
study夏羽's avatar
study夏羽 已提交
39 40 41
				await page.callMethod('toRegister')
				break;
			case "uni-id-password-error":
study夏羽's avatar
study夏羽 已提交
42 43
				const expectPasswordStr = ["密码错误","Password error"]
				expect(expectPasswordStr).toContain(resLogin.errMsg);
study夏羽's avatar
study夏羽 已提交
44 45
				await page.setData({
					"username": "DCloud",
A
Anne_LXM 已提交
46 47
					"password": "dcloud2022",
					// "password": "unistarter2022",
study夏羽's avatar
study夏羽 已提交
48 49
					"agree": true,
				})
A
Anne_LXM 已提交
50
				await page.callMethod('pwdLogin')
study夏羽's avatar
study夏羽 已提交
51 52
				break;
			case "uni-id-captcha-required":
study夏羽's avatar
study夏羽 已提交
53
				const expectCaptchaStr = ["请输入图形验证码","Captcha required"]
study夏羽's avatar
study夏羽 已提交
54
				expect(expectCaptchaStr).toContain(resLogin.errMsg);
study夏羽's avatar
study夏羽 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67
				await page.setData({
					"captcha":"1234"
				})
				const resLoginaa = await page.callMethod('pwdLogin')
				if(resLoginaa.errCode == 0){
					console.log('登录成功');
				}else{
					await page.setData({
						"username": "DCloud",
						"password": "dcloud2022",
						"captcha":"1234",
						"agree": true
					})
A
Anne_LXM 已提交
68
					await page.callMethod('pwdLogin')
study夏羽's avatar
study夏羽 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
				}
				break;
			case "uni-captcha-verify-fail":
				expect(resLogin.errMsg).toBe("验证码错误");
				break;
			case 10103:
				expect(resLogin.errMsg).toBe("密码错误次数过多");
				break;
			case 10002:
				expect(resLogin.errMsg).toBe("验证码不可为空");
				break;
			case "SYS_ERR":
				console.log("未知错误---SYS_ERR",resLogin)//[uni-id-co]: request:fail
				break;
			default:
A
Anne_LXM 已提交
84
				console.log(await program.currentPage());
study夏羽's avatar
study夏羽 已提交
85 86 87 88
				break;
		}
	})
});