Class: Capy::Evaluater

Inherits:
Object
  • Object
show all
Includes:
Capybara::DSL
Defined in:
lib/capy.rb

Instance Method Summary collapse

Constructor Details

#initializeEvaluater

Returns a new instance of Evaluater.



126
127
128
129
130
131
132
133
# File 'lib/capy.rb', line 126

def initialize
  if page.driver.respond_to?(:header)
    page.driver.header(
      'user-agent',
      'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.55.3 (KHTML, like Gecko) Version/5.1.5 Safari/534.55.3'
    )
  end
end

Instance Method Details

#browserObject



162
163
164
# File 'lib/capy.rb', line 162

def browser
  driver.browser
end

#capybara(script) ⇒ Object



149
150
151
# File 'lib/capy.rb', line 149

def capybara(script)
  instance_eval script
end

#driverObject



158
159
160
# File 'lib/capy.rb', line 158

def driver
  page.driver
end

#eval_script(script, mode) ⇒ Object



135
136
137
138
139
140
141
142
# File 'lib/capy.rb', line 135

def eval_script(script, mode)
  case mode
  when :javascript
    javascript script
  else
    capybara script
  end
end

#host(app_host) ⇒ Object



166
167
168
# File 'lib/capy.rb', line 166

def host(app_host)
  Capybara.app_host = app_host
end

#javascript(script) ⇒ Object Also known as: js



144
145
146
# File 'lib/capy.rb', line 144

def javascript(script)
  page.evaluate_script script.sub(/\A#!.*\n/, '')
end

#save_screenshot(png_path = nil) ⇒ Object



153
154
155
156
# File 'lib/capy.rb', line 153

def save_screenshot(png_path = nil)
  png_path = gen_uniq_file_name('png') unless png_path
  browser.save_screenshot(png_path)
end

#stopObject



170
171
172
# File 'lib/capy.rb', line 170

def stop
  Capy.start_shell(self)
end