Class: TouringTest::Driver
- Inherits:
-
Object
- Object
- TouringTest::Driver
- Defined in:
- lib/touring_test/driver.rb
Instance Attribute Summary collapse
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Instance Method Summary collapse
- #capture_screenshot_and_url ⇒ Object
- #execute_action(function_call) ⇒ Object
-
#initialize(session, root_path:) ⇒ Driver
constructor
A new instance of Driver.
Constructor Details
#initialize(session, root_path:) ⇒ Driver
Returns a new instance of Driver.
10 11 12 13 14 15 16 17 |
# File 'lib/touring_test/driver.rb', line 10 def initialize(session, root_path:) @session = session @screenshot_dir = File.join(root_path, "tmp", "screenshots") @screenshot_count = 0 @last_screenshot_path = nil FileUtils.mkdir_p(@screenshot_dir) FileUtils.rm_f(Dir.glob("#{@screenshot_dir}/*")) # Clear old screenshots end |
Instance Attribute Details
#session ⇒ Object (readonly)
Returns the value of attribute session.
8 9 10 |
# File 'lib/touring_test/driver.rb', line 8 def session @session end |
Instance Method Details
#capture_screenshot_and_url ⇒ Object
19 20 21 |
# File 'lib/touring_test/driver.rb', line 19 def capture_screenshot_and_url [capture_screenshot, session.current_url] end |
#execute_action(function_call) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/touring_test/driver.rb', line 23 def execute_action(function_call) action_name = function_call["name"].to_sym args = function_call["args"].transform_keys(&:to_sym) puts "[Action] #{action_name}(#{args.map { |k, v| "#{k}: #{v.inspect}" }.join(', ')})" if respond_to?(action_name, true) send(action_name, **args) else raise "Unknown action: #{action_name}" end end |