-
-
Save alisterscott/949623 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'watir-webdriver' # gem install watir-webdriver | |
require 'rspec' # gem install rspec | |
class BrowserContainer | |
attr_reader :browser | |
def initialize(browser) | |
@browser = browser | |
end | |
end | |
class FigureOutWhenApp < BrowserContainer | |
def calendar_name_page | |
CalendarNamePage.new(@browser) | |
end | |
def user_name_page | |
UserNamePage.new(@browser) | |
end | |
def calendar_page | |
CalendarPage.new(@browser) | |
end | |
class CalendarNamePage < BrowserContainer | |
def fill(params = {}) | |
self.name = params.fetch :name | |
continue | |
end | |
def name=(str) | |
name_field.set str | |
end | |
def continue | |
browser.button.click | |
end | |
def name_field | |
browser.text_field(:id => "calendar_name") | |
end | |
end # CalendarNamePage | |
class UserNamePage < BrowserContainer | |
def fill(params = {}) | |
self.name = params.fetch :name | |
continue | |
end | |
def name=(str) | |
name_field.set str | |
end | |
private | |
def continue | |
browser.button.click | |
end | |
def name_field | |
browser.text_field(:id => "person_name") | |
end | |
end # UserNamePage | |
class CalendarPage < BrowserContainer | |
def select_days(*days) | |
days.each do |day| | |
select_day day | |
end | |
end | |
def select_day(day) | |
browser.div(:text => day).when_present.click | |
end | |
end # CalendarPage | |
end # FigureOutWhenApp | |
describe "FigureOutWhen.com" do | |
let(:browser) { Watir::Browser.new :firefox, :profile => "default" } | |
let(:site) { FigureOutWhenApp.new(browser) } | |
before { browser.goto "http://figureoutwhen.com" } | |
after { browser.close } # comment this out to leave the browser running | |
it "should select do" do | |
site.calendar_name_page.fill :name => "lunch" | |
site.user_name_page.fill :name => "jari" | |
site.calendar_page.select_days "4", "5", "6" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment