views:

32

answers:

2

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 asking 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?

A: 

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.

Chubas
I agree that there should be boundary values, but part of my application's functionality is to generate random discrete values within those boundary values, and present those random values to the user. The user needs to then identify the difference between those random values, and respond to the application with that difference. When visiting the "drill prompt" page, the application's responsibility is to generate two random values, and solicit the user for input.
animal
A: 

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.

AlistairH