Creating Features - rquellh/testcafe-cucumber GitHub Wiki
Let's start by opening the testcafe-cucumber repo in VSCode. If you are lost please refer to the intro.
Now that the repo is open let's run the cucumber files that are in there as an example. Type npm run test into the command line. Four tests will be run and three will pass and one will fail. You'll also see what step in Cucumber failed and TestCafe will show where in the code the failure occurred. The following pages will help you become familiar with what's going on.
Lets take out the current tests from the project.
- Expand the featuresfolder and remove thegithub.featureandgoogle.featurefiles.
- Expand the step_definitionsfolder and remove thegithub.jsandgoogle.jsfiles.
- Expand the supportfolder and expand thepagesfolder and remove thegithub-page.jsfile
- The folder structure should look like the following
A .feature file contains the test(s) for a feature. The .feature file starts simply with the keyword Feature: which needs to be added for the following tests to be run. Let's create a .feature file below.
- In the featuresfolder root directory add the filesample_form.feature
- Add the Feature:line to the top of the form and describe the feature
- Add a description under Feature:so feature is further defined
You can add any information under the Feature: until you type the keyword Scenario:. A scenario quite simply is a test with a list of steps written under it. Each step could start with a *, but in order for the steps to be more comprehensible and business friendly use the predetermined Gherkin steps Given, When, Then, But, and And.
There is plenty of information online about the Gherkin syntax, so I won't go into much detail.
- 
Givenput the system in a known state
- 
Whenspecify an action performed
- 
Thenobserve outcomes or expected results
- 
AndandButcreates multipleGiven,When, andThensteps
Each test should have at least a Given, When, and Then step. Let's create a Scenario: for the sample form page.
Feature: Sample Form
    As a user
    I want to fill out the form
    So that the company recieves my information
    Scenario: Form Submission - Required Fields Only
        Given I navigate to the example form page
        When I fill out the name field with "John Doe"
        And I fill out the email field with "[email protected]"
        And I fill out the comment box with "This is a comment John Doe"
        And I select "5-7" from the expereince dropdown
        And I click the submit button
        Then I see "John Doe" in the name field on the submission form
        And I see "[email protected]" in the email field on the submission form
        And I see "This is a comment John Doe" in the message field on the submission form
        And I see the "Message Sent" messageThat's it you've successfully created your first scenario.
- If you are using the Cucumber (Gherkin) Full Support extension in VSCode you'll notice all of the syntax highlighting and completion.
- 
You can auto-format the .featurefile by the hotkey command CTRL + ALT + F
- 
Additional reading on Feature files and Gherkin 



