Skip to content

Commit 4bf985a

Browse files
committed
rb: Refactor IE server to use shared service class
1 parent c64a624 commit 4bf985a

File tree

4 files changed

+69
-147
lines changed

4 files changed

+69
-147
lines changed

rb/lib/selenium/webdriver/ie.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
# specific language governing permissions and limitations
1818
# under the License.
1919

20-
require 'selenium/webdriver/ie/server'
2120
require 'selenium/webdriver/ie/bridge'
21+
require 'selenium/webdriver/ie/service'
2222

2323
module Selenium
2424
module WebDriver

rb/lib/selenium/webdriver/ie/bridge.rb

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,28 @@ module IE
2727

2828
class Bridge < Remote::Bridge
2929

30-
HOST = Platform.localhost
31-
DEFAULT_PORT = 5555
32-
DEFAULT_TIMEOUT = 30
33-
3430
def initialize(opts = {})
3531
caps = opts.delete(:desired_capabilities) { Remote::Capabilities.internet_explorer }
36-
timeout = opts.delete(:timeout) { DEFAULT_TIMEOUT }
37-
port = opts.delete(:port) { DEFAULT_PORT }
32+
port = opts.delete(:port) { Service::DEFAULT_PORT }
3833
http_client = opts.delete(:http_client)
3934
ignore_mode = opts.delete(:introduce_flakiness_by_ignoring_security_domains)
4035
native_events = opts.delete(:native_events) != false
41-
implementation = opts.delete(:implementation)
42-
43-
@server = Server.get(:implementation => implementation)
4436

45-
@server.log_level = opts.delete(:log_level) if opts[:log_level]
46-
@server.log_file = opts.delete(:log_file) if opts[:log_file]
37+
@service = Service.new(IE.driver_path, port, *extract_service_args(opts))
4738

4839
unless opts.empty?
4940
raise ArgumentError, "unknown option#{'s' if opts.size != 1}: #{opts.inspect}"
5041
end
5142

52-
@port = @server.start Integer(port), timeout
53-
54-
if ignore_mode
55-
caps['ignoreProtectedModeSettings'] = true
56-
end
43+
@service.start
5744

45+
caps['ignoreProtectedModeSettings'] = true if ignore_mode
5846
caps['nativeEvents'] = native_events
5947

6048
remote_opts = {
61-
:url => @server.uri,
49+
:url => @service.uri,
6250
:desired_capabilities => caps
6351
}
64-
6552
remote_opts[:http_client] = http_client if http_client
6653

6754
super(remote_opts)
@@ -77,9 +64,18 @@ def driver_extensions
7764

7865
def quit
7966
super
80-
nil
8167
ensure
82-
@server.stop
68+
@service.stop if @service
69+
end
70+
71+
private
72+
73+
def extract_service_args(opts)
74+
args = []
75+
args << "--log-level=#{opts.delete(:log_level).to_s.upcase}" if opts[:log_level]
76+
args << "--log-file=#{opts.delete(:log_file)}" if opts[:log_file]
77+
args << "--implementation=#{opts.delete(:implementation).to_s.upcase}" if opts[:implementation]
78+
args
8379
end
8480

8581
end # Bridge

rb/lib/selenium/webdriver/ie/server.rb

Lines changed: 0 additions & 126 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# encoding: utf-8
2+
#
3+
# Licensed to the Software Freedom Conservancy (SFC) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The SFC licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
module Selenium
21+
module WebDriver
22+
module IE
23+
24+
#
25+
# @api private
26+
#
27+
28+
class Service < WebDriver::Service
29+
DEFAULT_PORT = 5555
30+
31+
private
32+
33+
def stop_server
34+
# server can only be stopped as process
35+
end
36+
37+
def start_process
38+
server_command = [@executable_path, "--port=#{@port}", *@extra_args]
39+
@process = ChildProcess.new(*server_command)
40+
41+
@process.io.inherit! if $DEBUG
42+
@process.start
43+
end
44+
45+
def cannot_connect_error_text
46+
"unable to connect to IE server #{@host}:#{@port}"
47+
end
48+
49+
end # Server
50+
end # IE
51+
end # WebDriver
52+
end # Selenium

0 commit comments

Comments
 (0)