如何测试支持 javascript 和不支持 javascript 的场景?

发布于 2024-11-05 05:46:48 字数 602 浏览 3 评论 0原文

我已经在我的应用程序中引入了 ajaxy 表排序,并且我想设置 Cucumber 测试来测试支持 javascript 和不支持 javascript 时的功能。

我使用的是水豚,所以如果我使用标志@javascript,它将使用 javascript 驱动程序运行测试。他们是否有一个标志可以运行该场景两次,一次使用javascript,一次不使用?

像下面这样的东西......

  @test-both-javascript-and-non-javascript
  Scenario: Table Search
    When I fill in "search" with "Jonathan"
    And I press "Search"
    Then I should see the following users:
      | Jonathan | Smith | [email protected] | active |

I have introduced ajaxy table sorting to my application, and I want to set up cucumber tests to test the functionality when javascript is supported and when javascript is not supported.

I am using capybara, so if I use the flag @javascript, it will run the test with a javascript driver. Is their a flag that will run the scenario twice once with javascript and once without?

Something like the following ...

  @test-both-javascript-and-non-javascript
  Scenario: Table Search
    When I fill in "search" with "Jonathan"
    And I press "Search"
    Then I should see the following users:
      | Jonathan | Smith | [email protected] | active |

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

人生戏 2024-11-12 05:46:48

使用 @javascript 将驱动程序从默认值切换为可以在页面上运行 javascript 的驱动程序。省略 @javascript 并不意味着您正在测试“当不支持 javascript 时”或“不支持 javascript”。 然后我应该在 的页面上看到“Javascript is not support”,使用默认值将失败驱动程序(即没有 @javascript 标签)。

如果您确实想使用不支持的 javascript 进行测试,您应该配置一个禁用 javascript 的新驱动程序,并使用新标签(例如 @nojavascript)在 Before('@nojavascript') 中切换到该驱动程序 块并切换回 After('@nojavascript') 块中的默认值。然后,您可以专门使用该标记编写场景,并在您想要检查 javascript 何时被禁用的情况下重复场景。

Using @javascript switches drivers from the default to one that can run the javascript on your pages. Leaving off @javascript does not mean you are testing "when javascript is not supported" or "without javascript support". A test of Then I should see "Javascript is not supported" on a page with <noscript>Javascript is not supported.</noscript> will fail using the default driver (i.e., no @javascript tag).

In case you really want to test with javascript not supported, you should configure a new driver with javascript disabled, and use a new tag (e.g., @nojavascript) to switch to that driver in a Before('@nojavascript') block and switch back to the default in the After('@nojavascript') block. Then you can write scenarios specifically with that tag, and repeat scenarios for cases when you want to check when javascript is disabled.

人海汹涌 2024-11-12 05:46:48

无论 JavaScript 启用还是禁用,行为真的都一样吗?如果是这样,你为什么要使用 JavaScript? ;-)

我怀疑实际上无论 JavaScript 是启用还是禁用,行为都会略有不同。因此,您应该有两个场景来描述每种情况的行为,例如,JavaScript 版本是否会在您键入时建议结果?

Is the behaviour really the same, regardless of whether JavaScript is enabled or disabled? If so, why are you using JavaScript at all? ;-)

I suspect that in reality the behaviour is slightly different whether JavaScript is enabled or disabled. Therefore you should have two scenarios describing the behaviour for each case, e.g. does the JavaScript version suggest results as you type?

拥醉 2024-11-12 05:46:48

我不建议在单次运行中启用和禁用 Javascript 支持。

相反,标记您需要(或不需要,由您决定)javascript 的场景并单独运行它们。您可能会发现需要重复一些场景来涵盖不同的行为,但这是值得的,因为您只会重复功能而不是实现。

最后,您可能还想使用不同的驱动程序运行此类场景,因此您可以将测试套件仅包含在“一个盒子”中。

I would not recommend enabling and disabling Javascript support on a single run.

Instead, tag the scenarios you need (or don't need, up to you) javascript and run those separate. You will probably find that you will need to repeat some scenarios to cover different behaviors, but it's worth it because you will only be repeating the feature and not the implementation.

And finally you might want to run such scenarios using different drivers as well, so you can contain your suite of tests in only "one box" as per say.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文