Skip to content

Instantly share code, notes, and snippets.

@DVG
Created December 13, 2013 16:32
Show Gist options
  • Save DVG/7946970 to your computer and use it in GitHub Desktop.
Save DVG/7946970 to your computer and use it in GitHub Desktop.
Super simple page object pattern
require 'capybara'
require 'capybara/dsl'
include Capybara::DSL
Capybara.default_driver = :selenium
Capybara.run_server = false
# Keep selenium happy behind the proxy
ENV['no_proxy'] = "127.0.0.1"
ENV['NO_PROXY'] = "127.0.0.1"
module BradleyPageObject
include Capybara::DSL
module ClassMethods
def link(name, *args)
define_method(name) { find_link *args }
define_method("click_#{name}".to_sym) { click_link *args }
end
def text_box(name, *args)
define_method(name) { find *args }
define_method("fill_in_#{name}".to_sym) { |options| fill_in *args, :with => options[:with] }
end
end
def self.included(base)
base.extend(ClassMethods)
end
end
class AmazonHomePage
include BradleyPageObject
link(:brand, 'nav-logo')
text_box(:search, 'twotabsearchtextbox')
def go_home
click_brand
end
def search_for(term)
fill_in_search with: term
end
end
visit('http://www.amazon.com')
home_page = AmazonHomePage.new
home_page.go_home
home_page.search_for "LEGO Marvel Super Heroes"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment