teamcapybara / capybara

Acceptance test framework for web applications
http://teamcapybara.github.io/capybara/
MIT License
9.97k stars 1.44k forks source link

"within" executing within ALL found instances of the selector #174

Closed netizer closed 13 years ago

netizer commented 13 years ago

I found that in version "0.4.0.rc" "within" method changed and now executes within first instance of the selector, not in all of them. This function was changed a lot of times in this release, and I couldn't find the right commit, but why behavior of this function was changed?

In some situations it introduced few complications. For example here:

Fax / Phone

    <div><label>Phone</label><span>0-12 345-678-90</span></div>
    <div><label>Fax</label><span>0-12 345-678-90</span></div>
    <div><label>Mobile</label><span>0-12 345-678-90</span></div>

I would check existance of word "Fax" with this step: Then I should see "Fax" within "label" Before, it worked, but now only first label is checked.

Or in this situation:

    <h1>Names:</h1>
    <ul>
    <li class="letter">A</li>
    <li>Adam</li>
    <li>Ann</li>
    <li class="letter">B</li>
    <li>Barbara</li>
    </ul>

I would check if letters are shown with the following steps Then I should see "A" within ".letter" And I should see "B" within ".letter" After release of "0.4.0.rc" second step will fail.

jnicklas commented 13 years ago

This is a documented change, which is in the History file and the release notes for Capybara 0.4.0. It's not like this is a regressions, it was a conscious choice to change the behaviour this way. There are better ways for achieving the things you want to achieve, don't depend on the default cucumber web steps, they suck anyway. Something like:

page.should have_css('.letter', :text => 'A')

would work perfectly fine for the second example, for instance. within is supposed to be used for restricting actions to one specific area of the page. Stuff like a row in a table, the sidebar, the footer, a particular list item, that kind of thing. I think that using within to refer to multiple elements on the page is a misuse of its intended function.

I'm closing this issue, since it definitely is not a regression, if you want to take this discussion further, please post to the mailing list.