Files

72 lines
4.9 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
async (page) => {
try {
page.setDefaultTimeout(8000);
const errors=[];page.on('pageerror',e=>errors.push(e.message));
const check=(ok,name)=>{if(!ok)throw Error(name)};
const idle=async()=>{await page.locator('.el-loading-mask').waitFor({state:'hidden'});};
await page.getByRole('textbox',{name:'用户名',exact:true}).fill('admin');
await page.getByRole('textbox',{name:'密码',exact:true}).fill('MySpace-local-2026');
await page.getByRole('button',{name:'进入我的空间'}).click();
await page.getByRole('heading',{name:'工作台',exact:true}).waitFor();
await page.setViewportSize({width:1440,height:1000});
await page.screenshot({path:'output/playwright/app-desktop.png',fullPage:true});
await page.getByRole('button',{name:'+ 记录此刻',exact:true}).click();
await page.getByPlaceholder('给想法起个名字').fill('浏览器验收笔记');
await page.getByRole('button',{name:'创建笔记',exact:true}).click();
await page.getByRole('textbox',{name:'Markdown 内容',exact:true}).fill('# 真实笔记\n\n**刷新仍然保留**\n\n<script>alert(1)</script>');
await idle();
await page.getByRole('button',{name:'保存',exact:true}).click();
await page.getByText('已保存到服务器 · 手动保存').waitFor();
check(await page.locator('.markdown strong').textContent()==='刷新仍然保留','Markdown preview');
check(await page.locator('.markdown script').count()===0,'XSS');
await page.reload();
await page.getByRole('button',{name:/浏览器验收笔记/}).click();
check((await page.getByRole('textbox',{name:'Markdown 内容',exact:true}).inputValue()).includes('刷新仍然保留'),'persistence');
await page.getByRole('textbox',{name:'笔记标题',exact:true}).fill('未保存的标题');
await idle();
await page.getByRole('button',{name:'← 返回笔记',exact:true}).click();
await page.getByRole('button',{name:'继续编辑',exact:true}).click();
check(await page.getByRole('textbox',{name:'笔记标题',exact:true}).inputValue()==='未保存的标题','leave protection');
await page.getByRole('textbox',{name:'笔记标题',exact:true}).fill('浏览器验收笔记');
await page.getByRole('button',{name:'收藏笔记',exact:true}).click();
await idle();
await page.getByRole('button',{name:'保存',exact:true}).click();
await page.getByText('已保存到服务器 · 手动保存').waitFor();
await page.screenshot({path:'output/playwright/app-editor.png',fullPage:true});
await page.setViewportSize({width:390,height:844});
await page.waitForTimeout(350);
check(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth),'mobile editor overflow');
await page.screenshot({path:'output/playwright/app-mobile-editor.png',fullPage:true});
await page.setViewportSize({width:1440,height:1000});
await idle();
await page.getByRole('button',{name:'← 返回笔记',exact:true}).click();
await idle();
await page.locator('input[type=file]').setInputFiles({name:'验收文件.txt',mimeType:'text/plain',buffer:Buffer.from('persistent browser upload')});
await page.getByRole('heading',{name:'验收文件.txt',exact:true}).waitFor();
await page.reload();
await page.getByRole('button',{name:/图床 \/ 文件/}).click();
await page.getByRole('heading',{name:'验收文件.txt',exact:true}).click();
const downloadPromise=page.waitForEvent('download');
await page.getByRole('link',{name:'下载原文件',exact:true}).click();
const download=await downloadPromise; check(download.suggestedFilename()==='验收文件.txt','download name');
await page.getByRole('button',{name:'删除文件',exact:true}).click();
await page.getByRole('button',{name:'确定',exact:true}).click();
await page.getByText('还没有匹配的内容。').waitFor();
await page.getByRole('button',{name:/知识库/}).click();
await page.getByRole('heading',{name:'浏览器验收笔记',exact:true}).click();
await page.getByRole('button',{name:'删除笔记',exact:true}).click();
await page.getByRole('button',{name:'确定',exact:true}).click();
await page.getByText('还没有匹配的内容。').waitFor();
await page.setViewportSize({width:390,height:844});
await page.waitForTimeout(350);
await page.getByRole('button',{name:'打开菜单',exact:true}).click();
await page.getByRole('button',{name:/工作台/}).click();
check(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth),'mobile dashboard overflow');
await page.screenshot({path:'output/playwright/app-mobile.png',fullPage:true});
await page.getByRole('button',{name:'切换主题',exact:true}).click();
await page.screenshot({path:'output/playwright/app-dark.png',fullPage:true});
check(errors.length===0,errors.join(';'));
console.log('PASS: login, note CRUD, Markdown safety, persistence, leave guard, favorite, private upload/download/delete, mobile layout, theme. No page errors.');
} catch(e) { await page.screenshot({path:'output/playwright/failure.png',fullPage:true}); console.log(await page.locator('body').innerText());throw e; }
}