| 12345678910 |
- import{chromium}from'playwright';import fs from'node:fs';import assert from'node:assert/strict';
- const root=new URL('.',import.meta.url).pathname,fixture=JSON.parse(fs.readFileSync(root+'fixture.json')),browser=await chromium.launch({headless:true,executablePath:process.env.CHROME_BIN}),samples=[];
- try{for(let pair=0;pair<10;pair++)for(const version of ['A','B']){
- const ctx=await browser.newContext({viewport:{width:390,height:844}}),page=await ctx.newPage(),api=[];await ctx.addInitScript(()=>{localStorage.setItem('xiaoshu.angular.session',JSON.stringify({token:'r:qa',user:{userId:300,groupId:3},student:{userId:1713,groupId:1}}));HTMLMediaElement.prototype.load=()=>{};HTMLMediaElement.prototype.play=()=>Promise.resolve();});
- const cdp=await ctx.newCDPSession(page);await cdp.send('Network.enable');await cdp.send('Network.emulateNetworkConditions',{offline:false,latency:20,downloadThroughput:4e6/8,uploadThroughput:3e6/8,connectionType:'cellular4g'});
- page.on('response',r=>{if(r.request().postDataJSON()?.params?.action==='e_ck_list')api.push({serverMs:Number(r.headers()['x-qa-read-ms']),wireBytes:Number(r.headers()['content-length']),decodedBytes:Number(r.headers()['x-qa-decoded-bytes'])});});
- await page.goto((version==='A'?process.env.BASELINE_URL:process.env.CANDIDATE_URL)+'/pages/stu/stu_list?nid='+fixture.pnid+'&orderId=qa-order',{waitUntil:'domcontentloaded'});await page.locator('.node-list > button').first().click();await page.waitForFunction(()=>!document.querySelector('.unit-actions .primary-button')?.disabled);
- const start=performance.now();await page.locator('.unit-actions .primary-button').click();await page.waitForFunction(()=>document.querySelectorAll('.word-refine-item').length===100);await page.locator('.word-select-check').first().click();await page.waitForFunction(()=>document.querySelector('.word-select-check')?.getAttribute('aria-pressed')==='true');
- const ms=Math.round(performance.now()-start);assert.equal(api.length,1);samples.push({pair,version,ms,...api[0],domNodes:await page.locator('.word-select-list *').count()});fs.writeFileSync(root+'paired-samples.json',JSON.stringify(samples,null,2));console.log(JSON.stringify(samples.at(-1)));await ctx.close();
- }const stat=rows=>{const s=rows.map(x=>x.ms).sort((a,b)=>a-b);return{n:s.length,p50:s[4],p75:s[7],p95:s[9]};},before=stat(samples.filter(x=>x.version==='A')),after=stat(samples.filter(x=>x.version==='B')),summary={before,after,improvement:1-after.p75/before.p75,scope:'unit choice click to 100 selectable course words; gzip; Fast4G; warm app, cold data'};assert.ok(after.p75<before.p75,'Must improve actual readiness');fs.writeFileSync(root+'paired-summary.json',JSON.stringify(summary,null,2));console.log(JSON.stringify(summary));}finally{await browser.close();}
|