如何使用 Cucumber.js 检查断开的链接

How to check broken links with Cucumber.js

我需要使用 Cucumber.js 检查页面上的 404 链接。所以我在猜测两件事。

Feature: Check broken links

Scenario: User clicks on links on web page Given User is on website And he clicks on link Then he shouldn't see 404 And user returns back to click to another link on page

您应该考虑使用 Mocha 进行此类测试,Gherkin 不是为循环等设计的。有关详细信息,请参阅此答案:

您可以使用场景大纲并传入 url 作为变量

Feature: Check broken links

Scenario Outline: User clicks on links on web page
    Given User is on website
    And he clicks on <link>
    Then he shouldn't see 404
    And user returns back to click to another link on page

Examples:
  | link |
  |  http://www.google.com   |
  |  http://www.gmail.com   |