Skip to content

Instantly share code, notes, and snippets.

@davidmweber
Created November 2, 2012 15:48
Show Gist options
  • Save davidmweber/4002159 to your computer and use it in GitHub Desktop.
Save davidmweber/4002159 to your computer and use it in GitHub Desktop.
Ruby REST and browser based web test example
#!/usr/bin/ruby
#
# Requires that you have installed the following gem packages:
# json, minitest, watir, watir-webdrive, rest-client
# To use Chrome, you need to install chromedriver on your path
#
# You can use cucumber instead of minitest. There are also other REST clients for Ruby
#
require 'rubygems'
require 'rest-client'
require 'json'
require 'pp'
require 'minitest/autorun'
require 'watir'
require 'watir-webdriver'
class TestReportSystem < MiniTest::Unit::TestCase
def setup
@browser = Watir::Browser.new :chrome # Defaults to firefox. Can do Safari and IE too.
# Log in here.....
end
def teardown
@browser.close
end
def test_report_lists # For minitest, the method names need to start with test
response = RestClient.get 'http://localhost:8080/reporter/reports/getReportList'
assert_equal response.code,200
parsed = JSON.parse response.to_str
assert_equal parsed.length, 3
end
def test_on_browser
@browser.goto 'http://localhost:8080/reporter/exampleReport/simple/genReport?month=Aug&year=2012'
assert(@browser.text.include?('Report for Aug 2012'))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment