Class: RainforestRubyRuntime::Runner
- Inherits:
-
Object
- Object
- RainforestRubyRuntime::Runner
- Defined in:
- lib/rainforest_ruby_runtime/runner.rb
Constant Summary collapse
- FAILURE_EXCEPTIONS =
[ RSpec::Expectations::ExpectationNotMetError, ::ElementNotFound, ].freeze
Instance Attribute Summary collapse
-
#config_options ⇒ Object
readonly
Returns the value of attribute config_options.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #current_browser ⇒ Object
- #driver ⇒ Object
- #extract_results(code, fake_session_id: nil) ⇒ Object
-
#initialize(options = {}) ⇒ Runner
constructor
A new instance of Runner.
- #run(code) ⇒ Object
- #session_id ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Runner
Returns a new instance of Runner.
10 11 12 13 14 15 |
# File 'lib/rainforest_ruby_runtime/runner.rb', line 10 def initialize( = {}) = .dup.freeze @step_variables = [:step_variables] @callback = NilDelegator.new(.fetch(:callback) { Empty.new }) @logger = .fetch(:logger) { Logger.new(StringIO.new) } end |
Instance Attribute Details
#config_options ⇒ Object (readonly)
Returns the value of attribute config_options.
3 4 5 |
# File 'lib/rainforest_ruby_runtime/runner.rb', line 3 def end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
3 4 5 |
# File 'lib/rainforest_ruby_runtime/runner.rb', line 3 def logger @logger end |
Instance Method Details
#current_browser ⇒ Object
75 76 77 |
# File 'lib/rainforest_ruby_runtime/runner.rb', line 75 def current_browser current_driver.browser end |
#driver ⇒ Object
71 72 73 |
# File 'lib/rainforest_ruby_runtime/runner.rb', line 71 def driver ENV.fetch("CAPYBARA_DRIVER") { "selenium" } end |
#extract_results(code, fake_session_id: nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rainforest_ruby_runtime/runner.rb', line 38 def extract_results(code, fake_session_id: nil) stdout = stderr = nil payload = nil begin stdout, stderr = capture_output2 do run(code) end rescue *FAILURE_EXCEPTIONS => e payload = exception_to_payload e, status: 'failed' rescue StandardError => e payload = exception_to_payload e, status: 'error' rescue SyntaxError, Exception => e payload = exception_to_payload e, status: 'fatal_error' end payload ||= { status: 'passed' } sid = fake_session_id || session_id payload = payload.merge({ stdout: stdout, stderr: stderr, session_id: sid, driver: driver, }) logger.debug("Payload") logger.debug(payload.inspect) payload end |
#run(code) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rainforest_ruby_runtime/runner.rb', line 17 def run(code) logger.debug "Running code:\n#{code}\nDriver: #{driver}" .default_driver = :"#{driver}" .default_max_wait_time = wait_time apply_config! setup_scope_registery! dsl = RainforestRubyRuntime::DSL.new(callback: @callback) test = dsl.run_code(code) if Test === test test.run else raise WrongReturnValueError, test end test ensure terminate_session! end |
#session_id ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/rainforest_ruby_runtime/runner.rb', line 79 def session_id current_browser.session_id if current_driver.browser.respond_to?(:session_id) rescue Selenium::WebDriver::Error::WebDriverError => e logger.error "Can't retrieve session id" logger.error "#{e.class} #{e.message}\n#{e.backtrace.join("\n")}" nil end |