Class: Culerity::RemoteBrowserProxy

Inherits:
RemoteObjectProxy show all
Defined in:
lib/culerity/remote_browser_proxy.rb

Instance Method Summary collapse

Methods inherited from RemoteObjectProxy

#exit, #id, #method_missing, #send_remote

Constructor Details

#initialize(io, browser_options = {}) ⇒ RemoteBrowserProxy

Returns a new instance of RemoteBrowserProxy.



4
5
6
7
8
# File 'lib/culerity/remote_browser_proxy.rb', line 4

def initialize(io, browser_options = {})
  @io = io
  @remote_object_id = "celerity".inspect
  @remote_object_id = new_browser(browser_options).inspect
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Culerity::RemoteObjectProxy

Instance Method Details

#confirm(bool, &block) ⇒ Object

Specify whether to accept or reject all confirm js dialogs for the code in the block that’s run.



47
48
49
50
51
52
53
# File 'lib/culerity/remote_browser_proxy.rb', line 47

def confirm(bool, &block)
  blk = "lambda { #{bool} }"
  
  self.send_remote(:add_listener, :confirm) { blk }
  block.call
  self.send_remote(:remove_listener, :confirm) { blk }
end

#wait_until(time_to_wait = 30, &block) ⇒ Object

Calls the block until it returns true or time_to_wait is reached. time_to_wait is 30 seconds by default

Returns true upon success Raises Timeout::Error when time_to_wait is reached.



17
18
19
20
21
22
23
24
# File 'lib/culerity/remote_browser_proxy.rb', line 17

def wait_until time_to_wait=30, &block
  Timeout.timeout(time_to_wait) do
    until block.call
      sleep 0.1
    end
  end
  true
end

#wait_while(time_to_wait = 30, &block) ⇒ Object

Calls the block until it doesn’t return true or time_to_wait is reached. time_to_wait is 30 seconds by default

Returns true upon success Raises Timeout::Error when time_to_wait is reached.



33
34
35
36
37
38
39
40
# File 'lib/culerity/remote_browser_proxy.rb', line 33

def wait_while time_to_wait=30, &block
  Timeout.timeout(time_to_wait) do
    while block.call
      sleep 0.1
    end
  end
  true
end