Sha256: 5aa8a19504e9edb3317696701081dbbcd1ca29642edee45747aa4fb41afbaac4

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

module Pages
  class BasePage
    include PageHelper

    def initialize(browser)
      @browser = browser
    end

    def self.url(url)
      define_method("url") do
        if url.is_a?(Hash)
          build_url(url)
        else
          url
        end
      end
    end

    def method_missing(sym, *args, &block)
      @browser.send(sym, *args, &block)
    end

    def goto
      @browser.goto(self.url)
      self
    end

    private
    def build_url(options={})
      path     = options[:path] || ''
      port     = options[:port] || ENV['PORT'] || '9292'
      password = options[:basic_auth_password] || ENV['BASIC_AUTH_PASSWORD']
      hostname = options[:hostname] || ENV['HOSTNAME'] || "localhost"
      protocol = options[:protocol] || 'http'

      user     = options[:basic_auth_user] || ENV['BASIC_AUTH_USER']
      password = options[:basic_auth_password]
      basic_auth = user && password ? "#{user}:#{password}" : nil

      url =  "#{protocol}://"
      url += "#{basic_auth}@" if basic_auth
      url += "#{hostname}"
      port ? url += ":#{port}/" : url += "/"
      if path
        url += "/" if url[-1] != "/" && path[0] != "/"
        url += path
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
watir_setup-0.0.2 lib/watir_setup/base_page.rb
watir_setup-0.0.1 lib/watir_setup/base_page.rb