I work for Sauce Labs and maintained the now deprecated Ruby gem, including adding parallel functionality to it. It's safe to say I have Opinions™️.
You'll have to decide whether to parallelise by test (eg, run more tests on a single browser at once) or by browser (run the same test on multiple platforms at once).
Because RSpec has no parallelisation support, your core approach for either is going to have to involve running multiple RSpec processes; What will differ is how you run those.
With Github actions, you can run multiple jobs in parallel. That's suitable for running all your tests against a single platform in serial, but running multiple complete runs in parallel. That is, running (All Tests: Firefox) and (All Tests: Chrome) simultaneously. All you'd have to do is set up one job per Sauce Labs concurrency slot, and pass in your browser configuration via input or environment variable.
If you instead wanted to run all your tests against a single platform, you could use Grosser's Parallel Tests library. It breaks tests up into (n) concurrency groups, then starts a separate RSpec process for each group. If you follow these instructions, each group should end roughly at the same time.
What I'd Do
I'd personally use the Parallel Tests gem with my full concurrency, in a single browser. That would act as a quality gate to let me know fastest if my code is flat out broken. I'd then add a matrix job (one per concurrency slot) that needs the first quality gate to pass before running. I can use the matrix variables to control which platform runs:
quality_gate:
name: Quality Gate, running all tests on Chrome Latest
steps:
prepare_code: #Setup
run_tests:
- run: parallel_rspec specs/
browser_coverage:
name: Concurrency 1
needs: quality_gate
strategy:
max-parallel: 2
fail-fast: true
matrix:
browserName: [Firefox, Chrome]
browserVersion: [latest]
platformName: [Windows 10, Windows 7, MacOS 10.14]
exclude:
- browserName: Chrome
browserVersion: latest
platformName: Windows 10
include:
- browserName: Safari
platformName: MacOS 10.14
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/[email protected]
with:
ruby-version: 2.7.1
- name: Install dependencies
run: bundle install
- name: run tests
env:
browserName: ${{ matrix.browserName }}
browserVersion: ${{ matrix.browserVersion }}
platformName: ${{ matrix.platformName }}
run: rspec
Caveats
- If your organisation shares concurrency between multiple teams, you may not have all your concurrency available at runtime
- Matrixes consists of every value multiplied by every other value, which may not be valid. For instance, Safari won't run on Windows 10. You'll need to check the Platform Configurator to ensure you're excluding invalid combinations
Bonus Points
If you add a workflow dispatch action, you can kick off your tests manually. By using inputs, you could manually specify browser configuration and/or concurrency for on-demand execution from Github.
Worked Example
OK so you inspired me to make a worked example. This action:
- Includes Sauce Connect
- Runs at full concurrency on a single browser to ensure code works
- If passes, runs across all other browsers
- Allows manual triggering of different browsers