I'm using Behat and Mink to do some Functional Tests from my website. Now there is a Feature where I upload some file to the server, and then I have to validate the changes made in the Server, that are caused by uploading the file, in a Report. Now in the Report I have to search each of the Entries and validate that the correct data is shown. Now I can put all this a single Feature because it will cause it to become too big and messy, especially the part about validating the data, I have to either create a FeatureContext
with a state, that takes the search data and result data in separate steps, or I'll have to put them the search data and the expected result data in a single table, which wouldn't be very clean. I can't use a Scenario Outline either, because that would cause the file to be uploaded each time the Scenario executes, which doesn't seem good either.
So the best way to handle this seems to be, creating separate Scenarios for the upload and checking features and do one of the following:
1. Somehow tell Behat to execute the 'Check' Scenario right after the 'Upload' Scenario.
2. Call the 'Upload' Scenario from the 'Check' Scenario.
How can any of these two alternatives be done? If none can, then what's the best way to handle this?
You need to make sure that the file is uploaded, the scenarios should be independent.
Use a Background for setup, in this way if the background fails then the following scenarios will be skipped.
The key of saving time and not upload each time is to check if the file is uploaded somehow or check that the first time setup step was executed was successfully.
For example in setup step you could have a condition like if(!isUploaded) { upload the file }.
Is uploaded can check the existence of a variable, of a file for the case where you set these on first successful execution of the step or it can check if the file is uploaded by other means(check the file name somewhere or check some change in the frontend).
@javascript @insulated
Feature: Search
Background:
Given I upload the search config file if needed
And I am on homepage
Scenario: Search - search with valid term
When I search for phone
Then the search result page should contain phones
Scenario: Search - search with valid term
When I search for blabla
Then the search result page should contain no items found message
'I upload the search config file if needed' - should contain a check to see if the file is updated and if not to execute calls to the steps for uploading the file.