首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >错误:协议JSON API在使用TestCafe服务器运行灯塔时出错

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

Stack Overflow用户
提问于 2020-04-15 11:15:41
回答 1查看 240关注 0票数 0

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

这是我的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.

哪里出了问题?为什么这种情况经常发生?灯塔就是不能和TestCafe一起工作吗?

EN

回答 1

Stack Overflow用户

发布于 2020-04-16 17:41:26

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

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61220739

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档