我似乎无法使用pa11y和它的“操作”功能登录网站。我找到的关于pa11y操作的文档和站点似乎表明这是一件简单的事情,但我没有运气。
我尝试过登录各种站点,从已建立的站点(GitHub),到托管在云中的我自己的站点,甚至是运行在我本地机器上的站点。它们都会到达登录表单提交按钮(通常是POST请求)的"click“操作,然后挂起并最终超时,在”等待url更改“操作发生之前。
如果我将headless设置为false并在Chromium中打开检查器,我可以看到在单击登录按钮后发出的POST请求,但它永远不会完成。有趣的是,当我在我控制的站点上尝试这样做,并且可以看到日志时,我看到成功的登录发生在服务器端,但是pa11y (也许这真的是一个木偶人或无头铬问题)似乎从未收到过响应。
我已经包含了我为GitHub尝试过的代码,它不能工作。我在Mac上使用Node 8.11.3来运行它。我甚至在另一台电脑上试过,仍然有同样的问题。该代码基于pa11y文档中给出的一个示例,并且只做了一点修改(https://github.com/pa11y/pa11y/blob/master/example/actions/index.js)。
我做错了什么?
'use strict';
const pa11y = require('pa11y');
runExample();
async function runExample() {
try {
var urlToTest = 'https://github.com/login';
const result = await pa11y(urlToTest, {
actions: [
'navigate to https://github.com/login',
'set field #login_field to MYUSERNAME',
'set field #password to MYPASSWORD',
'click element #login input.btn.btn-primary.btn-block',
// everything stops here...
'wait for url to not be https://github.com/login',
'navigate to https://github.com/settings/profile',
'screen-capture github.png'
],
chromeLaunchConfig: {
headless: false,
slowMo: 250
},
log: {
debug: console.log,
error: console.error,
info: console.log
},
timeout: 90000
});
console.log(result);
} catch (error) {
console.error(error.message);
}
}
发布于 2018-08-30 23:52:45
该问题似乎源于使用特定版本的puppeteer库,它是pa11y的依赖项。在工作环境中使用puppeteer 1.6.2。使用puppeteer 1.7.0会导致超时问题。通过在我的package.json文件中指定"puppeteer": "~1.6.0",和pa11y依赖项,我能够自己修复这个问题。当前版本的Pa11y可以与1.4.0以下的任何版本的puppeteer一起工作。
下面是关于GitHub的相关问题,以便pa11y库进行更新:https://github.com/pa11y/pa11y/issues/421
发布于 2018-08-16 19:40:13
我也有同样的问题。我通过将https://github.com/emadehsan/thal和这里的https://github.com/pa11y/pa11y/blob/master/example/puppeteer/index.js示例组合在一起,设法传递了登录页面。也许这对你有帮助。
https://stackoverflow.com/questions/51868635
复制相似问题