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 7756267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:46:45+00:00 2026-06-01T12:46:45+00:00

I wrote a feature to test the default configuration of my web app using

  • 0

I wrote a feature to test the default configuration of my web app using Cucumber and Capybara. Part of the feature looked like this:

And the page has a photo labeled "Device"
And the page has a checkbox labeled "Device"
And I check "Device"
And I submit the form
Then the resulting page has no photo labeled "Device"

It worked great. I want users who have installed and configured the web app on their own servers to be able to run the test to help confirm that their configuration is correct. And “Device” is a string in the default config file that the user can change. It’s an element in an array and they can add to or remove from the array when configuring their instance of the app.

Is this a sensible use of the tools or am I abusing Cucumber and/or Capybara? If it’s sensible, how would I do it? If it’s a bad idea, what tools might I use for this instead, if anything?

Here’s how I got it to work. I’m just not sure this is the best way to do it.

For this to work, the feature would have to look more like this:

And the page has at least 3 photos, let us call the last one "third_photo"

In the corresponding step definition, I use an XPath to pull out the corresponding label string for the first photo and assign it to a Hash object stored in a class variable.

And /^I the page has at least (\d*) photos, let us call the last one "([^\"]*)"$/ do |n, name|
  if ! defined?(@note)
    @note = Hash.new;
  end
   @note[name] = find(:xpath, '//ol[@id="menu"]/li[' +n+ ']/a').text;
end

Subsequent step definitions can now access the value, whatever it was.

So, another feature might be:

Then I uncheck "third_item"

And the corresponding step definition might be:

Then /I uncheck "([^\"]*)"/ do |item|
  uncheck(@note[item])
end

But I don’t feel good about it. If nothing else, I imagine there might be a name collision with another instance variable defined outside the step definitions.

It feels like I’m either Doing It Wrong or else I’m Using The Wrong Tool. What is the right way to do this?

  • 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-01T12:46:47+00:00Added an answer on June 1, 2026 at 12:46 pm

    There’s a blog post about using instance variables in step definitions at http://www.cloudspace.com/blog/2010/06/23/using-instance-variables-with-cucumber-steps/.

    Commenters talk about the coupling this entails and at least one possible way around it.

    In particular, davetron5000 says:

    What we do is to not use instance variables at all, but instead
    provide a has that shared state can go in. This hash is cleared after
    each test run. Not ideal, but it’s a bit cleaner than random instance
    variables all over the place (and also ensures a reasonably clean
    state before each test)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a test app using the twitter gem and I'd like to write
I have to write integration test case for my one feature listing page and
I wrote a test app that should never stop. It issues t.wait() ( t
I am trying to test drive an application feature using Robotium. One of the
Here's what I've done: I wrote a minimal web server (using Qt, but I
So I'm writing my app doing feature-first BDD with Rails, Cucumber, RSpec. My client
For example if I write Add A customer feature which might go like this:
Would having a nice little feature that makes it quicker to write code like
Using the C# compilers query comprehension features, you can write code like: var names
I wrote a windows service using VB that read some legacy data from Visual

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.