# frozen_string_literal: true module Wayfarer module Networking class Selenium include Strategy MOCK_STATUS_CODE = 200 MOCK_RESPONSE_HEADERS = {}.freeze def create ::Selenium::WebDriver.for(Wayfarer.config[:selenium][:driver], **options) end def destroy(instance) instance.quit end def navigate(instance, url) instance.navigate.to(url) end def live(instance) success(url: instance.current_url, body: instance.page_source, status_code: MOCK_STATUS_CODE, headers: MOCK_RESPONSE_HEADERS) end private def options Wayfarer.config[:selenium][:options].merge(http_client: http_client) end def http_client ::Selenium::WebDriver::Remote::Http::Default.new.tap do |client| client.read_timeout = Wayfarer.config[:selenium][:client_timeout] end end end end end