I started testing with Ruby. So i first use Test::Unit and then i want to test some functionality on web. I read some examples at mechanize documentation, which is here or at your ruby/gems directory. So let’s look at the code.
class LoginTest < Test::Unit::TestCase
#creating mechanize object
agent = WWW::Mechanize.new
page = agent.get(‘http://zaparka.cz/wp-login.php’)
# get first html form on page, u can use page.form(‘form_name’)
login_form = page.forms.first
#fill value <input type=”text” name=”log” /> with login name
login_form.log = ‘name’
#fill value <input name=”pwd” type=”password” /> with password
login_form.pwd = ‘secrets’
#submiting form and saving result page to value page
page = google_form.submit()
# test if login was succesflull
assert_equal ‘Dashboard ‹ Petr Zaparka — WordPress’, page.title
It’s very easy and simply. However you can’t test javasript functionality. Next time i post testing with WEBRAT.