Skip to content

Commit 2994952

Browse files
committed
[rb] Split rb/BUILD into smaller packages
This fits more into Bazel approach because smaller packages with a proper dependency tree would allow to use Bazel caching more efficiently. For example, only few tests would be re-run considering you ran all integration tests for Chrome before and only changed code in `chrome/driver.rb`. This is because just a few tests depend on `chrome/driver.rb`. Per-test file packages also allow us to use Bazel flaky retry flags efficiently - previously it would re-run all the tests when one of them fails. This commit also moves certain files around to make Ruby codebase more reasonable: * CDP client code generator lives in the `rb/lib/selenium/devtools` * Nightly version generator lives in a new `rb/lib/selenium/support` Since now integration tests are being in parallel by default, few changes had to be done to make support code more concurrency-safe. Notably, Grid and Rack servers are being started on randomized ports. Some other tests were adapted/guarded to work better when run in parallel. The test configuration is now controlled by a combination of `--define <name>=<value>` flags, supporting `browser/remote/headless` as names. See README.md changes for more details.
1 parent b5b25eb commit 2994952

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1190
-903
lines changed

.bazelrc

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ build --test_env=PYTHON_VERSION
6262
build --test_env=RUBYOPT="-Irb/lib -w"
6363

6464
# JRuby/TruffleRuby: https://github.com/jruby/jruby/issues/5661
65+
6566
build --action_env=HOME
6667
test --test_env=HOME
6768

.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@ indent_style = space
5353
indent_size = 2
5454
end_of_line = crlf
5555
charset = utf-8
56+
57+
[{*.bazel,WORKSPACE}]
58+
indent_style = space
59+
indent_size = 4

.github/workflows/ci-ruby.yml

+27-90
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,35 @@ jobs:
5151
- name: Build Gems
5252
run: bazel build //rb:${{ matrix.target }}
5353

54-
chrome-test:
54+
integration-test:
5555
if: ${{ needs.check_workflow.outputs.result == 'true' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || contains(toJson(github.event.commits), '[run ruby]') == true }}
5656
needs: check_workflow
5757
runs-on: ${{ matrix.os }}
58+
name: ${{ format('{0}{1}-test ({2})', (matrix.remote && 'remote-' || ''), matrix.browser, matrix.os) }}
5859
strategy:
5960
fail-fast: false
6061
matrix:
61-
target: [ 'chrome-test', 'remote-chrome-test' ]
62-
os: [ 'ubuntu-latest', 'windows-latest' ]
62+
browser:
63+
- chrome
64+
- edge
65+
- firefox
66+
remote:
67+
- false
68+
- true
69+
os:
70+
- ubuntu-latest
71+
- windows-latest
72+
exclude:
73+
- browser: edge
74+
os: ubuntu-latest
6375
steps:
6476
- name: Checkout source tree
6577
uses: actions/checkout@v3
6678
- name: Setup Bazel
6779
uses: p0deje/[email protected]
6880
with:
6981
bazelisk-cache: true
70-
disk-cache: rb-${{ matrix.target }}
82+
disk-cache: rb-${{ matrix.browser }}-remote-${{ matrix.remote }}
7183
external-cache: |
7284
crates: rust/Cargo.Bazel.lock
7385
npm: package-lock.json
@@ -84,6 +96,7 @@ jobs:
8496
if: matrix.os == 'ubuntu-latest'
8597
run: sudo apt-get -y install fluxbox
8698
- name: Setup Chrome
99+
if: matrix.browser == 'chrome'
87100
uses: browser-actions/setup-chrome@latest
88101
with:
89102
chrome-version: stable
@@ -96,95 +109,19 @@ jobs:
96109
- name: Set resolution
97110
if: matrix.os == 'windows-latest'
98111
run: Set-DisplayResolution -Width 1920 -Height 1080 -Force
99-
- name: Run Chrome tests
100-
run: bazel test --cache_test_results=no --test_output=all //rb:${{ matrix.target }}
101-
env:
102-
DISPLAY: :99
103-
104-
edge-test:
105-
if: ${{ needs.check_workflow.outputs.result == 'true' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || contains(toJson(github.event.commits), '[run ruby]') == true }}
106-
needs: check_workflow
107-
runs-on: ${{ matrix.os }}
108-
strategy:
109-
fail-fast: false
110-
matrix:
111-
target: [ 'edge-test', 'remote-edge-test' ]
112-
os: [ 'windows-latest' ]
113-
steps:
114-
- name: Checkout source tree
115-
uses: actions/checkout@v3
116-
- name: Setup Java
117-
uses: actions/setup-java@v3
118-
with:
119-
java-version: 11
120-
distribution: 'temurin'
121-
- name: Setup Bazel
122-
uses: p0deje/[email protected]
123-
with:
124-
bazelisk-cache: true
125-
disk-cache: rb-${{ matrix.target }}
126-
external-cache: |
127-
crates: rust/Cargo.Bazel.lock
128-
npm: package-lock.json
129-
pypi__pip: py/requirements_lock.txt
130-
rules_ruby_dist: rb/ruby_version.bzl
131-
repository-cache: true
132-
token: ${{ secrets.GITHUB_TOKEN }}
133112
- name: Setup Edge
113+
if: matrix.browser == 'edge'
134114
uses: browser-actions/setup-edge@latest
135115
with:
136116
edge-version: stable
137-
- name: Run Edge tests
138-
run: bazel test --cache_test_results=no --test_output=all //rb:${{ matrix.target }}
139-
140-
firefox-test:
141-
if: ${{ needs.check_workflow.outputs.result == 'true' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || contains(toJson(github.event.commits), '[run ruby]') == true }}
142-
needs: check_workflow
143-
runs-on: ${{ matrix.os }}
144-
strategy:
145-
fail-fast: false
146-
matrix:
147-
target: [ 'firefox-test', 'remote-firefox-test' ]
148-
os: [ 'ubuntu-latest', 'windows-latest' ]
149-
steps:
150-
- name: Checkout source tree
151-
uses: actions/checkout@v3
152-
- name: Setup Java
153-
uses: actions/setup-java@v3
154-
with:
155-
java-version: 11
156-
distribution: 'temurin'
157-
- name: Setup Bazel
158-
uses: p0deje/[email protected]
159-
with:
160-
bazelisk-cache: true
161-
disk-cache: rb-${{ matrix.target }}
162-
external-cache: |
163-
crates: rust/Cargo.Bazel.lock
164-
npm: package-lock.json
165-
pypi__pip: py/requirements_lock.txt
166-
rules_ruby_dist: rb/ruby_version.bzl
167-
repository-cache: true
168-
token: ${{ secrets.GITHUB_TOKEN }}
169-
- name: Setup Fluxbox
170-
if: matrix.os == 'ubuntu-latest'
171-
run: sudo apt-get -y install fluxbox
172-
- name: Setup Firefox
173-
uses: abhi1693/[email protected]
174-
with:
175-
browser: firefox
176-
version: latest
177-
- name: Start XVFB
178-
if: matrix.os == 'ubuntu-latest'
179-
run: Xvfb :99 &
180-
- name: Start Fluxbox
181-
if: matrix.os == 'ubuntu-latest'
182-
run: fluxbox -display :99 &
183-
- name: Set resolution
184-
if: matrix.os == 'windows-latest'
185-
run: Set-DisplayResolution -Width 1920 -Height 1080 -Force
186-
- name: Run Firefox tests
187-
run: bazel test --cache_test_results=no --test_output=all //rb:${{ matrix.target }}
117+
- name: Run tests
118+
run: >
119+
bazel test
120+
--define browser=${{ matrix.browser }}
121+
--define remote=${{ matrix.remote }}
122+
--flaky_test_attempts 3
123+
--local_test_jobs 1
124+
//rb/spec/integration/...
188125
env:
189126
DISPLAY: :99
190127

@@ -262,4 +199,4 @@ jobs:
262199
repository-cache: true
263200
token: ${{ secrets.GITHUB_TOKEN }}
264201
- name: Run unit tests
265-
run: bazel test --cache_test_results=no --test_output=all //rb:unit-test
202+
run: bazel test //rb/spec/unit/...

CONTRIBUTING.md

+15-35
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ the issue is a regression.
3030
## Feature Requests
3131

3232
If you find that Selenium is missing something, feel free to open an issue
33-
with details describing what feature(s) you'd like added or changed.
33+
with details describing what feature(s) you'd like added or changed.
3434

3535
If you'd like a hand at trying to implement the feature yourself, please refer to the [Code Contributions](#code-contributions) section of the document.
3636

@@ -180,7 +180,7 @@ Use `git rebase` (not `git merge`) to sync your work from time to time.
180180
### Step 5: Test
181181

182182
Bug fixes and features **should have tests**. Look at other tests to
183-
see how they should be structured. Verify that new and existing tests are
183+
see how they should be structured. Verify that new and existing tests are
184184
passing locally before pushing code.
185185

186186
#### Running tests locally
@@ -192,20 +192,20 @@ Build your code for the latest changes and run tests locally.
192192
<summary>
193193
Click to see How to run Python Tests.
194194
</summary>
195-
195+
196196
It's not mandatory to run tests sequentially but running Unit tests
197197
before browser testing is recommended.
198-
198+
199199
Unit Tests
200200
```shell
201201
% bazel test //py:unit
202202
```
203-
203+
204204
Remote Tests
205205
```shell
206206
% bazel test --jobs 1 //py:test-remote
207207
```
208-
208+
209209
Browser Tests
210210
```shell
211211
% bazel test //py:test-<browsername> #eg test-chrome, test-firefox
@@ -217,17 +217,17 @@ Build your code for the latest changes and run tests locally.
217217
<summary>
218218
Click to see How to run JavaScript Tests.
219219
</summary>
220-
220+
221221
Node Tests
222222
```shell
223223
% bazel test //javascript/node/selenium-webdriver:tests
224224
```
225-
225+
226226
Firefox Atom Tests
227227
```shell
228228
% bazel test --test_tag_filters=firefox //javascript/atoms/... //javascript/selenium-atoms/... //javascript/webdriver/...
229229
```
230-
230+
231231
Grid UI Unit Tests
232232
```shell
233233
% cd javascript/grid-ui && npm install && npm test
@@ -239,47 +239,27 @@ Build your code for the latest changes and run tests locally.
239239
<summary>
240240
Click to see How to run Java Tests.
241241
</summary>
242-
242+
243243
Small Tests
244244
```shell
245245
% bazel test --cache_test_results=no --test_size_filters=small grid java/test/...
246246
```
247-
247+
248248
Large Tests
249249
```shell
250250
% bazel test --cache_test_results=no java/test/org/openqa/selenium/grid/router:large-tests
251251
```
252-
252+
253253
Browser Tests
254254
```shell
255255
bazel test --test_size_filters=small,medium --cache_test_results=no --test_tag_filters=-browser-test //java/...
256256
```
257257
</details>
258258

259259
##### Ruby
260-
<details>
261-
<summary>
262-
Click to see How to run Ruby Tests.
263-
</summary>
264-
265-
It's not mandatory to run tests sequentially but running Unit tests
266-
before browser testing is recommended.
267-
268-
Unit Tests
269-
```shell
270-
% bazel test rb:unit-test
271-
```
272-
273-
Chrome Tests
274-
```shell
275-
bazel test rb:chrome-test
276-
```
277260

278-
Remote Tests
279-
```shell
280-
% bazel test --test_output=all --test_arg="-tfocus" --test_arg="--fail-fast" rb:remote-chrome-test
281-
```
282-
</details>
261+
Please see https://github.com/SeleniumHQ/selenium#ruby for details about running
262+
tests.
283263

284264
### Step 6: Push
285265

@@ -288,7 +268,7 @@ Build your code for the latest changes and run tests locally.
288268
```
289269

290270
Go to https://github.com/yourusername/selenium.git and press the _Pull
291-
Request_ and fill out the form.
271+
Request_ and fill out the form.
292272

293273
Pull requests are usually reviewed within a few days. If there are
294274
comments to address, apply your changes in new commits (preferably

0 commit comments

Comments
 (0)