fashuser
fashuser

Reputation: 1489

Cucumber: usage file in scenario

I have the following scenario:

Feature: Some feature
   Scenario: Test feature
     Given login as test_user
     When test_user submits changes with content:
        """
        Very long text
        """
     Then content is saved

The main goal is to move the "very long text" to some file or something like this and avoid duplication of this text in the defined scenarios.

Upvotes: 0

Views: 190

Answers (1)

user1459144
user1459144

Reputation: 2977

I see only one solution (this solution isn't so nice, but can be used as alternative):

Feature: Some feature
   Scenario: Test feature
     Given login as test_user
     When test_user submits changes with content very_long_text.txt            
     Then content is saved

And put very_long_text.txt in the project test resources. Separate folder can be created to hold all cucumber resources. As example: src/test/resources/cucumber

And create Utility class that read content of this resource:

public static String getText(String fileName){
    IOUtils.toString("cucumber" + fileName);
}

And use the file content in that way. In order to do not duplicate messages in the code

Upvotes: 0

Related Questions