【问题标题】:Reusable setup and teardown functions before each test?每次测试前可重复使用设置和拆卸功能?
【发布时间】:2020-08-13 20:03:15
【问题描述】:

我的背景主要是 Selenium 的 python 实现,所以我是 JavaScript 和 WebdriverIO 的新手。如果这是一个初级问题,请见谅

现在,有一段代码 before() => {} 块正在被复制/粘贴到教学 /test/specs 文件的开头,但我希望将它重构为一个单独的设置函数可以调用所有测试文件共享的,因此更易于维护和配置。

我在文档中找不到任何说明 WDIO 可重用函数的最佳做法的来源。创建 setup 和 teardown 函数的标准是什么?

【问题讨论】:

    标签: selenium webdriver-io


    【解决方案1】:

    设置和拆卸钩子可以在 wdio 配置文件中配置

    https://webdriver.io/docs/configurationfile.html

        /**
         * Gets executed before test execution begins. At this point you can access to all global
         * variables like `browser`. It is the perfect place to define custom commands.
         * @param {Array.<Object>} capabilities list of capabilities details
         * @param {Array.<String>} specs List of spec file paths that are to be run
         */
        before: function (capabilities, specs) {
        }
    

    如果这些不能满足您的需求,您必须按照您提到的那样做,即将重复的代码移动到单独模块中的函数中并在需要的地方导入。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-27
      • 1970-01-01
      • 2013-12-28
      • 1970-01-01
      • 1970-01-01
      • 2022-10-19
      • 1970-01-01
      相关资源
      最近更新 更多