Reputation: 190
I am trying to write a simple cucumber step where it checks to see if one of two phrases are on the page, but my attempts at if statements have failed. Here is the step i currently have
Then(/^I should see a pdf preview of the magazine$/) do
@browser.windows.last.use
@browser.text.should_not include "Page not found"
But, ideally, I want the step to check and see if the text "Page not found" is present, if so fail the test. If "page not found" is NOT present, then check to see if the text "Forbidden" is present, if so, fail the test. If neither phrase is present, then pass the test.
Where i think I am stumbling, is I dont know how to tell it, to stop and fail the test.
Ideally, I would think it would look like this...
if text "Page not found" visible?
fail test
elseif text "Forbidden" visible?
fail test
else
pass test
But I dont know how to put that into ruby/watir-webdriver code
Do I just have to make it throw exceptions if the test fails? If its that easy, will that fail the test, or pass it but give me a message and how do I make it pass if neither phrase is visible?
Upvotes: 0
Views: 685
Reputation: 46836
A Cucumber step will stop and fail the test as soon as any of the assertions fail (or an exception is raised). Conversely, a Cucumber step will pass if all assertions pass (or there are no exceptions raised).
As a result, you can simply do:
Then(/^I should see a pdf preview of the magazine$/) do
@browser.windows.last.use
@browser.text.should_not include "Page not found" # first assertion
@browser.text.should_not include "Forbidden" # second assertion
end
With this step:
Upvotes: 1