Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8234619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:32:36+00:00 2026-06-07T18:32:36+00:00

I have two scenarios in two different feature files but both scenarios tests search

  • 0

I have two scenarios in two different feature files but both scenarios tests search functions but on different parts of my page.
The scenarios I have looks something like this:

Scenario Outline: Search items from QuickSearch
Given that the following items
  | id | title       | 
  | 1  | Item1       | 
  | 2  | Item2       |
When I search for <criteria> in this search
Then I should get <result>
And I should not get <excluded>

Examples:
|criteria|result    | excluded  |
| 1      | 1        | 2         |
| 2      | 2        | 1         |

and:

Scenario Outline: Using a filter
Given that I have the following things:
 |id |name     |
 |1  | thing1  |
 |2  | thing2  |
When I use the <filter> filled with <criteria>
Then I should obtain these <results>
And I should not obtain these <exclusions>

Examples:
|filter     |criteria   |results    |exclusions |
|name       |thing      |1,2        |           |
|id         |1          |1          |2          |

As you can tell in the second scenario I have changed the word get to obtain in order to write separate steps for the two scenarios.
The only reason I need two different steps is because the id in the 2 different scenarios map to different names (no I cant use the same for both and don’t want to start on id 3 in the second)

So I’m thinking about common steps for both of the scenarios (at least when it comes to the then steps) and I want a hash mapping id and name together in order to do validation, but I want the hash to be different depending on which scenario called the step.

So, is there a way in cucumber + capybara that I can tell which scenario called a step?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:32:37+00:00Added an answer on June 7, 2026 at 6:32 pm

    I do not know of a way to directly access the scenario name from the Cucumber step. However, you can access the name in a before hook and store it in a variable so that it is available to your steps.

    Add this before hook to your env.rb:

    Before do |scenario|
        case scenario
            when Cucumber::Ast::OutlineTable::ExampleRow
                @scenario_name = scenario.scenario_outline.name
            when Cucumber::Ast::Scenario
                @scenario_name = scenario.name
            else
                raise('Unhandled scenario class')
        end
    end
    

    Edit: if you’re using a more recent version of Cucumber, try instead:

    Before do |scenario|
      case scenario.source.last
      when Cucumber::Core::Ast::ExamplesTable::Row
        @scenario_name = scenario.scenario_outline.name
      when Cucumber::Core::Ast::Scenario
        @scenario_name = scenario.name
      else
        raise('Unhandled scenario class')
      end
    end
    

    Your steps can then check the scenario name using @scenario_name. Example:

    Then /I should get (.*)/ do |result|
      if @scenario_name == 'Search items from QuickSearch'
        # Do scenario specific stuff
      elsif @scenario_name == 'Using a filter'
        # Do scenario specific stuff
      end
    
      # Do any scenario stuff
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to implement remote debugging in two different scenarios both without
I have scenario, I have two update panels on the page (both have update
There is two different scenarios I'm after: You have a shared_ptr You have a
Scenario I have a windows forms application. I want to use two different WCF
I have two distinct scenarios. One, where there is a many to many case,
I have a generic question about scope and encapsulation. Take two scenarios: Scenario 1:
Assume the following scenario. I have two files A.cpp and B.cpp in trunk. At
I have two scenarios. Suppose I have 3 shared libraries that export C++ symbols,
Assume two different scenarios: a) Each (service) class X has an interface X and
I have setup a Master/Slave replicatio in two different servers with the exact same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.