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

How to check broken links with Cucumber.js

本文关键字:断开 链接 检查 js 何使用 Cucumber      更新时间:2023-09-26

我需要使用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

  • 第二个是如何在js文件中实现点击所有链接来检查内容,并在每次检查后返回主页面

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

Meteor黄瓜/黑猩猩的步骤定义库

您可以使用场景大纲并将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   |