Class: WebDriverScriptAdapter::ExecEvalScriptAdapter

Inherits:
DumbDelegator
  • Object
show all
Defined in:
lib/webdriver_script_adapter/exec_eval_script_adapter.rb

Overview

Capybara distinguishes eval from exec (eval is a query, exec is a command) this decorator makes webdriver act like capybara

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.wrap(driver) ⇒ Object

Raises:



8
9
10
11
12
# File 'lib/webdriver_script_adapter/exec_eval_script_adapter.rb', line 8

def self.wrap(driver)
  raise WebDriverError, "WebDriver must respond to #execute_script" unless driver.respond_to? :execute_script

  driver.respond_to?(:evaluate_script) ? ExecEvalScriptAdapter2.new(driver) : new(driver)
end

Instance Method Details

#evaluate_script(script) ⇒ Object

returns result of executing script



21
22
23
# File 'lib/webdriver_script_adapter/exec_eval_script_adapter.rb', line 21

def evaluate_script(script)
  __getobj__.execute_script "return #{script}"
end

#execute_script(script) ⇒ Object

executes script without returning result



15
16
17
18
# File 'lib/webdriver_script_adapter/exec_eval_script_adapter.rb', line 15

def execute_script(script)
  super
  nil
end

#execute_script_fixed(script, *args) ⇒ Object



25
26
27
28
# File 'lib/webdriver_script_adapter/exec_eval_script_adapter.rb', line 25

def execute_script_fixed(script, *args)
  page = __getobj__
  page.execute_script(script, *args)
end