calabash / calabash-ios

Calabash for iOS
Other
1.81k stars 369 forks source link

Cucumber is running the background in an inappropriate way #1361

Closed guruprasadsr closed 6 years ago

guruprasadsr commented 6 years ago

Cucumber is running the background in an inappropriate way

Information: I have a background at the beginning of the tests that I have written for my iOS app. I use calabash cucumber to test the iOS app. When I have a background, I have observed that it is invoked at the beginning of the feature execution. Sometimes, it is also called when I run a scenario and my tests start to fail. In my calabash-ios frameowork, I have a lot of feature files (12 to be exact). Each of the feature files have 50-100 scenario and scenario outlines. The feature files have a background. I expect the background to be run for every scenario/scenario outline. This is not happening.

Configuration: Ruby: ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15] Calabash-cucumber: 0.21.1 Cucumber: 3.1.0

Questions:

1) Will a background be run before each scenario? 2) From the executions I have seen that it is being run at the beginning of the feature file. In one of the other scenario, it will be invoked and the test fails. Is it the expected behavior?

Sample feature:

@f_TestFeature Feature: This is a sample feature that I will use to understand the background

Background: This is a background Given I run the background

@uninstall_install_app_testfeature Scenario: If App is already present, uninstall it and install the app again Given I uninstall install and then open the app sample

@scenaio1 Scenario: I am on the screen sample 1 Given I am on the screen sample 1

@scenaio2 Scenario: I am on the screen sample 2 Given I am on the screen sample 2

@scenaio3 Scenario: I am on the screen sample 3 Given I am on the screen sample 3

Steps:

Given("I run the background") do puts "Running background now" end

Given("I uninstall install and then open the app sample") do puts "I uninstall install and then open the app sample" end

Given("I am on the screen sample 1") do puts "I am on the screen sample 1" end

Given("I am on the screen sample 2") do puts "I am on the screen sample 2" end

Given("I am on the screen sample 3") do puts "I am on the screen sample 3" end

Output:

$ cucumber features/sample.feature -f pretty -f html --out='test123.html' @f_TestFeature Feature: This is a sample feature that I will use to understand the background

Background: This is a background # features/sample.feature:4 Given I run the background # features/step_definitions/sample_steps.rb:1 Running background now

@uninstall_install_app_testfeature Scenario: If App is already present, uninstall it and install the app again # features/sample.feature:8 Given I uninstall install and then open the app sample # features/step_definitions/sample_steps.rb:5 I uninstall install and then open the app sample

@scenaio1 Scenario: I am on the screen sample 1 # features/sample.feature:12 Given I am on the screen sample 1 # features/step_definitions/sample_steps.rb:9 I am on the screen sample 1

@scenaio2 Scenario: I am on the screen sample 2 # features/sample.feature:16 Given I am on the screen sample 2 # features/step_definitions/sample_steps.rb:13 I am on the screen sample 2

@scenaio3 Scenario: I am on the screen sample 3 # features/sample.feature:20 Given I am on the screen sample 3 # features/step_definitions/sample_steps.rb:17 I am on the screen sample 3

4 scenarios (4 passed) 8 steps (8 passed) 0m0.027s

jmoody commented 6 years ago

The feature files have a background. I expect the background to be run for every scenario/scenario outline. This is not happening.

This is a cucumber problem, not a Calabash problem.

Background: This is a background
Given I run the background

Background Steps are run before every Scenario in the feature file.

I think you need to ask in a Cucumber forum.