Created
September 24, 2012 17:41
-
-
Save jarmo/3777234 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
# open up only one browser and store it into global variable | |
RSpec.configure do |config| | |
config.before :suite do | |
$browser = Watir::Browser.new :chrome | |
Test::Page.browser = $browser | |
end | |
config.after :suite do | |
$browser.close | |
end | |
end | |
class SearchPage < Test::Page | |
# if only container for search page, keep it DRY and use lazily evaluated proc | |
container {browser.div(id: "sbox")} | |
end | |
# override container! | |
SearchPage.new $browser.div(id: "ouyeah") | |
# setup the page! Should we use instance_eval in here? | |
SearchPage.new {|page| page.browser.goto "http://bing.com"} | |
# use custom browser for our page | |
search_page = SearchPage.new {|page| page.browser = Watir::Browser.new} | |
search_page.browser # => :firefox and not :chrome instance | |
# reference to $browser is still there | |
SearchPage.new.browser # => $browser e.g. :firefox instance | |
# use custom browser with container | |
my_browser = Watir::Browser.new | |
SearchPage.new(my_browser.div(id: "ohnoes")) {|page| page.browser = my_browser} | |
# or use less parentheses | |
SearchPage.new do |page| | |
my_browser = Watir::Browser.new | |
page.browser = my_browser | |
page.container = my_browser.div(id: "ohnoes") | |
end |
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
# what about this? | |
class SearchPage < Test::Page | |
setup {browser.goto "http://bing.com"} | |
container {browser.div(id: "sbox")} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment