我正在尝试编写代码来启动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一起工作吗?
发布于 2020-04-16 17:41:26
目前,还没有简单的方法来集成灯塔和TestCafe。请在TestCafe存储库中跟踪以下问题以通知我们的结果:https://github.com/DevExpress/testcafe/issues/3493。
此外,您还可以尝试此处所示的方法:https://stackoverflow.com/a/55447097/10684943,但它可能无法正确处理身份验证页面。
https://stackoverflow.com/questions/61220739
复制相似问题