开发者

How to test a scenario with javascript support and without javascript support?

开发者 https://www.devze.com 2023-03-02 16:11 出处:网络
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 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 dri开发者_JS百科ver. 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 | jonathan@example.com | active |


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.


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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消