开发者

Using click_link with Cucumber Scenario

开发者 https://www.devze.com 2023-03-11 08:12 出处:网络
I have the following Feature file which is attempting to visit a page, select a link then edit user data.

I have the following Feature file which is attempting to visit a page, select a link then edit user data.

Scenario: Edi开发者_JS百科t an existing member of the club
    Given I go to the member list page
    And I choose the first item
    And I fill in the "First Name" with "Bloggs
    When I press "Update"
    Then I should be on the member list page
    And I should see "Bloggs"

and the member_step.rb file contains

Given /^I choose the first item$/ do
    #save_and_open_page
    visit members_path
    click_link "1"
end

My routes.rb file has

Gfs::Application.routes.draw do
   resources :members
end

The problem is that I can't get the click_link "1" step to work. The intention is that it will

  1. Navigate to the '/members' index page
  2. The index page displays a list of users each prefixed with a number, that is the link.
  3. Select the link

What I know is that the index page does display a list, my route works ('/members), but my Cucumber is failing and I'm not basking in the glory of green.

The save_and_open_page diagnostic shows only the title of the index page and not the details, as though the controller is not accessing the data

Suggestions are most welcome.


Is there a Background where you create the members data? If not, it may be that the data does not exist.

I'd also suggest adding a step like

And I should not see "Bloggs"

before you update the record.


If I understood your cuke correctly, you really won't see the "1" link because:

Given I go to the member list page <-- first step
And I choose the first item <-- second step

...which expands to:

Given I go to the member list page <-- first step
visit members_path
click_link "1"

why are you visiting the member's path after you just visited the member list page? you should be checking that you ARE in the member's path. Something like:


Given I have existing users(generate members here using factory or whatever)
And I go to the member list page( go to member page)
When I follow "1" (click the first member)
Then I should be on the "1"'s member page
When I fill in...etc you get the point

Hope that helps!


I'm going to suggest that IFF the "1" is a true html anchor link, then you might consider using

And I follow "1"

You could easily wrap this in your own syntax to make it more aesthetically pleasing but the And I follow... step is one that you get out of the box in web_steps.rb.

Another gain in using that one is that you can use a selector to make the click more specific:

And I follow "1" within ".my-kickbutt-div"

Or something along those lines.

Another thing to check into. If you have @javascript enabled you might be seeing incorrect data in your save_and_open_page. My app is javascript/ajax heavy and I have to open the output in a browser with javascript turned off to see what is really visible there :P This might not be your issue, but just in case...

0

精彩评论

暂无评论...
验证码 换一张
取 消