Class: Superbot::Capybara::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/superbot/capybara/runner.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(browser: :local, region: nil) ⇒ Runner

Returns a new instance of Runner.



8
9
10
11
# File 'lib/superbot/capybara/runner.rb', line 8

def initialize(browser: :local, region: nil)
  @browser = browser
  @region = region
end

Instance Attribute Details

#browserObject

Returns the value of attribute browser.



44
45
46
# File 'lib/superbot/capybara/runner.rb', line 44

def browser
  @browser
end

#finishedObject

Returns the value of attribute finished.



44
45
46
# File 'lib/superbot/capybara/runner.rb', line 44

def finished
  @finished
end

#regionObject

Returns the value of attribute region.



44
45
46
# File 'lib/superbot/capybara/runner.rb', line 44

def region
  @region
end

#runnerObject

Returns the value of attribute runner.



44
45
46
# File 'lib/superbot/capybara/runner.rb', line 44

def runner
  @runner
end

#scriptObject

Returns the value of attribute script.



44
45
46
# File 'lib/superbot/capybara/runner.rb', line 44

def script
  @script
end

#test_resultObject

Returns the value of attribute test_result.



44
45
46
# File 'lib/superbot/capybara/runner.rb', line 44

def test_result
  @test_result
end

Class Method Details

.run(script, browser: :local, region: nil) ⇒ Object



13
14
15
# File 'lib/superbot/capybara/runner.rb', line 13

def self.run(script, browser: :local, region: nil)
  new(browser: browser, region: region).run(script)
end

Instance Method Details

#kill_sessionObject



25
26
27
28
29
30
31
# File 'lib/superbot/capybara/runner.rb', line 25

def kill_session
  runner&.kill
rescue Timeout::Error
  p # do nothing
ensure
  @runner = nil
end

#run(script) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/superbot/capybara/runner.rb', line 17

def run(script)
  puts "Attaching to #{browser} browser..."
  create_runner
  puts "Running test..."
  runner.in.writeln({ eval: script }.to_json)
  wait_for_finish
end

#wait_for_finishObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/superbot/capybara/runner.rb', line 33

def wait_for_finish
  loop do
    if finished
      @finished = false
      break
    end

    sleep 0.1
  end
end