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

问题描述 投票:0回答:1

我正在尝试编写代码,以启动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一起使用?

javascript testing e2e-testing testcafe lighthouse
1个回答
0
投票

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

此外,您也可以尝试此处显示的方法:https://stackoverflow.com/a/55447097/10684943,但是它可能无法在身份验证页面上正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.