This project serves as a minimal example of how to run UI tests against BrowserStack through GitLab CI using the Selenium Ruby bindings.
There are essentially two pieces required to get GitLab CI working with BrowserStack.
- A
.gitlab-ci.yml
file - BrowserStack Username / Access Key
In this example, spec/browserstack_spec.rb
is the main piece and is an RSpec test file.
This file contains one essential piece to getting BrowserStack configured:
let(:capabilities) do
{
browser: :chrome,
browser_version: '77.0',
os: 'OS X',
os_version: 'Mojave',
project: 'gitlab-browserstack-example',
build: ENV['CI_JOB_ID']
}
end
Here we are configuring the Desired Capabilities for Selenium as well as BrowserStack.
You'll notice we are also specifying ENV['CI_JOB_ID']
. This is a
pre-defined GitLab CI environment variable and it
is to differentiate each run by associating it with a GitLab Job.
Under the capabilities
hash, we specify
everything we'd like to configure BrowserStack with.
- Username
- Access Key
- Tags / Name / Build for naming your build in BrowserStack
Our GitLab CI configuration file contains one stage called test
, that
runs when we run the job manually.
In an actual CI/CD environment, you'd most likely have
when:manual
removed, meaning that these tests will run against BrowserStack on every push / merge request tomaster
.