Need help with the Adopting two Puppies with Cucumber implementations

155 views
Skip to first unread message

Shartul Kumar

unread,
Aug 19, 2013, 1:48:06 PM8/19/13
to cucumber-...@googlegroups.com

Hi,


Feature file:

Feature: Adopting  two puppies

As a puppy lover
I want to adopt puppies
So they can chew my furniture

Scenario: Adopting two puppies
Given I am on the puppy adoption site
When I click the first View Details button
And I click the Adopt Me button first
And I click the Adopt Another Puppy button
And I click the second View Details button
And I click the Adopt Me button second
And I click the Complete the Adoption button
And I enter "Cheezy" in the name field
And I enter "123 Main Street" in the address field
And I enter "che...@example.com" in the email field
And I select "Credit card" from the pay with dropdown
And I click the Place Order button
Then I should see "Thank you for adopting a puppy!"



Step definition:


Given(/^I am on the puppy adoption site$/) do
  @browser.goto "http://puppies.herokuapp.com"
end


When(/^I click the first View Details button$/) do
  @browser.button(:value => "View Details").click
end


And(/^I click the Adopt Me button first$/) do
  @browser.button(:value => "Adopt Me!").click
end


And(/^I click the Adopt Another Puppy button$/) do
  @browser.button(:value => "Complete the Adoption").click
end


And(/^I click the second View Details button$/) do
  @browser.button(:value => "Complete the Adoption").click
end


And(/^I click the Adopt Me button second$/) do
  @browser.button(:value => "Adopt Me!").click
end

And(/^I click the Complete the Adoption button$/) do                                                                      And(/^I enter "(.*?)" in the name field$/) do |arg1|
  @browser.button(:value => "Complete the Adoption").click
end


When(/^I enter "([^\"]*)" in the name field$/) do |name|
 @browser.text_field(:id => "order_name").set(name)
end



And(/^I enter "([^\"]*)" in the address field$/) do |adress|
  @browser.text_field(:id => "order_address").set(address)
end



And(/^I enter "([^\"]*)" in the email field$/) do |email|
  @browser.text_field(:id => "order_email").set(email)
end



And(/^I select "(.*?)" from the pay with dropdown$/) do |pay_type|
  @browser.select_list(:id => "order_pay_type").select(pay_type)
end


And(/^I click the Place Order button$/) do
  @browser.button(:value => "Place Order").click
end


Then /^I should see "([^\"]*)" $/ do |expected|
  @browser.text.should include expected
end






Following is the error:

C:\Ruby193\bin\ruby.exe -EUTF-8 -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:\Ruby193\bin/cucumber C:/RubymineProjects/test_puppies/features/adopting_two_puppies.feature --format Teamcity::Cucumber::Formatter --expand --color -r features
Testing started at 2:26 AM ...
C:/RubymineProjects/test_puppies/features/step_definitions/adopting_two_puppies.rb:66: syntax error, unexpected $end, expecting keyword_end (SyntaxError)
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.6/lib/cucumber/rb_support/rb_language.rb:122:in `load'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.6/lib/cucumber/rb_support/rb_language.rb:122:in `load_code_file'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.6/lib/cucumber/runtime/support_code.rb:180:in `load_file'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.6/lib/cucumber/runtime/support_code.rb:83:in `block in load_files!'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.6/lib/cucumber/runtime/support_code.rb:82:in `each'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.6/lib/cucumber/runtime/support_code.rb:82:in `load_files!'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.6/lib/cucumber/runtime.rb:183:in `load_step_definitions'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.6/lib/cucumber/runtime.rb:42:in `run!'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.6/lib/cucumber/cli/main.rb:47:in `execute!'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.6/bin/cucumber:13:in `<top (required)>'
C:/Ruby193/bin/cucumber:23:in `load'
C:/Ruby193/bin/cucumber:23:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'

Process finished with exit code 1


Please let me know what am I doing wrong. How should I bold statements in the feature file and accordingly.

I didn't get the thing suggested in the book on Page number  50 in the following paragraph.

"Go ahead and generate the step definition and implement the methods. As you see, we were able to
reuse much of the previous step definitions in this new Scenario. The two steps that we did have to
create were the ones that clicked the first and second view details buttons. We already had a step in
the first Scenario that clicked the first view details button. When we see this sort of duplication it is
a good idea to remove it. Please change the first scenario to use the step When I click the first View
Details button and then remove the step definition for the generic method so it no longer exists in
your step definition file."



Regards,
Shartul

Rob Park

unread,
Aug 19, 2013, 3:38:56 PM8/19/13
to cucumber-...@googlegroups.com
Sorry, don't know why the reply went direct instead of to the list. :-(

---------- Forwarded message ----------
From: Rob Park <robert...@gmail.com>
Date: Mon, Aug 19, 2013 at 3:37 PM
Subject: Re: Need help with the Adopting two Puppies with Cucumber implementations
To: Shartul Kumar <shartu...@gmail.com>





As for the stack trace, there is one somewhat obvious typo in there that appears to be a copy/paste issue although perhaps that was just to the post?

More importantly, what have you tried to find your problem? Have you tried commenting out chunks of your steps to find the error? 

Rob Park

unread,
Aug 19, 2013, 4:46:31 PM8/19/13
to cucumber-...@googlegroups.com



On Mon, Aug 19, 2013 at 4:29 PM, Shartul <shartu...@gmail.com> wrote:
Hi Rob,

thanks for the replying, still could not resolve the issue.

a) If you have the book then on page number 50 where it has been said to do some changes in the step definitions as following. I didn't get this

------------------------------------
"Go ahead and generate the step definition and implement the methods. As you see, we were able to
reuse much of the previous step definitions in this new Scenario. The two steps that we did have to
create were the ones that clicked the first and second view details buttons. We already had a step in
the first Scenario that clicked the first view details button. When we see this sort of duplication it is
a good idea to remove it. Please change the first scenario to use the step When I click the first View
Details button and then remove the step definition for the generic method so it no longer exists in
your step definition file."

------------------------------------


b)Therefore,  I have used "first" and "second" text to differ the same step for clicking of Adopt Me buttons.

c) What is wrong with the step definitions in the earlier first post.

This is the one I was addressing.
I believe you have a typo in your steps.
Try commenting in/out steps and rerunning until you find your error.
The stack trace is a hint that it's an unmatched do/end pair. 

d) Can someone provide me a correct step definitions file for adopting two puppies as described on page 50.



 

Regards,
Shartul



Regards
Shartul Kumar
 
 


On Tue, Aug 20, 2013 at 1:07 AM, Rob Park <robert...@gmail.com> wrote:




On Mon, Aug 19, 2013 at 1:48 PM, Shartul Kumar <shartu...@gmail.com> wrote:
As for the stack trace, there is one somewhat obvious typo in there that appears to be a copy/paste issue although perhaps that was just to the post?

More importantly, what have you tried to find your problem? Have you tried commenting out chunks of your steps to find the error? 
I didn't get the thing suggested in the book on Page number  50 in the following paragraph.

"Go ahead and generate the step definition and implement the methods. As you see, we were able to
reuse much of the previous step definitions in this new Scenario. The two steps that we did have to
create were the ones that clicked the first and second view details buttons. We already had a step in
the first Scenario that clicked the first view details button. When we see this sort of duplication it is
a good idea to remove it. Please change the first scenario to use the step When I click the first View
Details button and then remove the step definition for the generic method so it no longer exists in
your step definition file."



Regards,
Shartul




Shartul Kumar

unread,
Sep 11, 2013, 2:51:49 PM9/11/13
to cucumber-...@googlegroups.com
Can somebody please post the step definitions file for feature file at page number 50. ?

I am stuck and not able to move ahead. Since, am learning, it is difficult


Regards,
Shartul

Shartul

unread,
Sep 11, 2013, 3:02:34 PM9/11/13
to cucumber-...@googlegroups.com
This is my step definition



Given(/^I am on the puppy adoption site$/) do
  @browser.goto "http://puppies.herokuapp.com"
end


When(/^I click the first View Details button$/) do
  @browser.button(:value => "View Details", :index => "1").click
end


And(/^I click the Adopt Me button $/) do

  @browser.button(:value => "Adopt Me!").click
end


And(/^I click the Adopt Another Puppy button$/) do
  @browser.button(:value => "Complete the Adoption").click
end


And(/^I click the  second View Details button$/) do
  @browser.button(:value => "View Details", :index => "2").click
  end



Error received in console:


TypeError: expected Fixnum, got "1":String
./features/step_definitions/adopting_two_puppies.rb:8:in `/^I click the first View Details button$/'
C:\RubymineProjects\test_puppies\features\adopting_two_puppies.feature:9:in `When I click the first View Details button'



Regards
Shartul Kumar
 
 

Michael Stamps

unread,
Sep 11, 2013, 6:37:38 PM9/11/13
to cucumber-...@googlegroups.com
Take the quotes off the index values (also, they should be 0 and 1, not 1 and 2)  see below:

When(/^I click the first View Details button$/) do
  @browser.button(:value => "View Details", :index => 0).click
end

And(/^I click the  second View Details button$/) do
  @browser.button(:value => "View Details", :index => 1).click
end

Reply all
Reply to author
Forward
0 new messages