Recently I spent quite a time to start e2e test to my project and incorporate it into build pipeline. A setup requires at least 2 nodes (mongodb + .Net5 backend with Angular client) so it is been decided to run all of this in docker. I've added additional docker-compose-test.yml where I'll start temporary nodes to run server integration tests (that needs mongo) and then client tests including e2e (that needs completely working setup). So after days of tuning all of this I ended up with a protractor.conf.js
that have a chromeDriver hardcoded for docker:
capabilities: {
'browserName': 'chrome',
chromeOptions: {
args: ['--headless', '--disable-gpu', '--no-sandbox'],
},
},
directConnect: true,
chromeDriver: '/usr/bin/chromedriver', // !!!
baseUrl: 'http://localhost:4444/',
framework: 'jasmine',
It finally works in docker perfectly (with chromedriver update disabled, since it is preinstalled on another stage into Alpine image, where automatic update not working at all otherwise, and it is just noticeable faster). But the problem is, not surprisingly, it is no longer works locally:
Error message: Could not find chromedriver at Q:\usr\bin\chromedriver. Run 'webdriver-manager update' to download binaries.
Also additionally I always have to pass --dev-server-target=
both locally and in docker because I'm always have this either already running in docker or in my local ng serve, so another dev-server don't make sense for me. I've added this to package.json
: "e2e": "ng e2e --dev-server-target="
it works for npm run e2e
, but I also want to have ng e2e
without parameters for local run (I believe it is possible to configure, but how?)
And how I can setup chromedriver that works both in docker and on a local runs?
Local runs are easier to debug and faster to start...
NOTE: 4444
is a port of my dev web server, I just recently realized that selenium uses the same.
what I did in this case was to declare a docker image specific environment variable
# Dockerfile
ENV DOCKERIMAGEENV="true"
and then inside the config, I placed a simple if/else logic
if (process.env.DOCKERIMAGEENV) {
// do whatever you need for your docker
} else {
// local specific options
}
so in your case this would look like this
let chromedriverPath;
if (process.env.DOCKERIMAGEENV) {
chromedriverPath = '/usr/bin/chromedriver'
} else {
chromedriverPath = 'C:\another\path'
}
exports.config = {
directConnect: true,
chromeDriver: chromedriverPath,
}