Class: Common::DSL::Browser

Inherits:
Watir::Browser
  • Object
show all
Defined in:
lib/spider_rails/common/dsl.rb

Overview

Add a visit method to ::Watir::Browser

Instance Method Summary collapse

Constructor Details

#initialize(browser = :phantomjs, *args) ⇒ Browser

Returns a new instance of Browser.



11
12
13
# File 'lib/spider_rails/common/dsl.rb', line 11

def initialize(browser = :phantomjs, *args)
  super
end

Instance Method Details

#dsl_enableObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/spider_rails/common/dsl.rb', line 15

def dsl_enable
  @doc = Nokogiri::HTML.parse(self.html)
  ::String.class_variable_set(:@@doc, @doc)
  eval <<-RUBY
class ::String
  def ctn
    if block_given?
      @@doc.css(self) &block
    else
      @@doc.css(self).each do |e|
        return e.text
      end
    end
  end
end
  RUBY
end

#visit(relative_url = nil, base_url = 'http://localhost:3000/') ⇒ Object



7
8
9
# File 'lib/spider_rails/common/dsl.rb', line 7

def visit(relative_url = nil, base_url = 'http://localhost:3000/')
  goto("#{base_url}#{relative_url}")
end