If you prefer writing integration tests in ruby instead of Cucumber's plain english, consider interacting with Webrat directly as I show in this episode.
Great screencast, Ryan! Thanks for covering Webrat.
For anyone interested in Webrat's Selenium support... grab the 0.4.4 gem I just released (once it's made it to the gem mirrors, or directly from git).
Fixed a couple bugs and added much better output to explain what's going on in that mode. I'll do a write up on my blog on how to run the example from this screencast in Selenium ASAP.
Hi Ryan,
Great screencast as usual. I just happened to notice that in the portion for test_helper.rb where you add the webrat configure command, you miss to highlight the point that a line for require 'webrat' needs to be added to the top of the file as well. Some users can get confused when they run rake test:integration and get an error as it cannot find Webrat. Hope it helps.
@Rupak, webrat should already be required by the config.gem line in the test.rb environment file which is why I didn't need to require it at the top of the test_helper.rb. Did that not work for you?
First off you are really helping people adopt rails.
Excellent work, really. thanks !
Couple of questions.
when you do script/console and modified a model,
1) why don't you have to do a model.save to apply the updates to the database. Looks like it does that automatically. why ?
2) i see you do model.build how is it different from model.save or model.new ?
After showing the Cucumber and raw webrat approaches for integration tests... I think it would be GREAT if you can screencast Stories, the minimalistic integration testing framework announced recently.
I think it fits all those people who think Cucumber is too much, but love Cucumber's plain english output and webrat. Take a look over here:
how can i click a button when dialog shows during test? example: when deleting element dialog shows to confirm this action, is it possible to test it with webrat? if yes, how?
Thanks Ryan for the railscast. I am a beginner to Webrat. I tried out the step you showed in it, but i am getting an error
undefined method `title' for #<ActionView::Base:0x49390c8>
Extracted source (around line #1):
1: <% title "Log in" %>
2:
3: <p>Don't have an account? <%= link_to "Sign up!", signup_path %></p>
4:
Please let me know where the issue is. I would greatly appreciate your help.
Thanks for this screencast! By the way, I tried to modify the tests so that they check for a redirect after logging in. So I used assert_redirected_to .... But now I get an error saying there was no expected redirect and just a 200 status code. Argh!!! This sucks! I want to use assert_redirected_to but I can't because something gets broke when you mix Webrat with Rspec!!! Any ideas??
Thanks Ryan, I didn't realize it was so easy to use webrat on its own!
oh and ... "dealing directly with Webrat through ruby" ... 6:37 and 6:56 ... its looping through my brain now and won't stop.
I've had the same issues getting mechanize and selenium to work. I still won't give up on webrat. Bryan has done a great job with this tool.
After last weeks episode, I was curious about Webrat and now you have answered my questions!
Too...many...testing...frameworks!!
(hence no tests)
Just passing on a note of thanks for all these great screencasts. I watch them every week and have learned a ton.
Please continue with these testing screencasts.
Thanks :-)
Great screencast, Ryan! Thanks for covering Webrat.
For anyone interested in Webrat's Selenium support... grab the 0.4.4 gem I just released (once it's made it to the gem mirrors, or directly from git).
Fixed a couple bugs and added much better output to explain what's going on in that mode. I'll do a write up on my blog on how to run the example from this screencast in Selenium ASAP.
Cheers,
-Bryan
As promised, here are instructions for running those exact same tests with Webrat's Selenium mode:
http://www.brynary.com/2009/4/6/switching-webrat-to-selenium-mode
Thanks for providing those instructions Bryan! I'll link to them in the show notes for the episode.
Hi Ryan,
Great screencast as usual. I just happened to notice that in the portion for test_helper.rb where you add the webrat configure command, you miss to highlight the point that a line for require 'webrat' needs to be added to the top of the file as well. Some users can get confused when they run rake test:integration and get an error as it cannot find Webrat. Hope it helps.
Thanks,
Rupak Ganguly
keep it up.
For those on Linux using FF 3 (Selenium mode) -
config.selenium_browser_key =
'*firefox3 /opt/firefox/firefox-bin'
binary path may vary, space is required.
@Rupak, webrat should already be required by the config.gem line in the test.rb environment file which is why I didn't need to require it at the top of the test_helper.rb. Did that not work for you?
I've been trying to get this to work but every time I try to run the test I get `test': wrong number of arguments (1 for 2) (ArgumentError).
I copied the tests from the episode so that I would have a starting point so there are no typos. I'm lost on this one.
@Jacob, interesting. Are you using the latest version of Rails? Do you have any other testing plugins installed which may be interfering with this?
Thanks again for showing webrat! We just started with Cucumber, but this is easier!
First off you are really helping people adopt rails.
Excellent work, really. thanks !
Couple of questions.
when you do script/console and modified a model,
1) why don't you have to do a model.save to apply the updates to the database. Looks like it does that automatically. why ?
2) i see you do model.build how is it different from model.save or model.new ?
thanks again.
I can´t install webrat. I always get this error
In file included from ./html_document.h:4,
from html_document.c:1:
./native.h:11:28: error: libxml/xmlsave.h: No such file or directory
Any idea?
what do i need to pass in "visit '/'" to access a page with basic_http_authentication?
i couldn't find anything on the web...
Hi, thanks for the screencast.
The only issue I am having is with the Xpaths.
I would like to test if a page has certain title, this wont't work:
response.should have_xpath("//title{#{my_title}}")
Hi Ryan, thanks again for a great screencast. What do you prefer, webrat och cucumber for integration tests?
After showing the Cucumber and raw webrat approaches for integration tests... I think it would be GREAT if you can screencast Stories, the minimalistic integration testing framework announced recently.
I think it fits all those people who think Cucumber is too much, but love Cucumber's plain english output and webrat. Take a look over here:
http://blog.citrusbyte.com/2009/05/20/stories/
how can i click a button when dialog shows during test? example: when deleting element dialog shows to confirm this action, is it possible to test it with webrat? if yes, how?
Webrat is the best!!!
Is it possible to have webrat check for things in the popup after you click on a link?
Good work! I will use it in my project.
Webrat does not currently allow use of xpath, but there is a small patch to allow this at:
https://webrat.lighthouseapp.com/projects/10503-webrat/tickets/153-within-should-support-xpath
Asciicasts are great, but in this instance it is out of step. Quite different from the screencast.
Thanks Ryan for the railscast. I am a beginner to Webrat. I tried out the step you showed in it, but i am getting an error
undefined method `title' for #<ActionView::Base:0x49390c8>
Extracted source (around line #1):
1: <% title "Log in" %>
2:
3: <p>Don't have an account? <%= link_to "Sign up!", signup_path %></p>
4:
Please let me know where the issue is. I would greatly appreciate your help.
Thanks for this screencast! By the way, I tried to modify the tests so that they check for a redirect after logging in. So I used assert_redirected_to .... But now I get an error saying there was no expected redirect and just a 200 status code. Argh!!! This sucks! I want to use assert_redirected_to but I can't because something gets broke when you mix Webrat with Rspec!!! Any ideas??
Holy cow, I was wondering *yesterday evening* when will you release a jQuery railscast, and voilà! Railscasts make Monday mornings enjoyable again :-)
@AJ - Rails is looking for the layout that nifty_scaffold generated. Try "script/generate nifty_layout".
so far no issues and errors experienced. much easier than cucumber. thanks for this easy to follow tutorials and instructions.
I've never thought of that. Thanks for sharing.
- http://number1papers.com