Writing code for your test cases

From Test Automation Wiki
Revision as of 10:21, 27 June 2016 by Gijsp (talk | contribs)
Jump to: navigation, search

This page will describe how you can start putting actions behind the steps you have written in `Writing_gherkin_test_cases_in_cucumber`.

Step definitions

Start by opening the following files:

  • /yourproject/features/step_definitions/interactions_steps.rb
  • /yourproject/features/example.feature

As you can see, the step Given I navigate to Google in english is defined in the interaction_steps.rb file as following:

Given(/^I navigate to (.*) in (.*)$/) do |site,language|
  #... code here...
end

When you are executing your scenarios, with every step you run, the system will search for a definition of that step. If a Defined Step matches the Step in the scenario, it will run the code in the brackets of the step definition. <blocknote> Actually all definitions are loading before it starts going through the steps, but it's simpler to see it as every step being looked up. </blocknote>

Making a custom step

Let's start by creating a new scenario in example.feature: