如何测试支持 javascript 和不支持 javascript 的场景?
我已经在我的应用程序中引入了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 @javascript 将驱动程序从默认值切换为可以在页面上运行 javascript 的驱动程序。省略 @javascript 并不意味着您正在测试“当不支持 javascript 时”或“不支持 javascript”。
然后我应该在
,使用默认值将失败驱动程序(即没有 @javascript 标签)。的页面上看到“Javascript is not support”
如果您确实想使用不支持的 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 theAfter('@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.无论 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?
我不建议在单次运行中启用和禁用 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.