Importing Scenarios
Overview
To help users reuse Scenarios across Cycle tests, Cycle includes a Step for importing Scenarios from another Feature File. This Step is: I import scenarios from "<FEATURE_FILE_PATH>".
The import Scenarios Step primarily serves to enable the use of a second Step, I execute scenario "<SCENARIO_NAME>", which executes the imported Scenarios.
How the Step works
An absolute or relative path can be provided as the parameter for the import Scenarios Step.
The Step will first look for the specified Feature File in the default Resource Directory. If the Step does not find it there, the Step will fall back to looking for a Feature File with that path relative to the current file.
Using the import Scenarios Step within a Scenario (or within the Background of a Feature) allows a Scenario or Feature to execute any of the Scenarios that are contained within the imported Feature File.
Scenarios are executed either by using the I execute scenario "<SCENARIO_NAME>" Step, or by using the "<SCENARIO_NAME>" Step. These Steps are interchangeable.
Practical applications
The import functionality allows you to create Utility Feature Files that contain reusable, oft-used Scenarios. Typical uses for a Utility Feature would be opening or closing a browser or connecting to a database.
Using the import Scenarios Step in the Background of the main Feature makes the imported Scenarios available to all Scenarios in the main Feature.
Example
In the example below, Scenarios from the first Feature File, saved as Web_Browser_Utilities.feature, will be imported into the second main Feature File, saved as Browser_Test.feature.
Note that both the I execute scenario "<SCENARIO_NAME>" and "<SCENARIO_NAME>" Steps are used in the example below. Also note how the "<SCENARIO_NAME>" Step can be used to create more readable Features when reusing Scenarios.
Imported Feature
Feature: Web Browser Utilities
Scenario: Launch Chrome
Given I open "Chrome" web browser
And I wait 2 seconds
Scenario: I launch IE
Given I open "Internet Explorer" web browser
And I wait 2 seconds
Scenario: I close the browser
Given I close web browser
Main Feature
Feature: Browser Test
Scenario: Chrome
Given I import scenarios from "Web_Browser_Utilities.feature"
And I execute scenario "Launch Chrome"
And I wait 2 seconds
And "I close the browser"
Scenario: IE
Given I import scenarios from "Web_Browser_Utilities.feature"
And "I launch IE"
And I wait 2 seconds
And "I close the browser"