AI_UIAutomation/tests/auth/forgot_password.test.ts

50 lines
2.1 KiB
TypeScript

import { describe, it, beforeAll, afterAll, expect } from 'vitest';
import { DeviceDriver } from '../../drivers/types';
import { createDriver } from '../../drivers/factory';
import { TestReporter } from '../../utils/test-reporter';
import { registerAccount, forgotPassword, isLoggedIn, onesPlatform } from '../../utils/common';
import { setupResilientHooks } from "../../utils/common";
import * as dotenv from 'dotenv';
import * as path from 'path';
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
// 自包含:先注册一个新临时账号,再对它做忘记密码改密(不依赖会被注销/过期的写死账号)。
const ANCHOR = `${onesPlatform(15941)} 忘记密码`; // P0:忘记密码验证
describe('Auth - 忘记密码(自包含:注册新账号再改密)', () => {
let driver: DeviceDriver;
let reporter: TestReporter;
setupResilientHooks(() => driver);
beforeAll(async () => {
driver = createDriver();
await driver.createSession();
if (driver.restartApp) await driver.restartApp(); // 跨用例复位:清上个用例残留的脏态(EU区域/弹框/卡页)
reporter = new TestReporter('Auth_ForgotPassword', driver.platform.toUpperCase());
});
afterAll(async () => {
reporter.generate();
await driver.destroySession();
});
it(ANCHOR, { timeout: 300000 }, async () => {
const start = Date.now();
try {
// 1) 注册新临时账号(返回邮箱 + mail.tm token,用于收重置码)
const acct = await registerAccount(driver);
// 2) 对该账号做忘记密码改密(forgotPassword 内部会先登出再进登录表单)
const newPwd = await forgotPassword(driver, { email: acct.email, token: acct.token });
// 改密成功后会自动登录进账号 → isLoggedIn 即验证改密成功
const ok = await isLoggedIn(driver);
expect(ok).toBe(true);
reporter.record(ANCHOR, 'PASS', Date.now() - start, `${acct.email} 改密为 ${newPwd} 并自动登录`);
} catch (e: any) {
const ss = await driver.screenshot().catch(() => '');
reporter.record(ANCHOR, 'FAIL', Date.now() - start, e.message, ss);
throw e;
}
});
});