extremely cheezy

Main menu

Cucumber & Cheese

My book if finally out! You can pick up a beta copy of the book at the LeanPub site.

A few years ago I set out to master Acceptance Test Driven Development (ATDD, also variously known as Behavior Driven Development or Storytesting). After trying several of the available tools I settled on Cucumber. For Web applications, I also used the most popular Ruby tool for page traversal and verification, Watir.

As I started working with teams to implement this practice, I discovered that the ATDD community was writing more and more new Ruby gems to empower and simplify this kind of testing. I also found that some of the things I personally wanted to simplify were not supported by any existing Ruby gem, so like the crazed developer I am, I set out to build my own. To my surprise, others started using some of the gems I created and began asking a lot of questions about their usage.

This book is my attempt to share as much of my experience using Cucumber and Watir as possible. I will cover many patterns, practices, tools, and (Yes) Ruby gems that make testing applications (particularly but not limited to Web applications) easier including a few of my own. I will also cover the proper way to structure and write your test automation code so that it is less brittle, simpler, better organized, more expressive, and therefore easier to change over the lifecycle of your application. My goal is to help you see and understand the benefits of ATDD and learn how to use Cucumber and Ruby to adopt (and help us refine!) this amazing practice.

This book is full of hands-on programming exercises and I strongly suggest you do them all. Even if you are not testing applications that are like the ones showcased in this book, the knowledge of how to write sound robust tests will transfer to whatever you have to test.

Downloads

154 thoughts on “Cucumber & Cheese”

Eagerly waiting for your book ! I hope it will be about a testing framework using Cucumber+RSpec+watir-webdriver. Am I right?
and btw, could you hihg-light the difference between your page object implementation from that of Alister Scott’s (watirmelon.com) ?

You are right about the topic of my book. It will be focused on those topics as well as other interests for writing robust test suites like test data management, etc.

Alister Scott’s gem is based on a simple module I wrote for a client a couple of years ago and blogged about here. It is a very nice, clean wrapper for making pages. My gem adds a lot more functionality. I believe it addresses many of the problems people have when testing websites.

I have been given the opportunity to work in corporate environment on an agile software development right out of college as a tester and will start learning about automated tesing soon. I am very much a beginner and have little to no exposure to Ruby and much less programming in general. I will be using RubyMine and Cucumber to develop test scripts so I watned to know if your book will be for an advanced user or a rookie like me?

I though I was testing not too bad, and after your book, I want to do it better.
So, I am asking myself a lots of details.
– Is it seems acceptable to play with the @browser in a PageObject method ?
– How to go on a particular url in start of a PageObject method ? Actually, I add a cucumber step to make a goto before to use my PageObject.

1) I think you will not need to play with the @browser in your methods. Everything you should need is available through the PageObject module and supporting classes. If you find some capability that is only available through the @browser instance please let me know so I can add it to the gem.

2) I am not sure how far you are in the book but what you are describing is exactly what the page_url and visit_page combo are designed to do. In you page object you use the page_url class method to define the url for the page and in your step definitions you can use the visit_page(YourPage). This will take you to the page and then you can begin your work.

I’m new to automated testing, but I’m trying to get my head round Gherkin, BDD and stuff like that. Coming from a PHP background, I have been using Behat and I have thrown a few rather obscure questions at the Behat forum, which led to Marcello telling me I am
‘trying to achieve the “acceptance-testing-centric model” ..’ rather than ‘.. the “system-behaviour-specification-centric model”‘

So, my question is.. should I buy your book? Will it help me understand how to structure acceptance tests and develop a testing framework using Behat, Gherkin, Mink and PHP, or is it purely aimed at the Ruby / Watir / Cucumber world?

I will probably buy it anyway, but if you can tell me it would be useful then I can get the company to pay for it!

I have just started working through the exercises in the book, but as you may already know one of the links required to complete the exercise is not working. This is where you click on the “Adopt Me” button for the chosen puppy and then fill out details. Do you have any idea when this will be back up?

As an alternative can I try downloading the application locally and changing the web links in the ruby scripts?

Thanks for the heads up on that. I was not aware that the application was having problems. Heroku upgraded my database (not at my request) on Monday and something must have happened. I’ll look into it today.

Hi
I’m trying to run the following command:>testgen project test_puppies
and getting the error below after installing the testgen gem. I have looked around for answers to similar issues on various sites but can’t find anything that seems useful.
Was wondering if you had run into this before and could advise what I can do to solve?

Some extra info that may help.
I have been having trouble executing the commands to install gems as outline in the book. As an example I have tried to run

>gem install rake bundler yard watir-webdriver

ERROR: Could not find a valid gem ‘rake’ (>= 0) in any repository
ERROR: While executing gem … (Gem::RemoteFetcher::FetchError)
Errno::EHOSTUNREACH: A socket operation was attempted to an unreachable host
. – connect(2) (http://rubygems.org/latest_specs.4.8.gz)

The first time I did this on my personal machine it worked. Several weeks later however I tried it on our dev/test machine and it gave the error above. At the time there was a message on the http://rubygems.org/ site saying that the “Dependancy API” was not working 100% and the status of the API was shown as red at http://status.rubygems.org/. I thought that this may have had something to do with it. I then proceeded to download and install each gem manually, including the dependant gems. One of the one’s I missed was the aruba gem. Was wondering if this may be the cause of not being able to run the testgen command above?

>gem install rake bundler yard watir-webdriver
ERROR: Could not find a valid gem ‘rake’ (>= 0) in any repository
ERROR: While executing gem … (Gem::RemoteFetcher::FetchError)
Errno::ETIMEDOUT: A connection attempt failed because the connected party di
d not properly respond after a period of time, or established connection failed
because connected host has failed to respond. – connect(2) (http://rubygems.org/
latest_specs.4.8.gz)

That error typically means that the gem process is unable to make a connection with rubygems.org or one of the other mirrors. Is it possible that the machine you are trying this on is not connected to the internet or is having some networking issues?

Hi
1) I have tried on three different machines within my company LAN , one of which was a virtual machine and they are all displaying the same sort of behaviour. I can access the internet on all of them. I have also tried disconnecting one of the machines from the company LAN and connecting it to my home internet connection and getting similar behaviour.

a) Could it be an issue with rubygems.org web site
b) Is there another way to install them?

2) Do you have any feedback on my initial question regarding the error I was getting running the “testgen create project” command dated October 27, 2012 at 3:47 further up the blog

p.S apologies for all the questions, just eager to get something running!

I did a check of the testgen gem and discovered that I am no longer using the functionality that caused me to include the sys-uname gem. In response to this discovery I just released a new version of testgen that eliminates that dependency. Please get the latest testgen (version 0.5.2) and then perform a bundle update on your project.

Hi! A concept question. On page 97 you create a module called SideMenuPanel that holds the elements for the side menu and afterwards require and include it on the class.

If the SideMenuPanel is almost all around the site, what about to create a class for it? I know its not a Page but this way you can reference to it as on_page(SideMenuPanel) to perform menu actions and you can continue with on_page(HomePage) for the other interactions. Is there any other problems on that except the Menu is not a Page and is not “elegant” to use a class?

I’m trying to follow the Chapter on working with and connecting to Databases and experienced the following issue when setting up the puppy site on my local. In the puppies directory I ran the bundle Install command and received “Could not find addressable-2.3.1 in any of the sources” I checked the rubygems.org site and this version of addressable is marked as yanked. So when I run the rails s command the puppy site does not start. Is there a workaround for this? I’m new to ATDD, and your book has been a tremendous help! Keep up the good work!

I have a problem with “bundle install” in the puppies directory(page 106)
C:\puppies>bundle install
Fetching gem metadata from http://rubygems.org/………
Fetching gem metadata from http://rubygems.org/..
Resolving dependencies…
Could not find addressable-2.3.1 in any of the sources

OS: Windows 7
btw, “test_puppies” project works fine and test_puppies and puppies are in the same diractory

Hello! I purchased your book this week and have found it to be very useful. I have just started the section Cucumbers & Puppies and have run into some problems. I should start by saying that I am behind a corporate firewall and the only way I could get the gems installed was to go to the RubyGems website and download one at a time as I was made aware of the dependencies, and then install from the download folder. My OS is Windows Server 2008 R2 – 64 bit. When I try to run making_cheese.feature, I get the following errors:
C:\Ruby200\bin\ruby.exe -EUTF-8 -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:\Ruby200\bin/cucumber C:/RubymineProjects/test_puppies/features/making_cheese.feature –format Teamcity::Cucumber::Formatter –expand –color -r features
Testing started at 1:52 PM …
Using the default profile…
WARNING: cannot load such file — 2.0/gherkin_lexer_en
Couldn’t load 2.0/gherkin_lexer_en
The $LOAD_PATH was:
C:/Ruby200/lib/ruby/gems/2.0.0/gems/cucumber-1.2.1/bin/../lib
C:/RubyMine 5.0/rb/testing/patch/common
C:/RubyMine 5.0/rb/testing/patch/bdd
C:/Ruby200/lib/ruby/gems/2.0.0/gems/gherkin-2.11.6/lib
C:/Ruby200/lib/ruby/gems/2.0.0/gems/builder-3.2.0/lib
C:/Ruby200/lib/ruby/gems/2.0.0/gems/diff-lcs-1.2.1/lib
C:/Ruby200/lib/ruby/gems/2.0.0/gems/cucumber-1.2.1/lib
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-expectations-2.13.0/lib
C:/Ruby200/lib/ruby/gems/2.0.0/gems/multi_json-1.6.1/lib
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rubyzip-0.9.9/lib
C:/Ruby200/lib/ruby/gems/2.0.0/gems/ffi-1.4.0/lib
C:/Ruby200/lib/ruby/gems/2.0.0/gems/ffi-1.4.0/ext/ffi_c
C:/Ruby200/lib/ruby/gems/2.0.0/gems/childprocess-0.3.8/lib
C:/Ruby200/lib/ruby/gems/2.0.0/gems/websocket-1.0.7/lib
C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.30.0/lib
C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-webdriver-0.6.2/lib
C:/Ruby200/lib/ruby/gems/2.0.0/gems/i18n-0.6.4/lib
C:/Ruby200/lib/ruby/gems/2.0.0/gems/faker-1.1.2/lib
C:/Ruby200/lib/ruby/gems/2.0.0/gems/yml_reader-0.2/lib
C:/Ruby200/lib/ruby/gems/2.0.0/gems/data_magic-0.14/lib
C:/Ruby200/lib/ruby/gems/2.0.0/gems/page_navigation-0.7/lib
C:/Ruby200/lib/ruby/gems/2.0.0/gems/page-object-0.8.6/lib
C:/Ruby200/lib/ruby/site_ruby/2.0.0
C:/Ruby200/lib/ruby/site_ruby/2.0.0/i386-msvcrt
C:/Ruby200/lib/ruby/site_ruby
C:/Ruby200/lib/ruby/vendor_ruby/2.0.0
C:/Ruby200/lib/ruby/vendor_ruby/2.0.0/i386-msvcrt
C:/Ruby200/lib/ruby/vendor_ruby
C:/Ruby200/lib/ruby/2.0.0
C:/Ruby200/lib/ruby/2.0.0/i386-mingw32. Reverting to Ruby lexer.
No lexer was found for en (cannot load such file — gherkin/lexer/en). Supported languages are listed in gherkin/i18n.json. (Gherkin::I18n::LexerNotFound)
C:/Ruby200/lib/ruby/gems/2.0.0/gems/gherkin-2.11.6/lib/gherkin/i18n.rb:108:in `rescue in lexer’
C:/Ruby200/lib/ruby/gems/2.0.0/gems/gherkin-2.11.6/lib/gherkin/i18n.rb:97:in `lexer’
C:/Ruby200/lib/ruby/gems/2.0.0/gems/gherkin-2.11.6/lib/gherkin/parser/parser.rb:138:in `transition_table’
C:/Ruby200/lib/ruby/gems/2.0.0/gems/gherkin-2.11.6/lib/gherkin/parser/parser.rb:127:in `build_transition_map’
C:/Ruby200/lib/ruby/gems/2.0.0/gems/gherkin-2.11.6/lib/gherkin/parser/parser.rb:123:in `transition_map’
C:/Ruby200/lib/ruby/gems/2.0.0/gems/gherkin-2.11.6/lib/gherkin/parser/parser.rb:90:in `initialize’
C:/Ruby200/lib/ruby/gems/2.0.0/gems/gherkin-2.11.6/lib/gherkin/parser/parser.rb:67:in `new’
C:/Ruby200/lib/ruby/gems/2.0.0/gems/gherkin-2.11.6/lib/gherkin/parser/parser.rb:67:in `push_machine’
C:/Ruby200/lib/ruby/gems/2.0.0/gems/gherkin-2.11.6/lib/gherkin/parser/parser.rb:30:in `parse’
C:/Ruby200/lib/ruby/gems/2.0.0/gems/cucumber-1.2.1/lib/cucumber/feature_file.rb:37:in `parse’
C:/Ruby200/lib/ruby/gems/2.0.0/gems/cucumber-1.2.1/lib/cucumber/runtime/features_loader.rb:28:in `block in load’
C:/Ruby200/lib/ruby/gems/2.0.0/gems/cucumber-1.2.1/lib/cucumber/runtime/features_loader.rb:26:in `each’
C:/Ruby200/lib/ruby/gems/2.0.0/gems/cucumber-1.2.1/lib/cucumber/runtime/features_loader.rb:26:in `load’
C:/Ruby200/lib/ruby/gems/2.0.0/gems/cucumber-1.2.1/lib/cucumber/runtime/features_loader.rb:14:in `features’
C:/Ruby200/lib/ruby/gems/2.0.0/gems/cucumber-1.2.1/lib/cucumber/runtime.rb:170:in `features’
C:/Ruby200/lib/ruby/gems/2.0.0/gems/cucumber-1.2.1/lib/cucumber/runtime.rb:46:in `run!’
C:/Ruby200/lib/ruby/gems/2.0.0/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:43:in `execute!’
C:/Ruby200/lib/ruby/gems/2.0.0/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:20:in `execute’
C:/Ruby200/lib/ruby/gems/2.0.0/gems/cucumber-1.2.1/bin/cucumber:14:in `’
C:/Ruby200/bin/cucumber:23:in `load’
C:/Ruby200/bin/cucumber:23:in `’
-e:1:in `load’
-e:1:in `’

I would suspect that the gems were not installed properly. Please take a look at this page and see if setting the http-proxy value will allow you to get through the firewall. If so, I would suggest installing the gems again. Let me know if this is not an option and we will look at other solutions.

When you included PageObject it added a method named initialize that requires you to pass a browser object. You would only want to include this module in classes that are indeed page objects. That will be explained later in the book.

You should have all of your features in a directory named features and the step definitions in a directory named step_definitions under that directory. If you use the tool testgen to generate your project structure it will follow this pattern. These are the directories that cucumber is expecting.

I understood that unordered_list is a method available in the page_object gem. How we are passing a local variable, (named as a page, here) which is acting as a parent object (like current page) for the div object. Please explain. I am not understanding this block of code.
Explanation in the book – “Instead we are passing a block which receives a local variable which is an instance of our page” – actually we are writing a class which is going to represent a page. Where we are creating the instance of our page.

Hope you got my question. Waiting for your response with more excitement.

A block is nothing more than a piece of code that is passed to a method as an argument. At some later point, the method receiving the block decides when it is time to execute that block.

In the case of the each method above, it takes a single argument which is a block. In the unordered_list method above we have the following signature:

unordered_list(name, identifier={:index => 0}, &block)

This method can be called in one of three ways.

1) You can call it with the name only like this – unordered_list(:error_list). In this case the second parameter kicks in and it will select the first unordered list if finds when you call one of the generated methods.

2) You can call it with the name and identifier like this – unordered_list(:error_list, :id => 'some_id'). In this case it will use the id to locate the unordered list when you call one of the generated methods.

3) You can call it with the name and the block like this – unordered_list(:error_list) do |page|... end. IN this case it will expect the block to find the unordered list. The reason we can pass the page as a parameter is that the block is not executed until you use one of the generated methods which is after the instance of the page is created.

Again, when we call one of the generated methods on the page instance the block is executed and when it is executed it is passed the instance of the page. I hope this all makes sense.

I got a laptop with Windows 8 o/s. installed ruby 1.9.3 and rubymine 4.0.3.
After installing testgen and bundler, using testgen created test_puppies project.
did .bundle install n Bundle update .
Added a first feature as below
Feature: Adopting puppies
Scenario: Adopting one puppy
Given I am on the puppies adoption website
when I ran the scenario got the fallowing error. Tried a lot to resolve but not succeeded. Please help me.

When I installed latest version of the rubymine how to make sure that all the gems installed earlier will automatically gets loaded to Rubymine latest version showthat I can see in setttings/rubysdk and gems window.

RubyMine does not actually load the gems. Instead, it points to them. You can select the appropriate version of ruby to use (from the ones you have installed) in the Settings dialog in the section labeled “Ruby SDK and Gems”.

Thank you for an excellent book, I like the very hands on approach, I am stuck at the end of chapter 5 , section “Removing the duplicate navigation”,B6.0 the method call to navigate_to does not work in the below step, am I missing something ? all routes are setup in env.rb and all requires seem to be in place. I cant also find the definition of navigate_to in page_factory.rb

When(/^I checkout leaving the name field blank$/) do
navigate_to(CheckoutPage).checkout(‘name’ => ”)
end
…
When I checkout leaving the name field blank
undefined method `new’ for PageObject::PageFactory:Module (NoMethodError)
./features/step_definitions/adoption_steps.rb:85:in `/^I checkout leaving
the name field blank$/’
features\adopting_puppies.feature:80:in `When I checkout leaving the name
field blank’

—
Having said that the below step from another scenario that uses navigate_all works

Sorry pl ignore the previous error , the actual error message I get is is below
———-
When I checkout leaving the name field blank
undefined method `navigate_to’ for nil:NilClass (NoMethodError)
./features/step_definitions/adoption_steps.rb:85:in `/^I checkout leaving
the name field blank$/’
features\adopting_puppies.feature:80:in `When I checkout leaving the name
field blank’
Then I should see error message “Name can’t be blank”
———-

Its me again :-), just realised that I had missed the page_navigation gem, how ever this still does not work, I am not sure how will the navigate_to will work without an initial page reference ? how ever the code in the book uses it without a reference ?

Thanks for your message.
Solved it, found out that in my env.rb I had World(PageObject::PageFactory, PageObject) causing the navigate_to of module PageObject being invoked instead of the page_navigation method ! removed the PageObject from there.

bundle install for test_puppies gives
—— Start —
D:\eBook\cucumber\cukes_and_cheese\test_puppies>bundle install
Using i18n (0.6.4)
Using multi_json (1.7.7)
Using activesupport (3.2.1)
Using builder (3.0.4)
Using activemodel (3.2.1)
Using arel (3.0.2)
Using tzinfo (0.3.37)
Using activerecord (3.2.1)
Using ffi (1.9.0)
Using childprocess (0.3.9)
Using diff-lcs (1.2.4)
Using gherkin (2.12.0)
Using cucumber (1.3.2)
Using faker (1.1.2)
Using yml_reader (0.2)
Using data_magic (0.14)
Using database_cleaner (1.0.1)
Using factory_girl (4.2.0)
Using page_navigation (0.9)
Using rubyzip (0.9.9)
Using websocket (1.0.7)
Using selenium-webdriver (2.33.0)
Using watir-webdriver (0.6.4)
Using page-object (0.9.0)
Using rspec-core (2.13.1)
Using rspec-expectations (2.13.0)
Using rspec-mocks (2.13.1)
Using rspec (2.13.0)
Using sqlite3 (1.3.7)
Using bundler (1.0.22)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
— End —

Just a suggestion about the book, I often tend to copy and paste the code snippets from the book as I progress but am having to delete the line numbers that get copied from the pdf , is there a way this can be avoided perhaps by havng line numbers a comments on the right hand side instead or have a ‘figure’ label for each snippet that points to a url ? I find the snippets extremly useful and prefer to either type them myself or copy paste instead of downloading an entire zip file. This makes it stick to you more.

Hello Cheezy,
Having issues running the android demo, error “Unknown error (Windows says “The operation completed successfully.”, but it did not.) (ChildProcess::LaunchError) on Windows 7 Enterprise 64 bit. I understand that this might be a known issue. Any workarounds ?

Hello Cheezy,
This is my first ever test test for a mobile app !
I have managed to install the android SDK and managed to install the puppy application which then I can start from the android avd command and I can start the puppy app on the emulator. I then try to run cuke features as mentioned in the book which throws the error.

bundle update gives
Using rake (10.1.0)
Using ffi (1.9.0)
Using childprocess (0.3.9)
Using ADB (0.5.6)
Using brazenhead (0.4.7)
Using builder (3.2.2)
Using diff-lcs (1.2.4)
Using multi_json (1.7.7)
Using gherkin (2.12.0)
Using multi_test (0.0.1)
Using cucumber (1.3.3)
Using i18n (0.6.4)
Using faker (1.1.2)
Using yml_reader (0.2)
Using data_magic (0.14)
Using page_navigation (0.9)
Using gametel (0.7)
Using require_all (1.2.1)
Using rspec-core (2.14.1)
Using rspec-expectations (2.14.0)
Using rspec-mocks (2.14.1)
Using rspec (2.14.0)
Using bundler (1.0.22)
—————————-
Error thrown to console
——————————
Using the default profile…
Feature: Displaying information about the puppies available for adoption

This screen really has no behavior. It simply displayes the
list of puppies available for adoption.

Scenario: Knowing the name of the available puppies
[36mThen I can see that “[36m[1mSparky[0m[0m[36m” is available for adoption[0m

Scenario: Knowing the breed and gender of available puppies
[36mThen I can see the “[36m[1mRuby Sue[0m[0m[36m” is a “[36m[1mPit Bull Terrier[0m[0m[36m”[0m
[36mAnd I can see that “[36m[1mRuby Sue[0m[0m[36m” is a “[36m[1mFemale[0m[0m[36m”[0m

Scenario: Being overwhelmed by the cuteness of the available puppies
[36mThen I will be moved when I look into “[36m[1mMaggie Mae[0m[0m[36m”s eyes[0m

Scenario: Getting to know the available puppies
[36mThen I can see that “[36m[1mBrook[0m[0m[36m”s description starts with “[36m[1mThis young lady is trying[0m[0m[36m”[0m

Scenario: Learning more about a puppy I am interested in
[36mWhen I want to learn more information about “[36m[1mSparky[0m[0m[36m”[0m
[36mThen I will be able to see “[36m[1mSparky[0m[0m[36m”s details[0m

Scenario: Seeing the name and breed of my puppy
[36mWhen I want to learn more information about “[36m[1mSparky[0m[0m[36m”[0m
[36mThen I know that he is a type of “[36m[1mAustrailian Cattle Dog (Blue Heeler)[0m[0m[36m”[0m
[36mAnd I know that he is a “[36m[1mMale[0m[0m[36m”[0m

Scenario: Learning more about the life of my puppy
[36mWhen I want to learn more information about “[36m[1mSpud[0m[0m[36m”[0m
[36mThen I can see that my puppy “[36m[1mis playful and friendly and would make a great addition to your family[0m[0m[36m”[0m

Scenario: Looking into the eyes of my puppy one last time
[36mWhen I want to learn more information about “[36m[1mRuby Sue[0m[0m[36m”[0m
[36mThen I can look into the eyes of my puppy before I make my decision[0m

Scenario: Knowing what my puppy will set me back
[36mWhen I want to learn more information about “[36m[1mTipsy[0m[0m[36m”[0m
[36mThen I know that the adoption fee is “[36m[1m$42.00[0m[0m[36m”[0m

I am trying to develop a suite of acceptance tests for a legacy .NET web application. One of our goals is to have this suite available so that we can do extensive refactoring of the original backend code. The tests will let us know if we break something.

I am trying to use the PageObject gem to click on a button. Unfortunately the button is not really a button, but is a div, declared in HTML like this:

SignOut

In the legacy javascript/JQuery I read:

$(“#SignOut”).button();

And also:

$(“#SignOut”).click(function() {
…
});

So the button is declared as a div and somehow given a clickable property which functions as desired.

When I try to access and click this element via PageObject I fail.

When I have “button(:signout_button, :id=> ‘SignOut’)” in my page class and “on(DefaultPage).signout_button” in my step definition I get:
unable to locate element, using {:id=>”SignOut”, :tag_name=>”button”} (Watir::Exception::UnknownObjectException)
(eval):1:in `process_watir_call’

When I try using “div(:signout_div, :id=> ‘SignOut’)” in my page class and “on(DefaultPage).signout_div.click” in my step definition I get:

undefined method `click’ for “Sign Out”:String (NoMethodError)

Which makes sense because “on(DefaultPage).signout_div” would just return the contents of the div.

How can I click on this “button” in my test? I prefer to not have to modify the legacy code in order to make it testable.

Do you know of any way to use Cucumber and Watir to interact with a flash module (swf)? I would like to be able to click on links and buttons in the flash element similar to how I interact with a browser application. Any information would be appreciated.

PageObject does not work with Flash because selenium-webdriver and watir-webdriver do not work with Flash. I’ve never worked with Flash so I do not have a good solution for you. You might ask a friend of mine – @robpark on twitter. I think he has some experience with Flash and Cucumber.

Hi Cheezy,
When I tried to install the puppy application, I am getting error – ‘rails’ is not recognized as an internal or external command,
operable program or batch file.

I extracted the zip to the directory where puppy_test is located
In cmd I set the path to – C:\SanjayWork\Ruby-Project\puppies
and run bundle install
It complained that
C:\SanjayWork\Ruby-Project\puppies>bundle install
Fetching gem metadata from http://rubygems.org/……..
Fetching gem metadata from http://rubygems.org/..
Resolving dependencies…
Could not find addressable-2.3.1 in any of the sources

I did a manual install for addressable gem and it installed version 2.3.5

Then I run rails s, then another error –
‘rails’ is not recognized as an internal or external command,
operable program or batch file.

Hi,
I’m making my way through the book and stuck at testgen on page 40.
I ran gem install testgen
gem install bundler
Then i ran testgen project test_puppies –pageobject-driver=watir
and got an error :

No command ‘testgen’ found, did you mean:
Command ‘tetgen’ from package ‘tetgen’ (multiverse)
testgen: command not found

The problem is that testgen is currently on version 0.8.4. Please update the gem and let me know if the problem still exists. If you are using bundler you can simply execute `bundler update`. If not simply execute `gem update testgen`.

Stuck on the webservices example on page 135. I get a bad URI exception. The URI how ever seems to be perfectly valid. Did some googling but not sure if this is a bug in the ruby uri module or something else ? I am using ruby ruby 1.9.3p125 (2012-02-16) [i386-mingw32]

I get the below when I try to run the feature

When I ask the service for the supported operations
bad URI(is not URI?): {:host=>”www.webservicex.net”, :path=>”/uszip.asmx”, :port=>”80″, :query
=>”WSDL”, :scheme=>”http”, :headers=>{}, :body=>nil, :ssl_verify_peer=>true} (URI::InvalidURIError)
D:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/uri/common.rb:178:in `split’
D:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/uri/common.rb:213:in `parse’
D:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/uri/common.rb:749:in `parse’
./features/step_definitions/web_service_steps.rb:2:in `/^I ask the service for the supported operations$/’
features\web_service.feature:4:in `When I ask the service for the supported operations’

Hey Cheese ,
How are you?
I am newvbie in automation , learning things from your book . but here i am facing a challenge is that – how could user background scernario in my every feauter .
example : I want to fill up a form in website . so it needs to log into the site . I have successfully done with login as seperate feature . but when i am writing feature for fill up form , then I could i impletement login in filling up a form feature

I would instead allow a route to handle all of this for me. Setup a route that logs into the system and navigates to the pages. Then your first step could say “Given I’m ” and your step definition could simply “navigate_to(PageForAction)”. Look up the section that talks about navigation and routes in the book.

Love the book. Thanks! I do have a couple questions I hope you can answer.

How would you recommend storing data. For example a list of emails. I want to do something like this:
Given I am signed in as user1

My step would be:
Given(/^I am signed in as ([^”]*)$/) do |user|
@email = somemethod(user)
visit HomePage do |page|
page.signin(:email => @email)
end
end

Should it be stored in a hash? In a module? In a hash in a module? I thought of putting it in the default.yml file that is used by DataMagic but was not sure how to access that in the step definitions. There are currently about 15 email addresses.

Had another question about running tests in parallel. How many threads are possible before stability becomes an issue? I run 8 threads with my quad core. If possible I would like to take advantage of a second quad core using Selenium Grid2. I would run the hub and one node on my laptop. The other node would be on the second machine. Could I run 12-16 threads in this type of setup without issues?
Thanks for your help.

I try to Installing the puppy application on your computer.
When I run
rails s
I am getting:
C:/Ruby193/lib/ruby/gems/1/9.1/gems/execjs-2.0.2/lib/execjs/runtimes.rb:51:in ‘autodetect’: Could not find JavaScript runtime.
See https:github.com/sstephenson/execjs for a list of available runtimes.(ExecJS::RuntimeUnavailable)

First off I just wanted to say that I am completely new to web development/ruby and I am loving it so far! Saw you speak/battle @CodeMash this year and it was a great event – finally found a community I really love.

Going through your book everything was working smoothly until the Factory Girl stuff came into play. I can send my full stack traces if you need them, didn’t want to clutter the post.

factory :adoption do
association :order
puppy Puppy.find_by_name(‘Hanna’)
end
end

World(FactoryGirl::Syntax::Methods)
———————————————————————————————–
Now if I remove require ‘factory_girl’ from my env.rb file, I get :

uninitialized constant FactoryGirl (NameError)
———————————————————————————————–
And lastly whenever I took everything from adoption_factory.rb and slapped it in env.rb, it WORKED! But I wanted to figure out why, I assume this is some sort of structure issue I may have or a Rubymine/Cucumber/CMD Prompt issue requiring files twice.

Thank you so much, sorry for the long message but I wanted to get the full understanding instead of just making things work.

The error is stating that you are trying to declare the order factory more than once. If you look at the entire stack trace and find the first (from the top) that mentions some of your code and not a gem’s code then you can see where it believes you are declaring it a second time.

What directory is the adoption_factory.rb file in? Is it possible that it is getting evaluated more than once? For example, if it is in the systems directory someplace it will automatically be read. If you then require it someplace else it will be read a second time.

I just downloaded a book so I could learn more about cucumber etc. Unfortunately, test application http://puppies.herokuapp.com is not working:
“Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.

Just got into the automation space not too long ago and have some basic experience with Ruby and Cucumber. I am interested in getting your book, but have had a hard time trying to find information on whether Ruby/Cucumber and Watir would work with Drupal coded websites. I see alot of information on Behat/Mink for the PHP based, but Im only familiar with Ruby/Cucumber. Would I be fine with just ruby/cucumber and using Watir to test Drupal sites, or do i need to learn/ get behat/mink?

Hi,
I just love your book after completing 4 chapters. Just facing one problem in proceeding next. The testing web site http://puppies.herokuapp.com/ having some issues. After clicking on Adopt me button its giving some error “We’re sorry, but something went wrong.” could you please take a look at this.
Thanks in advance.

Hello, looks like something not working on http://puppies.herokuapp.com/ again.
Everytime i click on Adopt me on the details page i get an error page saying
“We’re sorry, but something went wrong.
We’ve been notified about this issue and we’ll take a look at it shortly.”

Selenium::WebDriver::Error::NoSuchDriverError: Unexpected error launching Intern
et Explorer. Protected Mode settings are not the same for all zones. Enable Prot
ected Mode must be set to the same value (enabled or disabled) for all zones.

Enjoying the book so far. One issue I’ve run into is with the first cuke example. I created the feature file and step definitions file, both run correctly when executing the Cucumber commands within the Apple Terminal but when I run the feature file within RubyMine, the step definitions aren’t recognized and I get the standard ‘add the snippets’ message. Wondering what may be happening? Any help would be great.

I am reading through your book (great work, thanks a lot!) and in parallel trying to create a testing harness for our application.
I am stuck where page navigation comes into play… routes are defined properly, also World(PageObject::PageFactory) is included in my env.rb
Problem is that not even the first page of the route is being loaded via navigate_to, but the test fails when trying to interact with an element on the page (Watir::Exception::UnknownObjectException: unable to locate element), which is of course not being found, because the browser doesn´t even load the first page of the route. 🙁

Hi Cheesy,
Thanks a lot for the Cucumber and Cheese. I have lil java knowledge and moving to Ruby (Watir+Cucumber) was like walking the park.
When I was using Selenium WebDriver+Testng+Maven f/w (JAVA), we used to
1. prepare logs,
2. read excel files,
3. Collect error logs
4. reports in nice XSLT reports
I have moved entirely to Watir+Cucumber but I am stil missing these 4. Do you suggest doing above in Watir+Cucumber or other optimum way.

Helle Jeff, great thanks for the book, its amazing, but i stuck on this moment:
And(/^I should see “([^”]*)” as the subtotal for Brook line item (\d+)$/) do |subtotal, line_item|
row = (line_item.to_i – 1) * 6
expect (@browser.table(index: 0)[row][3].text).to eql subtotal
end

The issue you have is the space after the word expect. Because of the space, the ruby interpreter believes that everything that follows is an argument to the expect method. Instead, with the space removed it scopes the parameter to the browser call.

First off, great book! But I’ve come across the issue below which I can’t work out.

I’m on the “Using the database” chapter and I’m having issues launching the puppies application locally.

The gems I’m using are from ruby version 1.9.3-p551 as I’m not able to install the gems using ruby version 1.9.3-p194 on Mac osx as RVM seems to halt the installation process. Not sure if this is why I’m seeing the issue, but when I start the puppy application and point my browser to http://localhost:3000, I get the following error: