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
- BROWSERS =
%w(chrome firefox ie edge safari).freeze
Instance Attribute Summary collapse
-
#browser ⇒ Object
Returns the value of attribute browser.
-
#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_klass ⇒ Object
- #driver_type ⇒ Object
-
#initialize(options = {}) ⇒ Runner
constructor
A new instance of Runner.
- #run(codes) ⇒ Object
- #run_rspec(describe) ⇒ Object
- #session_id ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Runner
Returns a new instance of Runner.
13 14 15 16 17 18 |
# File 'lib/rainforest_ruby_runtime/runner.rb', line 13 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
#browser ⇒ Object
Returns the value of attribute browser.
4 5 6 |
# File 'lib/rainforest_ruby_runtime/runner.rb', line 4 def browser @browser end |
#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
69 70 71 |
# File 'lib/rainforest_ruby_runtime/runner.rb', line 69 def current_browser current_driver.browser end |
#driver_klass ⇒ Object
62 63 64 65 66 67 |
# File 'lib/rainforest_ruby_runtime/runner.rb', line 62 def driver_klass { 'selenium' => Drivers::Selenium, 'sauce' => Drivers::Sauce, }.fetch(driver_type) end |
#driver_type ⇒ Object
58 59 60 |
# File 'lib/rainforest_ruby_runtime/runner.rb', line 58 def driver_type ENV.fetch("CAPYBARA_DRIVER") { "selenium" } end |
#run(codes) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rainforest_ruby_runtime/runner.rb', line 20 def run(codes) logger.debug "Running code:\n#{codes.join('\n')}\nDriver: #{driver_type}" .default_driver = :"#{driver_type}" .default_max_wait_time = wait_time setup_scope_registry! dsl = RainforestRubyRuntime::DSL.new(callback: @callback) tests = codes.map { |code| dsl.run_code(code) } if tests.all? { |test| test.is_a?(Test) } describe = driver_klass.new().to_rspec(tests) run_rspec(describe) else raise WrongReturnValueError, tests.reject { |test| test.is_a?(Test) } end tests ensure terminate_session! end |
#run_rspec(describe) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rainforest_ruby_runtime/runner.rb', line 41 def run_rspec(describe) if ENV['RUNTIME_ENV'] == 'test' && ENV['SHOW_OUTPUT'] != 'true' # if we're in tests, don't mix output from here with tests output # and don't include this describe block in the test count describe.run RSpec.world.example_groups.pop else RSpec.configure do |config| config.color = true config.formatter = :documentation end RSpec.configuration.reporter.report(RSpec.world.example_count([describe])) do |reporter| describe.run(reporter) end end end |
#session_id ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/rainforest_ruby_runtime/runner.rb', line 73 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 |