How to use it?

Webrat’s Core API

visit

click_link

fill_in

check and uncheck

choose

select

attach_file

click_button

Webrat works with RSpec, Shoulda and Cucumber
Webrat and cucumber do not have to be used together. You can use Webrat with whatever testing framework you want to use.
Webrat also works with Rails, Sinatra and Merb.

Webrat can do input matching to labels. Webrat encourages you to put good labels on your form fields.

When things go wrong Webrat uses ”’save_and_open_page”’ and writes out the current response body and brings up the page.

Webrat Adapters

Rails

Merb

Sinatra

Selenium

Mechanize (can use to scrape other websites i.e. google)

Evil plot is to write adapters so he can test everything at once.

Selenium

Webrat started as an alternative to selenium, but it now includes a selenium adapter. Bryan suggests not using selenium whenever possible. You should start with the traditional webrat mode and not the selenium mode. Unfortunately, it’s the only way to test a real browser, such as javascript.

# is not run in normal webrat mode
webrat.automate do
end
# is not run in selenium webrat mode
webrat.simulate do
...
end

The ‘selenium’ object is exposed from the selenium client gem. You can use it directly within your tests.

Automating a real web browser is SLOW

One more thing…

rack::test – gives you a quick way to generate requests to any rack enabled application
Makes it easy to test complicated routing of requests through rack apps. For example, a rails metal that routes to a sinatra app.

Rack::Test API

get
post, put, delete head
request
…

Questions

Q: How do you deal with links with the same names?

A: Webrat has a method called “within” which allows you to scope your selectors to be inside an HTML tag.

Q: Does it have support for checking HTML validity?

A: No, that is outside of the scope of core webrat. However, we have talked about the ability to capture

Q: Where does the output of save_and_open_page go?

A: Into Rails’ tmp directory

Q: Selenium client has some interesting screen grab is that being exposed?