> ok, much simpler solution. Apologies for all the posts, still
> learning here:
>
> Then /^the element "([^"]*)" should exist$/ do |element|
> response.should have_selector(element)
> end
>
> Then /^the element "([^"]*)" should not exist$/ do |element|
> response.should_not have_selector(element)
> end
>
>
Is this the abstraction level in your steps? It sounds kind of nerdy
and elaborate ;-)
How about Then I should see "OMFG"
Using Gherkin as a dumb api-to-human translator leads to test scripts
(features and scenarios) that are not only horrible to read (and
type), but also very hard to maintain, as a minor CSS tweak now fails
half of your cukes.
Aslak
>
> On Dec 12, 3:02 pm, Nellboy <nell...@gmail.com> wrote:
>> Just as I posted, I found this:
>>
>> http://makandra.com/notes/831-test-that-a-css-selector-is-present-wit...
>>
>> is this the best possible way?
>>
>> cheers
>>
>> Paul
>>
>> On Dec 12, 3:00 pm, Nellboy <nell...@gmail.com> wrote:
>>
>>
>>
>>
>>
>>
>>
>>> Hi
>>
>>> I would like to test the existence of an element on the page ...
>>
>>> e.g:
>>
>>> Then the element ".form" should exist
>>
>>> could anyone point me in the right direction ?
>>
>>> thanks
>>
>>> Paul
>
> --
> You received this message because you are subscribed to the Google Groups "Cukes" group.
> To post to this group, send email to cu...@googlegroups.com.
> To unsubscribe from this group, send email to cukes+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
>
For Capybara, the guts of the step definition would look like:page.should have_css(".form")Like Chuck says, it depends on the technology you're using to interact with the Web.Cucumber itself doesn't know anything about web pages, HTML or selectors. For that, you'll want software like Capybara or WebRat. I like Capybara.Like Aslak says, Cucumber is just there as thin translation layer between your specific domain language and Ruby code.The feature side should use language like:When I place an order for "My First e-Book"Then the shipping charge on my order should be $0.00It's the step definition's job to define these human steps in terms of selectors, events and HTML assertions.It takes some time to get used to, and there are a lot of bad examples out there -- the web_steps that the cucumber-rails bridge generates are famous for setting people off in the wrong direction.
Not really - they are both equally bad.
> this is contained within web_steps.rb for cucumber with Rails. People far
> more experienced in these matters than me wrote this, so I'm not going to
> question it.
How embarassing, I apologise. Maybe I've been too liberal accepting
patches. Or maybe I realised how bad this is after I accepted it,
that's more likely.
Anyway, I'll yank it from a future release so people don't get tempted
to write CSS selectors in their features (what a crazy idea). There is
a patch floating around that allows you to map a "named" UI element to
a selector. -Similar to how we refer to pages in When /I go to (.*)/.