AI_UIAutomation/tests/auth/third_party_login.test.ts

62 lines
2.7 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 { signInWithGoogle, signOut, signInWithEmail, 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(15942)} 第三方登录`; // P0:第三方(Google)登录验证
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_ThirdPartyLogin', driver.platform.toUpperCase());
});
afterAll(async () => {
reporter.generate();
await driver.destroySession();
});
it(ANCHOR, { timeout: 150000 }, async () => {
const start = Date.now();
// iOS:第三方登录跳过 —— iOS 上 Apple ID / 第三方授权强制 2FA 验证码,无可靠自动化来源(Google 路径在 iOS 亦走 Apple 系统授权)。
if (driver.platform === 'ios') {
reporter.record(ANCHOR, 'SKIP', Date.now() - start, 'iOS 第三方登录需验证码(2FA),无法自动化,跳过');
return;
}
try {
// 第三方(Google)登录:登录页 → Google → 系统账号浮层继续 → 回 App 登录成功
const ok = await signInWithGoogle(driver);
expect(ok).toBe(true);
reporter.record(ANCHOR, 'PASS', Date.now() - start, 'Google 第三方登录成功');
} catch (e: any) {
const ss = await driver.screenshot().catch(() => '');
reporter.record(ANCHOR, 'FAIL', Date.now() - start, e.message, ss);
throw e;
} finally {
// 还原:登出 Google 账号,登回主账号,避免污染其它用例
try {
await signOut(driver);
await signInWithEmail(driver);
await isLoggedIn(driver);
} catch (e: any) { console.log(`还原主账号失败(不影响本用例结果): ${e.message}`); }
}
});
// Apple 第三方登录:UI 路径已摸通(登录页 → More → Apple → webview 填 Apple ID → Continue
// → 填密码 → Sign In),但 Apple 在账号密码后强制要求**验证码(2FA)**,无可靠自动化来源 → 跳过。
// 第三方登录的 P0 覆盖由上面的 Google 路径完成。
it.skip('第三方登录-Apple(需 2FA 验证码,无法自动化)', async () => {});
});