I am trying to create a quizzing style skill drilling site and use Cucumber to drive the testing. As a rough estimate pretend I am presenting the user with two numbers, and a开发者_如何转开发sking the user to click a button representing their difference. Two obvious scenarios would be:
Scenario: Difference drill, correct answer
Given I am on the difference drill prompt page
And the first number is X
And the second number is Y
When I press "X-Y"
Then I should see "Correct!"
Scenario: Difference drill, incorrect answer
Given I am on the difference drill prompt page
And the first number is X
And the second number is Y
When I press "X-Y-1"
Then I should see "Incorrect."
I don't think Scenario Outlines are quite the right answer here, is there any way of having Cucumber tests where the data presented to the user is somewhat randomly generated, and the user's actions are contingent upon that data?
In this case, I think what you want to do is to store the value from the Given step in an instance variable, e.g. @x.
Then you will be able to reference this variable in any subsequent When\Then steps.
You can share common steps as a Background, or abstract those steps into a shared one.
I don't follow you with the randomly generated data. You're refering to generating random data in the test? This is not a good practice IMHO, you have to first delimit the boundaries of your possible random data and then test with known, fixed values inside and outside of that boundaries.
精彩评论