Class: TouringTest::Driver

Inherits:
Object
  • Object
show all
Defined in:
lib/touring_test/driver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#sessionObject (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_urlObject



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