Posts tagged cucumber
Testing for a redirect using Capybara and Selenium WebDriver
1I just spent the better part of 8 hours trying to figure out how to do this. The Selenium WebDriver API docs are pretty bewildering especially when it comes to trying to interact with the HTTP response or request itself because those constructs are abstracted quite a bit.
1 2 3 4 5 6 7 8 9 10 11 | Then /^I should be on the (.*) page$/ do |page_name| object = instance_variable_get("@#{page_name}") page.current_path.should == send("#{page_name.downcase.gsub(' ','_')}_path", object) page.status_code.should == 200 end Then /^I should be redirected to the (.*) page$/ do |page_name| page.driver.request.env['HTTP_REFERER'].should_not be_nil page.driver.request.env['HTTP_REFERER'].should_not == page.current_url step %Q(I should be on the #{page_name} page) end |
Which we can use in a Cucumber feature like so:
1 2 3 4 5 6 | Given I am on the homepage When I click on the link to add a widget Then I should be able to complete the widget form And I should be redirected to the widget page And I should see a confirmation message And I should see the widget listed |
Writing the First Cucumber Feature
0I’m currently working on my first BDD project, but after reading through the Cucumber wiki for what felt like the 100th time I was still not sure where to start. I tried generating a boilerplate feature file as the documentation suggests (even though the documentation then tries to dissuade you from taking that approach in the next paragraph), but the generated file didn’t really provide much guidance so I was back to square one. Finally I started asking for advice on the freenode #cucumber channel. It seemed like a shot in the dark, knowing that every project is different and there isn’t really a single pattern that would work for everyone. The initial responses were less than illuminating, but after a few short minutes someone offered the following advice:
1 2 3 4 5 6 7 8 9 10 11 12 | msassak: auth features are not very valuable, imo msassak: you need to do them, but i would implement almost anything first msassak: err anything else cbloom: So assume every user is registered for now. Then start hiding stuff after the other features are complete? msassak: that's what i would do cbloom: OK, that makes a lot of sense. msassak: <strong>imagine you are going to present this to someone who is going to pay you for it</strong> msassak: <strong>do they want to see that users can log in, or that users can do something cool on the site?</strong> cbloom: they want to see that users can print coupons cbloom: so I'll start with that msassak: yup, exactly cbloom: so simple, yet so abstract |
It seems so simple now. Now to see if that actually cures my writers block.