错误:协议JSON API在使用TestCafe服务器运行Lighthouse时出错



我正在尝试编写代码,以启动TestCafe服务器,登录到经过身份验证的页面,导航到我想要的页面,然后针对该页面执行Lighthouse。

这是我的testcafeServer.js文件:

const createTestCafe = require('testcafe'); let testcafe = null; createTestCafe('localhost', 1337, 1338) .then((tc) => { testcafe = tc; const runner = testcafe.createRunner(); return runner.src(['test_lightHouse.js']).browsers(['chrome']).run(); }) .then((failedCount) => { console.log('Tests failed: ' + failedCount); testcafe.close(); });

这是我的test_lighthouse.js文件:

import { Selector } from 'testcafe'; var fs = require('fs'); const lighthouse = require('lighthouse'); fixture`LightHouse Test`.page( 'MY-SPECIFIC-URL' ); test(`Generate Light House Result `, async (t) => { //Specific code to navigate to a certain page const auditResult = await lighthouse( 'MY-CURRENT-URL-I-WANT-TO-TEST', { logLevel: 'info', output: 'html', port: 1337, //I am getting this port # from the TestCafe server I am standing up locally - might be wrong } ); // Write data in 'Output.txt' . fs.writeFile('mynewfile3.html', auditResult, function (err) { if (err) throw err; console.log('Saved!'); }); console.log(auditResult); });

当执行此代码时,我得到以下错误:

✖ Generate Light House Result 1) Error: Protocol JSON API error (list), status: 404 Browser: Chrome 80.0.3987.163 / macOS 10.15.4 102 | return resolve({message: data}); 103 | } 104 | return reject(e); 105 | } 106 | } > 107 | reject(new Error(`Protocol JSON API error (${command}), status: ${response.statusCode}`)); 108 | }); 109 | }); 110 | 111 | // This error handler is critical to ensuring Lighthouse exits cleanly even when Chrome crashes. 112 | // See https://github.com/GoogleChrome/lighthouse/pull/8583.

出了什么问题?为什么这种情况经常发生?Lighthouse就是不想和TestCafe合作吗?

目前,没有简单的方法可以将灯塔与TestCafe集成。请在TestCafe存储库中跟踪以下问题,以便收到我们的结果通知:https://github.com/DevExpress/testcafe/issues/3493.

此外,您可以尝试此处显示的方法:https://stackoverflow.com/a/55447097/10684943,但它可能无法正确处理身份验证页面。

最新更新