【问题标题】:Extending expect-webdriverio with custom matchers使用自定义匹配器扩展 expect-webdriverio
【发布时间】:2021-01-27 22:27:44
【问题描述】:

我需要为我的 wdio 打字稿框架制作一个自定义匹配器。我查看了https://github.com/webdriverio/expect-webdriverio/blob/master/docs/Extend.md 并完成了所有操作,我复制并粘贴了完全相同的代码。所以在我的 before() 钩子中:

const matchers = require('myMatchers');
matchers.addCustomMatchers();

就在我的 wdio conf 文件旁边:

module.exports = {
    addCustomMatchers: () => {
        console.log("MY MATCHER");
        expect.extend({
            myMatcher(actual, expected) {
                return { pass: actual === expected, message: () => 'some message' }
            },
        })
    }
}

当我开始测试时,我在控制台中看到“MY MATCHER”行。所以它得到正确执行。 但是我在尝试做期望时看不到 myMatcher。我错过了什么?

【问题讨论】:

  • “看不到 myMatcher”。不知道是什么意思。你在哪里看不到?

标签: typescript webdriver-io


【解决方案1】:

文档有效。对于 TypeScript 项目,您还必须声明类型。

查看我的示例项目:

  1. before hook
  2. matchers
  3. matcher types
  4. usage in test

注意: 确保为您提供最新的 wdio 包和有效的 tsconfig.json。你可以在项目中找到所有这些。

【讨论】:

  • 非常感谢,您的示例对我很有用!
猜你喜欢
  • 2011-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-10
相关资源
最近更新 更多