Sha256: 45d41018f9e880361475a7c7c0a0075c7522093a271f2c2b749b82929c2a57ae
Contents?: true
Size: 1.69 KB
Versions: 1
Compression:
Stored size: 1.69 KB
Contents
# frozen_string_literal: true # Released under the MIT License. # Copyright, 2023-2024, by Samuel Williams. require_relative 'bridge/chrome' require_relative 'bridge/firefox' require_relative 'error' module Async module WebDriver # A bridge is a process that can be used to communicate with a browser. # It is not needed in all cases, but is useful when you want to run integration tests without any external drivers/dependencies. # As starting a bridge can be slow, it is recommended to use a shared bridge when possible. module Bridge ALL = [ Bridge::Chrome, Bridge::Firefox, ] def self.each(&block) return enum_for(:each) unless block_given? ALL.each do |klass| next unless klass.new.supported? yield klass end end # The environment variable used to select a bridge. # # ``` # ASYNC_WEBDRIVER_BRIDGE=Chrome # ASYNC_WEBDRIVER_BRIDGE=Firefox # ``` ASYNC_WEBDRIVER_BRIDGE = 'ASYNC_WEBDRIVER_BRIDGE' # The environment variable used to disable headless mode. # # ``` # ASYNC_WEBDRIVER_BRIDGE_HEADLESS=false # ``` ASYNC_WEBDRIVER_BRIDGE_HEADLESS = 'ASYNC_WEBDRIVER_BRIDGE_HEADLESS' class UnsupportedError < Error end # @returns [Bridge] The default bridge to use. def self.default(env = ENV, **options) if env[ASYNC_WEBDRIVER_BRIDGE_HEADLESS] == "false" options[:headless] = false end if name = env[ASYNC_WEBDRIVER_BRIDGE] self.const_get(name).mew(**options) else ALL.each do |klass| instance = klass.new(**options) return instance if instance.supported? end raise UnsupportedError, "No supported bridge found!" end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
async-webdriver-0.5.0 | lib/async/webdriver/bridge.rb |