testing - Polymer 3.0 a11ySuite 测试报错

标签 testing polymer accessibility polymer-3.x

我正在尝试让 a11ySuite 在 Polymer 3.0 测试中正常工作。

当我使用 polymer test 运行测试时,测试超时,我可以在自动浏览器的控制台中看到以下错误:

Uncaught ReferenceError: Polymer is not defined
at Suite.a11ySuite.eachTest (a11ySuite.js:51)
at mocha.js:1550
at Object.exports.forEach (mocha.js:1595)
at Suite.eachTest (mocha.js:1550)
at Runner.grepTotal (mocha.js:1224)
at Runner.grep (mocha.js:1215)
at new Runner (mocha.js:1197)
at Mocha.run (mocha.js:592)
at _runMocha (extend.js:41)
at done (util.js:34)

如果我在 Debug模式下运行,从 polymer serve url,我收到此错误:

a11ySuite.js:49 Uncaught TypeError: fixtureElement.create is not a function
at Suite.a11ySuite.eachTest (a11ySuite.js:49)
at mocha.js:1550
at Object.exports.forEach (mocha.js:1595)
at Suite.eachTest (mocha.js:1550)
at Runner.grepTotal (mocha.js:1224)
at Runner.grep (mocha.js:1215)
at new Runner (mocha.js:1197)
at Mocha.run (mocha.js:592)
at _runMocha (extend.js:41)
at done (util.js:34)

这之前还有一堆来自 mocha 的 404,关于 lodash、sinonjs 和 test-fixture,假设这是因为它在 serve 模式下运行。

这是我的测试代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Verifier - a11y test</title>

    <script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
    <script src="../node_modules/web-component-tester/browser.js"></script>
    <script type="module" src="../src/verifier.js"></script>
</head>
<body>
    <test-fixture id="BUVA11y">
        <template>
            <verifier id="verifier"></verifier>
        </template>
    </test-fixture>

    <script>
      suite('A11y testing', function() {
        a11ySuite('BUVA11y');
      });
    </script>
</body>
</html>

我无法在网上找到更多信息,而且关于这个主题的文档非常有限(实际上确实不准确)。

最佳答案

web-component-tester 版本 6.4.3 开始,

a11ySuite 已移至 wct-browser-legacy .鉴于“传统”命名,我猜它已被弃用。我假设它是这样使用的:

<script type="module">
  import {a11ySuite} from 'wct-browser-legacy/a11ySuite.js';
  a11ySuite('view1'); // "view1" == template name
</script>

但我无法让它在一个干净的 polymer-3-starter-kit 项目中工作(即 a11ySuite 属性存在于模块中,但始终未定义)。设置断点 where that variable is defined ,我可以看到该变量实际上从未设置过,因为无论出于何种原因从未调用 Mocha pre-require 事件处理程序。

但是,似乎 axe-core (通过 pwa-helpers )是 Polymer 3 中使用的最新a11y 测试工具,基于 test code in pwa-starter-kit :

<script type="module">
  import 'axe-core/axe.min.js';
  import {axeReport} from 'pwa-helpers/axe-report.js';

  suite('views a11y tests', function() {
    test('my-view1', function() {
      const el = fixture('view1');
      return axeReport(el);
    });
    ...
  });
</script>

关于testing - Polymer 3.0 a11ySuite 测试报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50517884/

相关文章:

android - 以编程方式将谷歌帐户添加到android

html - 使用动态绑定(bind)的 polymer 绘制树结构

java - Android:以编程方式更改可访问性顺序

android - 在包 'accessibilityEventTypes' 中找不到属性 'android' 的资源标识符

objective-c - 观察AXUIelement的子元素变化?

testing - E2E 测试 Jasmine /Protractor 中的 Ionic 3 无限滚动模拟

android - 如何使用 Espresso 测试 Android 应用程序已关闭

testing - CMake - 有没有办法检查是否启用了测试?

javascript - Polymer 3 ide - 模板编辑

javascript - Bootstrap Javascript 无法在 Firefox 和 Safari IOS 中运行