AI_UIAutomation/tests/auth/eu_login.test.ts

56 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 { signInWithEmail, signOut, isLoggedIn, onesPlatform } from '../../utils/common';
import { setupResilientHooks } from "../../utils/common";
import { getAccountCredentials, getEuAccountCredentials } from '../../config/account.config';
import * as dotenv from 'dotenv';
import * as path from 'path';
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
const ANCHOR = `${onesPlatform(227290)} 欧区账号登录`; // 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_EuLogin', driver.platform.toUpperCase());
});
afterAll(async () => {
reporter.generate();
await driver.destroySession();
});
it(ANCHOR, { timeout: 180000 }, async () => {
const start = Date.now();
const eu = getEuAccountCredentials();
const main = getAccountCredentials();
try {
// 登录欧区账号
await signInWithEmail(driver, eu);
expect(await isLoggedIn(driver)).toBe(true);
console.log(`欧区账号登录成功: ${eu.email}`);
// 登录欧区账号后:登出,再登回常用(主)账号
await signOut(driver);
await signInWithEmail(driver, main);
expect(await isLoggedIn(driver)).toBe(true);
console.log(`已登回常用账号: ${main.email}`);
reporter.record(ANCHOR, 'PASS', Date.now() - start, `欧区 ${eu.email} 登录成功,并登回常用账号 ${main.email}`);
} catch (e: any) {
const ss = await driver.screenshot().catch(() => '');
reporter.record(ANCHOR, 'FAIL', Date.now() - start, e.message, ss);
throw e;
}
});
});