capybara - Is there a way to check which cucumber scenario called a certain step? -
I have two scenarios in two different feature files, but both scenarios test the search functions, but my pages On different parts of In scenarios, I see something like this:
Scenarios Outline: Search items from Quick Search, considering that the following items. ID | Title | | 1 | Item 1 | 2 | Item 2 | When I & lt; Criteria & gt; In this search then I'll be able to & lt; Results & gt; And let me & lt; Excluded & gt; Example: | Criteria | Results | Excluded. | 1 | 1 | 2 | | 2 | 2 | 1 |
And:
Scenario outline: Using a filter Given that I have the following things: | Id | Name | | 1 | Thing 1 | 2 | Talk 2 When I & lt; Filter & gt; & Lt; Benchmarking & gt; Filled with this I'll get this & lt; Results & gt; And let me see this & lt; Exclusions & gt; Examples should not be obtained: | Filter | Criteria | Results | Exclusion | | Name | Talk 1,2 | | | | ID | 1 | 1 | 2 |
As you can tell in another scenario, I have changed the two scenarios to get the word to write different steps. The only reason is that I need two different steps because IDs map to different names in different 2 scenarios (I can not use it for both, and do not want to start at ID3 in the other )
So I am thinking of common steps for both scenarios (at least when this step takes place) and I have to get a hash mapping ID and name to verify, but IWant to differentiate the hash on which the scenario is called.
So, there is a way in cucumber + Cappabara that which position I have said a step?
I do not know a way to access the name of the scenario directly from cucumber stage, however, you hook it first You can use the name in it and store it in any variable so that it is available for your steps.
Add it before hooking up your env.rb:
First make. Scenario | Case scenario when cucumber :: Est :: OutlineBall :: Example Line @scenario_name = Scenario. Scenario_outline.name when cucumber :: Est :: Scenario @scenario_name = Scenario.name and Extend ("without vertical class") End term
Your step can then examine the landscape name using @scenario_name
. Example:
Then / I should get (. *) / Do it. Results | If @scenario_name == 'Find Items From Quick Search' Scenarios Specific Content elsif @scenario_name == 'Using a Filter' # End of Scenario Specific Content #Do Alliance Landscape Accessories End
Comments
Post a Comment