0

We are using a test Protractor-Cucumber BDD test framework. Does Cucumber js not support 'Background' hook?

I am trying a scenario like shown below:

Background:
Given an authenticated user

Scenario Outline:  test something
Given the home page is displayed
When I fill the form for <patient>
Then form should be submitted successfully

Examples:
|patient|
|pat1   |
|pat2   |

On running get error -

expected: #TagLine, #ScenarioLine, #ScenarioOutlineLine, #Comment, #Empty, got 'Background:'
expected: #TagLine, #ScenarioLine, #ScenarioOutlineLine, #Comment, #Empty, got 'Given an authenticated user'
Manya
  • 315
  • 4
  • 17
  • Just remove the `Outline` from Scenario and try! – Ram Pasala Aug 09 '16 at 17:39
  • @igniteram1 This `Outline` should be exactly where it is right now and must not be removed. – Eugene S Aug 10 '16 at 02:21
  • Ya I agree there were some changes to this, that's why i suggested to remove and try. But nevertheless this should work I tried it works! check your feature files for other things may be that is causing! – Ram Pasala Aug 10 '16 at 04:14
  • Got the issue. The feature file contained tags in between 'Feature' and 'Background' keywords which was causing the issue. Moving the Background to just below 'Feature' solved the issue. Thanks for your inputs, – Manya Aug 10 '16 at 18:21

2 Answers2

1

It looks like the feature heading is missing. Cucumber needs a defined feature for your scenarios in order to run.

To just test things out try this:

Feature: Test features

Background:
Given an authenticated user

Scenario Outline:  test something
Given the home page is displayed
When I fill the form for <patient>
Then form should be submitted successfully

Examples:
|patient|
|pat1   |
|pat2   |
Mallory
  • 251
  • 2
  • 5
  • it had the Feature heading. I just did not add it in the example. Anyways it does not solve the issue – Manya Aug 09 '16 at 16:33
  • @Manya The please post your **full** feature file. People don't have to guess how it looks like. – Eugene S Aug 10 '16 at 02:18
0

When you are using scenario outline there should be regex for the examples in step definition file. In your case, in this step When I fill the form for patient, for patient you need to use (.*) this regex to execute with pat1 and pat2 examples.

Second thing whatever error you are getting are different for both the scenario. In first case you are expecting this: #TagLine, #ScenarioLine, #ScenarioOutlineLine, #Comment, #Empty, but the result of your step definition file was giving only 'Background:'.It means the test case is failing in assertion. There is no error in feature file. If you are running multiple test cases then you need to give name for this feature to identification of our test case.

Thank you.

Gajanan Kulkarni
  • 697
  • 6
  • 22