Sha256: a127d4ae6f3b655b9cc287023250633206ce88dff234ec96456252d04278166a

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module WatirSpec
  class RemoteServer
    include Watir::Exception

    attr_reader :server

    def start(port = 4444, args: [])
      require 'selenium/server'

      @server ||= Selenium::Server.new(jar,
                                       port: Selenium::WebDriver::PortProber.above(port),
                                       log: !!$DEBUG,
                                       background: true,
                                       timeout: 60)
      args.each { |arg| @server << arg }
      @server.start
      at_exit { @server.stop }
    end

    private

    def jar
      if File.exist?(ENV['REMOTE_SERVER_BINARY'] || '')
        ENV.fetch('REMOTE_SERVER_BINARY', nil)
      elsif ENV['LOCAL_SELENIUM']
        File.expand_path('../selenium/bazel-bin/java/server/src/org/openqa/selenium/grid/selenium_server_deploy.jar')
      elsif !Dir.glob('*selenium*.jar').empty?
        Dir.glob('*selenium*.jar').first
      else
        Selenium::Server.download
      end
    rescue SocketError
      # not connected to internet
      raise Error, 'unable to find or download selenium-server jar'
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
watir-7.3.0 lib/watirspec/remote_server.rb
watir-7.2.2 lib/watirspec/remote_server.rb
watir-7.2.1 lib/watirspec/remote_server.rb
watir-7.2.0 lib/watirspec/remote_server.rb