53 lines
3.6 KiB
JavaScript
53 lines
3.6 KiB
JavaScript
// 验证旧商务登录外观和三步找回密码;短信接口始终使用测试响应。
|
|
const fs=require('node:fs/promises');
|
|
const path=require('node:path');
|
|
const {chromium}=require(process.env.SW_PLAYWRIGHT_MODULE||'playwright');
|
|
(async()=>{
|
|
const browser=await chromium.launch({channel:'chrome',headless:true});
|
|
const calls=[];
|
|
try {
|
|
const context=await browser.newContext({viewport:{width:1440,height:1000}});
|
|
const page=await context.newPage();
|
|
const errors=[];page.on('pageerror',e=>errors.push(e.message));
|
|
await page.route('http://127.0.0.1:8080/api/**',async route=>{
|
|
const request=route.request();const uri=new URL(request.url());const apiPath=uri.pathname.slice(4);
|
|
if(apiPath.startsWith('/sw/auth/forgot-password/')){
|
|
const action=apiPath.split('/').pop();const payload=request.postDataJSON();calls.push({action,payload});
|
|
const data=action==='verify-code'?{resetToken:'a'.repeat(64)}:action==='reset'?{}:{maskedPhone:'138****8000'};
|
|
await route.fulfill({json:{code:0,msg:'成功',data}});return;
|
|
}
|
|
if(apiPath==='/base/captcha'){
|
|
const response=await route.fetch({url:'http://127.0.0.1:18000/base/captcha'});const body=await response.json();body.data.openCaptcha=true;await route.fulfill({response,json:body});return;
|
|
}
|
|
await route.continue();
|
|
});
|
|
await page.goto('http://127.0.0.1:8080/#/login');
|
|
await page.getByText('欢迎登录',{exact:true}).waitFor();
|
|
await page.getByPlaceholder('请输入验证码',{exact:true}).waitFor();
|
|
if(await page.title()!=='遨游龙翔游戏平台')throw new Error('页面标题没有使用旧商务名称');
|
|
if(!await page.getByAltText('遨游龙翔游戏平台',{exact:true}).isVisible())throw new Error('旧品牌图片未显示');
|
|
await page.screenshot({path:path.join(process.env.TEMP,'sw-kra-login-desktop.png'),fullPage:true,animations:'disabled'});
|
|
await page.getByRole('button',{name:'忘记密码?'}).click();
|
|
const dialog=page.getByRole('dialog',{name:'找回密码'});
|
|
await dialog.getByPlaceholder('请输入您注册的商务账号').fill('demo_biz');
|
|
await dialog.getByRole('button',{name:'下一步',exact:true}).click();
|
|
await dialog.getByText('138****8000',{exact:true}).waitFor();
|
|
await dialog.getByPlaceholder('请输入 6 位验证码').fill('123456');
|
|
await dialog.getByRole('button',{name:'下一步',exact:true}).click();
|
|
await dialog.getByPlaceholder('6-15 位字符').fill('abc123');
|
|
await dialog.getByPlaceholder('请再次输入新密码').fill('abc123');
|
|
await dialog.getByRole('button',{name:'完成',exact:true}).click();
|
|
await dialog.waitFor({state:'hidden'});
|
|
const actions=calls.map(c=>c.action);
|
|
if(JSON.stringify(actions)!==JSON.stringify(['check','send-code','verify-code','reset']))throw new Error('三步流程请求顺序不正确');
|
|
const reset=calls[3].payload;
|
|
if(reset.resetToken!=='a'.repeat(64)||reset.newPassword!=='abc123'||reset.confirmPassword!=='abc123')throw new Error('重置请求参数未对齐');
|
|
if(errors.length)throw new Error('页面运行时错误:'+errors.join(';'));
|
|
await page.setViewportSize({width:390,height:844});
|
|
await page.screenshot({path:path.join(process.env.TEMP,'sw-kra-login-mobile.png'),fullPage:true,animations:'disabled'});
|
|
const report={method:'真实 Chrome 渲染;找回密码接口使用受控响应,不发送真实短信',title:await page.title(),actions,pageErrors:errors,passed:true};
|
|
await fs.writeFile('docs/sw6-to-kra/login-page-verification-2026-11-03.json',JSON.stringify(report,null,2));
|
|
console.log(JSON.stringify(report));
|
|
}finally{await browser.close();}
|
|
})().catch(e=>{console.error(e.message);process.exitCode=1});
|