With appropriate options Cucumber can control Webdriver which actually fires up

With appropriate options cucumber can control

This preview shows page 272 - 274 out of 517 pages.

With appropriate options, Cucumber can control Webdriver, which actually fires up a real browser and “remote controls” it to make it do what the stories say, including all JavaScript code. For this chapter, we will stick to using Capybara’s “headless browser simulator” mode, which is much faster and is appropriate for testing everything except JavaScript. Figure 7.16 towards the end of the chapter shows the relationship among these tools. 7.7 Running Cucumber and Capybara A major benefit of user stories in Cucumber is Red-Yellow-Green analysis . Once a user story is written, we can try to run it immediately. In the beginning, steps may initially be highlighted either in Red (for failing) or Yellow (not yet implemented). Our goal is to take each step and go from Yellow or Red to Green (for passing), by incrementally adding what’s needed to make it pass. In some cases, this is really easy. In the next chapter, we similarly try to go from Red to Green at the level of unit tests . Recall that unit tests are for individual methods whereas Cucumber scenarios test entire paths through the app and thus can be acceptance tests or integration tests. Cucumbers are green The test-passing green color of the cucumber plant gives this tool its name. Like other useful tools we’ve seen, Cucumber is supplied as a Ruby gem, so the first thing we need to do is declare that our app depends on this gem and use Bundler to install it. Building on the myrottenpotatoes app you started in Chapter 4 , add the following lines to Gemfile ; we’ve indicated that Cucumber and its related gems are only needed in the test environment and not the production and development environments (Section 4.2 introduced the three environments in which Rails apps can run).
Image of page 272
1 # add to end of Gemfile 2 group :test do 3 gem ’cucumber-rails’, :require => false 4 gem ’cucumber-rails-training-wheels’ # some pre-fabbed step definitions 5 gem ’database_cleaner’ # to clear Cucumber’s test database between runs 6 gem ’capybara’ # lets Cucumber pretend to be a web browser 7 gem ’launchy’ # a useful debugging aid for user stories 8 end Once you’ve modified Gemfile , run bundle install --without production . If all goes well, you’ll eventually see “Your bundle is complete.” We now have to set up the directories and “boilerplate” files that Cucumber and Capybara need. Like Rails itself, Cucumber comes with a generator that does this for you. In the app’s root directory, run the following two commands (if they ask whether it’s OK to overwrite certain files such as cucumber.rake , you can safely say yes): rails generate cucumber:install capybara rails generate cucumber_rails_training_wheels:install Running these two generators gives you commonly used step definitions as a starting point, such as interactions with a web browser. For this app, you will find them in myrottenpotatoes/features/step_definitions/web_steps.rb . In addition to these predefined steps, you’ll need to create new step definitions to match the unique functionality of your app. You will
Image of page 273
Image of page 274

You've reached the end of your free preview.

Want to read all 517 pages?

  • Spring '19
  • Dr.Marcos

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors