Skip to content

Commit 0ce65b1

Browse files
committed
[rb] add initial support for selenium manager
1 parent 9442ff3 commit 0ce65b1

File tree

12 files changed

+254
-42
lines changed

12 files changed

+254
-42
lines changed

.github/workflows/ci-ruby.yml

Lines changed: 78 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,29 @@ jobs:
2929
matrix:
3030
target: [ 'selenium-devtools', 'selenium-webdriver' ]
3131
steps:
32-
- uses: actions/checkout@v2
33-
- uses: actions/setup-java@v1
32+
- name: Checkout source tree
33+
uses: actions/checkout@v2
34+
- name: Setup Java
35+
uses: actions/setup-java@v1
3436
with:
3537
java-version: 11
36-
- uses: ruby/setup-ruby@v1
38+
- name: Setup Ruby
39+
uses: ruby/setup-ruby@v1
3740
with:
3841
ruby-version: 2.7
39-
- uses: actions/cache@v2
42+
- name: Cache Bazel artifacts
43+
uses: actions/cache@v2
4044
with:
4145
path: |
4246
~/.cache/bazel-disk
4347
~/.cache/bazel-repo
4448
key: ${{ runner.os }}-bazel-ruby-build-gem-${{ matrix.target }}-${{ hashFiles('**/BUILD.bazel') }}
4549
restore-keys: |
4650
${{ runner.os }}-bazel-ruby-build-gem-${{ matrix.target }}-
47-
- uses: ./.github/actions/setup-bazelisk
48-
- uses: ./.github/actions/bazel
51+
- name: Setup bazelisk
52+
uses: ./.github/actions/setup-bazelisk
53+
- name: Build Gems
54+
uses: ./.github/actions/bazel
4955
with:
5056
command: build //rb:${{ matrix.target }}
5157

@@ -58,29 +64,37 @@ jobs:
5864
matrix:
5965
target: [ 'chrome-test', 'remote-chrome-test' ]
6066
steps:
61-
- uses: actions/checkout@v2
62-
- uses: actions/setup-java@v1
67+
- name: Checkout source tree
68+
uses: actions/checkout@v2
69+
- name: Setup Java
70+
uses: actions/setup-java@v1
6371
with:
6472
java-version: 11
65-
- uses: ruby/setup-ruby@v1
73+
- name: Setup Ruby
74+
uses: ruby/setup-ruby@v1
6675
with:
6776
ruby-version: 2.7
68-
- uses: actions/cache@v2
77+
- name: Cache Bazel artifacts
78+
uses: actions/cache@v2
6979
with:
7080
path: |
7181
~/.cache/bazel-disk
7282
~/.cache/bazel-repo
7383
key: ${{ runner.os }}-bazel-ruby-${{ matrix.target }}-${{ hashFiles('**/BUILD.bazel') }}
7484
restore-keys: |
7585
${{ runner.os }}-bazel-ruby-${{ matrix.target }}-
76-
- uses: ./.github/actions/setup-bazelisk
86+
- name: Setup bazelisk
87+
uses: ./.github/actions/setup-bazelisk
7788
- name: Setup Fluxbox
7889
run: sudo apt-get -y install fluxbox
79-
- uses: ./.github/actions/setup-chrome
80-
- run: Xvfb :99 &
90+
- name: Setup Chrome
91+
uses: browser-actions/setup-chrome@latest
92+
- name: Start XVFB
93+
run: Xvfb :99 &
8194
- name: Start Fluxbox
8295
run: fluxbox -display :99 &
83-
- uses: ./.github/actions/bazel
96+
- name: Run Chrome tests
97+
uses: ./.github/actions/bazel
8498
with:
8599
command: test --test_output=all //rb:${{ matrix.target }}
86100
env:
@@ -95,30 +109,40 @@ jobs:
95109
matrix:
96110
target: [ 'firefox-test', 'remote-firefox-test' ]
97111
steps:
98-
- uses: actions/checkout@v2
99-
- uses: actions/setup-java@v1
112+
- name: Checkout source tree
113+
uses: actions/checkout@v2
114+
- name: Setup Java
115+
uses: actions/setup-java@v1
100116
with:
101117
java-version: 11
102-
- uses: ruby/setup-ruby@v1
118+
- name: Setup Ruby
119+
uses: ruby/setup-ruby@v1
103120
with:
104121
ruby-version: 2.7
105-
- uses: actions/cache@v2
122+
- name: Cache Bazel artifacts
123+
uses: actions/cache@v2
106124
with:
107125
path: |
108126
~/.cache/bazel-disk
109127
~/.cache/bazel-repo
110128
key: ${{ runner.os }}-bazel-ruby-${{ matrix.target }}-${{ hashFiles('**/BUILD.bazel') }}
111129
restore-keys: |
112130
${{ runner.os }}-bazel-ruby-${{ matrix.target }}-
113-
- uses: ./.github/actions/setup-bazelisk
131+
- name: Setup bazelisk
132+
uses: ./.github/actions/setup-bazelisk
114133
- name: Setup Fluxbox
115134
run: sudo apt-get -y install fluxbox
116-
- name: Setup Firefox and GeckoDriver
117-
uses: ./.github/actions/setup-firefox
118-
- run: Xvfb :99 &
135+
- name: Setup Firefox
136+
uses: abhi1693/setup-browser@v0.3.4
137+
with:
138+
browser: firefox
139+
version: latest
140+
- name: Start XVFB
141+
run: Xvfb :99 &
119142
- name: Start Fluxbox
120143
run: fluxbox -display :99 &
121-
- uses: ./.github/actions/bazel
144+
- name: Run Firefox tests
145+
uses: ./.github/actions/bazel
122146
with:
123147
command: test --test_output=all //rb:${{ matrix.target }}
124148
env:
@@ -129,20 +153,25 @@ jobs:
129153
needs: check_workflow
130154
runs-on: ubuntu-latest
131155
steps:
132-
- uses: actions/checkout@v2
133-
- uses: ruby/setup-ruby@v1
156+
- name: Checkout source tree
157+
uses: actions/checkout@v2
158+
- name: Setup Ruby
159+
uses: ruby/setup-ruby@v1
134160
with:
135161
ruby-version: 2.7
136-
- uses: actions/cache@v2
162+
- name: Cache Bazel artifacts
163+
uses: actions/cache@v2
137164
with:
138165
path: |
139166
~/.cache/bazel-disk
140167
~/.cache/bazel-repo
141168
key: ${{ runner.os }}-bazel-ruby-docs-${{ hashFiles('**/BUILD.bazel') }}
142169
restore-keys: |
143170
${{ runner.os }}-bazel-ruby-${{ matrix.target }}-
144-
- uses: ./.github/actions/setup-bazelisk
145-
- uses: ./.github/actions/bazel
171+
- name: Setup bazelisk
172+
uses: ./.github/actions/setup-bazelisk
173+
- name: Run docs tests
174+
uses: ./.github/actions/bazel
146175
with:
147176
command: run //rb:docs
148177

@@ -151,20 +180,25 @@ jobs:
151180
needs: check_workflow
152181
runs-on: ubuntu-latest
153182
steps:
154-
- uses: actions/checkout@v2
155-
- uses: ruby/setup-ruby@v1
183+
- name: Checkout source tree
184+
uses: actions/checkout@v2
185+
- name: Setup Ruby
186+
uses: ruby/setup-ruby@v1
156187
with:
157188
ruby-version: 2.7
158-
- uses: actions/cache@v2
189+
- name: Cache Bazel artifacts
190+
uses: actions/cache@v2
159191
with:
160192
path: |
161193
~/.cache/bazel-disk
162194
~/.cache/bazel-repo
163195
key: ${{ runner.os }}-bazel-ruby-lint-${{ hashFiles('**/BUILD.bazel') }}
164196
restore-keys: |
165197
${{ runner.os }}-bazel-ruby-lint-
166-
- uses: ./.github/actions/setup-bazelisk
167-
- uses: ./.github/actions/bazel
198+
- name: Setup bazelisk
199+
uses: ./.github/actions/setup-bazelisk
200+
- name: Run lint tests
201+
uses: ./.github/actions/bazel
168202
with:
169203
command: run //rb:lint
170204

@@ -177,19 +211,24 @@ jobs:
177211
matrix:
178212
ruby: [ '2.7', '3.1' ]
179213
steps:
180-
- uses: actions/checkout@v2
181-
- uses: ruby/setup-ruby@v1
214+
- name: Checkout source tree
215+
uses: actions/checkout@v2
216+
- name: Setup Ruby
217+
uses: ruby/setup-ruby@v1
182218
with:
183-
ruby-version: ${{ matrix.ruby }}
184-
- uses: actions/cache@v2
219+
ruby-version: 2.7
220+
- name: Cache Bazel artifacts
221+
uses: actions/cache@v2
185222
with:
186223
path: |
187224
~/.cache/bazel-disk
188225
~/.cache/bazel-repo
189226
key: ${{ runner.os }}-bazel-ruby-unit-test-${{ matrix.ruby }}-${{ hashFiles('**/BUILD.bazel') }}
190227
restore-keys: |
191228
${{ runner.os }}-bazel-ruby-unit-test-${{ matrix.ruby }}-
192-
- uses: ./.github/actions/setup-bazelisk
193-
- uses: ./.github/actions/bazel
229+
- name: Setup bazelisk
230+
uses: ./.github/actions/setup-bazelisk
231+
- name: Run unit tests
232+
uses: ./.github/actions/bazel
194233
with:
195234
command: test --test_output=all //rb:unit-test

rb/BUILD.bazel

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ copy_file(
2222
out = "lib/selenium/webdriver/atoms/findElements.js",
2323
)
2424

25+
copy_file(
26+
name = "manager-linux",
27+
src = "//common/manager:linux/selenium-manager",
28+
out = "bin/linux/selenium-manager",
29+
)
30+
31+
copy_file(
32+
name = "manager-windows",
33+
src = "//common/manager:windows/selenium-manager.exe",
34+
out = "bin/windows/selenium-manager.exe",
35+
)
36+
37+
copy_file(
38+
name = "manager-macos",
39+
src = "//common/manager:macos/selenium-manager",
40+
out = "bin/macos/selenium-manager",
41+
)
42+
2543
copy_file(
2644
name = "get-attribute",
2745
src = "//javascript/webdriver/atoms:get-attribute.js",
@@ -118,6 +136,9 @@ ruby_library(
118136
":find-elements",
119137
":get-attribute",
120138
":is-displayed",
139+
":manager-linux",
140+
":manager-macos",
141+
":manager-windows",
121142
":license",
122143
],
123144
deps = [

rb/lib/selenium/webdriver/chrome/service.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module WebDriver
2222
module Chrome
2323
class Service < WebDriver::Service
2424
DEFAULT_PORT = 9515
25+
BROWSER_NAME = 'chrome'
2526
EXECUTABLE = 'chromedriver'
2627
MISSING_TEXT = <<~ERROR
2728
Unable to find chromedriver. Please download the server from

rb/lib/selenium/webdriver/common.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
require 'selenium/webdriver/common/proxy'
2323
require 'selenium/webdriver/common/log_entry'
2424
require 'selenium/webdriver/common/file_reaper'
25+
require 'selenium/webdriver/common/selenium_manager'
2526
require 'selenium/webdriver/common/service'
2627
require 'selenium/webdriver/common/service_manager'
2728
require 'selenium/webdriver/common/socket_lock'
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# frozen_string_literal: true
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+
class SeleniumManager
23+
BIN_PATH = "../../../../../bin"
24+
25+
def self.driver_location(browser_name)
26+
path = File.expand_path(BIN_PATH, __FILE__)
27+
path << if Platform.windows?
28+
'/windows/selenium-manager.exe'
29+
elsif Platform.mac?
30+
'/macos/selenium-manager'
31+
elsif Platform.linux?
32+
'/linux/selenium-manager'
33+
end
34+
path = File.expand_path(path, __FILE__)
35+
command = "#{path} --browser #{browser_name}"
36+
WebDriver.logger.debug("Executing Process #{command}")
37+
location = `#{command}`.split("\t").last.strip
38+
WebDriver.logger.debug("Driver found at #{location}")
39+
location
40+
end
41+
end # SeleniumManager
42+
end # WebDriver
43+
end # Selenium

rb/lib/selenium/webdriver/common/service.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ def initialize(path: nil, port: nil, args: nil)
8080
end
8181

8282
def launch
83-
sm = ServiceManager.new(self)
84-
sm.start
85-
sm
83+
ServiceManager.new(self).tap(&:start)
8684
end
8785

8886
def shutdown_supported
@@ -100,6 +98,7 @@ def extract_service_args(driver_opts)
10098
def binary_path(path = nil)
10199
path = path.call if path.is_a?(Proc)
102100
path ||= Platform.find_binary(self.class::EXECUTABLE)
101+
path ||= SeleniumManager.driver_location(self.class::BROWSER_NAME)
103102

104103
raise Error::WebDriverError, self.class::MISSING_TEXT unless path
105104

rb/lib/selenium/webdriver/edge/service.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module WebDriver
2424
module Edge
2525
class Service < Selenium::WebDriver::Chrome::Service
2626
DEFAULT_PORT = 9515
27+
BROWSER_NAME = 'edge'
2728
EXECUTABLE = 'msedgedriver'
2829
MISSING_TEXT = <<~ERROR
2930
Unable to find msedgedriver. Please download the server from

rb/lib/selenium/webdriver/firefox/service.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module WebDriver
2222
module Firefox
2323
class Service < WebDriver::Service
2424
DEFAULT_PORT = 4444
25+
BROWSER_NAME = 'firefox'
2526
EXECUTABLE = 'geckodriver'
2627
MISSING_TEXT = <<~ERROR
2728
Unable to find Mozilla geckodriver. Please download the server from

rb/lib/selenium/webdriver/ie/service.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module WebDriver
2222
module IE
2323
class Service < WebDriver::Service
2424
DEFAULT_PORT = 5555
25+
BROWSER_NAME = 'ie'
2526
EXECUTABLE = 'IEDriverServer'
2627
MISSING_TEXT = <<~ERROR
2728
Unable to find IEDriverServer. Please download the server from
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# frozen_string_literal: true
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+
require_relative '../spec_helper'
21+
22+
module Selenium
23+
module WebDriver
24+
module Chrome
25+
describe Service, exclusive: {browser: :chrome} do
26+
it 'auto uses chromedriver' do
27+
allow(Platform).to receive(:find_binary)
28+
service = Service.new
29+
service_manager = service.launch
30+
expect(service_manager.uri).to be_a(URI)
31+
end
32+
end
33+
end # Chrome
34+
end # WebDriver
35+
end # Selenium

0 commit comments

Comments
 (0)