angular / protractor

E2E test framework for Angular apps
http://www.protractortest.org
MIT License
8.75k stars 2.31k forks source link

cannot run Protractor on a docker image #4601

Open rolandjitsu opened 6 years ago

rolandjitsu commented 6 years ago

Bug report

I'm trying to run e2e tests on CircleCI 2.0 infrastructure using a simple custom docker image, but it seems like if I use the directConnect flag, it does't work.

I'm using Alpine with Chromium 61 in the docker images. I'm not sure if this fails because I'm using Chromium and not Chrome.

exports.config = { allScriptsTimeout: 11000, specs: [ './e2e/*/.e2e-spec.ts' ], capabilities: { browserName: 'chrome', // Run tests in a headless Chrome // https://github.com/angular/protractor/blob/master/docs/browser-setup.md#using-headless-chrome chromeOptions: { args: [ // IMPORTANT: Required flag for running Chrome in unprivileged Docker, // see https://github.com/karma-runner/karma-chrome-launcher/issues/125#issuecomment-312668593 '--no-sandbox', '--headless', '--disable-gpu' ] } }, // TODO: Try to figure out why using directConnect doesn't work directConnect: true, baseUrl: 'http://localhost:4224/', framework: 'jasmine', jasmineNodeOpts: { showColors: true, defaultTimeoutInterval: 30000, print: () => {} }, onPrepare() { // Add jasmine spec reporter jasmine.getEnv() .addReporter(new SpecReporter({spec: {displayStacktrace: true}})); // Compile TS files require('ts-node').register({ project: 'e2e/tsconfig.e2e.json' }); } };

- A relevant example test
```ts
import {AppPage} from './portal.po';

describe('App', () => {
    let page: AppPage;

    beforeEach(() => {
        page = new AppPage();
    });

    it('should display welcome message', () => {
        page.navigateTo();
    });
});

webpack: Compiled successfully. [12:19:40] I/file_manager - creating folder /root/gva-travel/node_modules/webdriver-manager/selenium [12:19:40] I/update - chromedriver: unzipping chromedriver_2.33.zip [12:19:41] I/update - chromedriver: setting permissions to 0755 for /root/gva-travel/node_modules/webdriver-manager/selenium/chromedriver_2.33 [12:19:41] I/launcher - Running 1 instances of WebDriver [12:19:41] I/direct - Using ChromeDriver directly... [12:19:41] E/launcher - spawn /root/gva-travel/node_modules/webdriver-manager/selenium/chromedriver_2.33 ENOENT [12:19:41] E/launcher - Error: spawn /root/gva-travel/node_modules/webdriver-manager/selenium/chromedriver_2.33 ENOENT at _errnoException (util.js:1024:11) at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19) at onErrorNT (internal/child_process.js:372:16) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9) [12:19:41] E/launcher - Process exited with error code 199 npm ERR! code ELIFECYCLE npm ERR! errno 199 npm ERR! gva-travel@0.0.0 e2e:ci: ng e2e --prod --no-progress --no-live-reload --no-watch --port 4224 npm ERR! Exit status 199 npm ERR! npm ERR! Failed at the gva-travel@0.0.0 e2e:ci script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2017-11-25T12_19_41_356Z-debug.log Exited with code 199


- Steps to reproduce the bug
- The URL you are running your tests against (if relevant)
rolandjitsu commented 6 years ago

And if I try without it I get:

(node:73) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.

webpack: Compiled successfully.
[13:44:06] I/update - chromedriver: file exists /root/gva-travel/node_modules/webdriver-manager/selenium/chromedriver_2.33.zip
[13:44:06] I/update - chromedriver: unzipping chromedriver_2.33.zip
[13:44:06] I/update - chromedriver: setting permissions to 0755 for /root/gva-travel/node_modules/webdriver-manager/selenium/chromedriver_2.33
[13:44:06] I/update - chromedriver: chromedriver_2.33 up to date
[13:44:06] I/launcher - Running 1 instances of WebDriver
[13:44:06] I/local - Starting selenium standalone server...
[13:44:07] I/local - Selenium standalone server started at http://172.19.0.3:37615/wd/hub
[13:44:27] E/launcher - Timed out waiting for driver server to start.
Build info: version: '3.7.1', revision: '8a0099a', time: '2017-11-06T21:07:36.161Z'
System info: host: '338ac0b1aeda', ip: '172.19.0.3', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-97-generic', java.version: '1.8.0_151'
Driver info: driver.version: unknown
[13:44:27] E/launcher - WebDriverError: Timed out waiting for driver server to start.
Build info: version: '3.7.1', revision: '8a0099a', time: '2017-11-06T21:07:36.161Z'
System info: host: '338ac0b1aeda', ip: '172.19.0.3', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-97-generic', java.version: '1.8.0_151'
Driver info: driver.version: unknown
    at Object.checkLegacyResponse (/root/gva-travel/node_modules/selenium-webdriver/lib/error.js:546:15)
    at parseHttpResponse (/root/gva-travel/node_modules/selenium-webdriver/lib/http.js:509:13)
    at doSend.then.response (/root/gva-travel/node_modules/selenium-webdriver/lib/http.js:441:30)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
From: Task: WebDriver.createSession()
    at Function.createSession (/root/gva-travel/node_modules/selenium-webdriver/lib/webdriver.js:769:24)
    at Function.createSession (/root/gva-travel/node_modules/selenium-webdriver/chrome.js:761:15)
    at createDriver (/root/gva-travel/node_modules/selenium-webdriver/index.js:170:33)
    at Builder.build (/root/gva-travel/node_modules/selenium-webdriver/index.js:626:16)
    at Local.getNewDriver (/root/gva-travel/node_modules/protractor/built/driverProviders/driverProvider.js:53:33)
    at Runner.createBrowser (/root/gva-travel/node_modules/protractor/built/runner.js:195:43)
    at q.then.then (/root/gva-travel/node_modules/protractor/built/runner.js:339:29)
    at _fulfilled (/root/gva-travel/node_modules/protractor/node_modules/q/q.js:834:54)
    at self.promiseDispatch.done (/root/gva-travel/node_modules/protractor/node_modules/q/q.js:863:30)
    at Promise.promise.promiseDispatch (/root/gva-travel/node_modules/protractor/node_modules/q/q.js:796:13)
    at /root/gva-travel/node_modules/protractor/node_modules/q/q.js:604:44
    at runSingle (/root/gva-travel/node_modules/protractor/node_modules/q/q.js:137:13)
    at flush (/root/gva-travel/node_modules/protractor/node_modules/q/q.js:125:13)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
[13:44:27] E/launcher - Process exited with error code 199
npm ERR! code ELIFECYCLE
npm ERR! errno 199
npm ERR! gva-travel@0.0.0 e2e:ci: `ng e2e --prod --no-progress --no-live-reload --no-watch --port 4224`
npm ERR! Exit status 199
npm ERR! 
npm ERR! Failed at the gva-travel@0.0.0 e2e:ci script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2017-11-25T13_44_28_022Z-debug.log
Exited with code 199
rolandjitsu commented 6 years ago

And a final note, if I set the path to the chromedriver that's installed on the system via chromeDriver: '/usr/bin/chromedriver', then the tests run just fine.

Xotabu4 commented 6 years ago

@rolandjitsu I would suggest to not put tests and chrome in same container - for scalability and stability reasons. This allows to use ready-to-use official selenium doker files for browsers, and in future you might replace chrome container with selenium grid easily. Or even some other selenium grid replacement like Selenoid: https://medium.com/@aandryashin/selenium-done-in-60-seconds-176796f8bdc7

You can take my gist as example: https://gist.github.com/Xotabu4/a243d9ff25cfe276bcaa0175fb6a4b00

rolandjitsu commented 6 years ago

@Xotabu4 I was not aware you could do that on CircleCI. Thanks.

benjaminapetersen commented 6 years ago

Experiencing more or less the same issue now. Have a container setup with Xvfb and Firefox, attempting to run some Protractor tests against a webapp in a separate container, using an environment variable to provide the address.

The tests run fine locally, but once I docker build and docker run the image, the tests fail with the following:

[14:00:48] D/launcher - Running with --troubleshoot
[14:00:48] D/launcher - Protractor version: 5.3.0
[14:00:48] D/launcher - Your base url for tests is https://192.168.1.69:8443
(node:25) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[14:00:48] I/launcher - Running 1 instances of WebDriver
[14:00:48] I/direct - Using FirefoxDriver directly...
[14:01:49] E/launcher - address not available
[14:01:49] E/launcher - WebDriverError: address not available
    at Object.throwDecodedError (/opt/smoke-test/node_modules/selenium-webdriver/lib/error.js:514:15)
    at parseHttpResponse (/opt/smoke-test/node_modules/selenium-webdriver/lib/http.js:519:13)
    at doSend.then.response (/opt/smoke-test/node_modules/selenium-webdriver/lib/http.js:441:30)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:160:7)
From: Task: WebDriver.createSession()
    at Function.createSession (/opt/smoke-test/node_modules/selenium-webdriver/lib/webdriver.js:769:24)
    at Function.createSession (/opt/smoke-test/node_modules/selenium-webdriver/firefox/index.js:521:41)
    at Direct.getNewDriver (/opt/smoke-test/node_modules/protractor/built/driverProviders/direct.js:105:33)
    at Runner.createBrowser (/opt/smoke-test/node_modules/protractor/built/runner.js:195:43)
    at q.then.then (/opt/smoke-test/node_modules/protractor/built/runner.js:339:29)
    at _fulfilled (/opt/smoke-test/node_modules/q/q.js:834:54)
    at self.promiseDispatch.done (/opt/smoke-test/node_modules/q/q.js:863:30)
    at Promise.promise.promiseDispatch (/opt/smoke-test/node_modules/q/q.js:796:13)
    at /opt/smoke-test/node_modules/q/q.js:556:49
    at runSingle (/opt/smoke-test/node_modules/q/q.js:137:13)
[14:01:49] E/launcher - Process exited with error code 199

The 199 code is the "kitchen sink" error code & doesn't give a lot to go on. The most notable line is E/launcher - address not available, which seems important, but I'm not quite sure what to track down to resolve. Its not clear who or what is asking for the address or what kind of address is desired.

vjbhaskar commented 6 years ago

Hello im trying to run the test on docker and i get the following error, i am using gulp angular protractor, is this a known issue?

gulp protractor:local

[12:50:23] Using gulpfile ~/gulpfile.js
[12:50:23] Starting 'webdriver-update'...
[12:50:23] I/file_manager - creating folder /root/node_modules/protractor/node_modules/webdriver-manager/selenium
[12:50:26] I/update - chromedriver: unzipping chromedriver_2.36.zip
[12:50:27] I/update - chromedriver: setting permissions to 0755 for /root/node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.36
[12:50:45] I/update - geckodriver: unzipping geckodriver-v0.19.1.tar.gz
[12:50:45] I/update - geckodriver: setting permissions to 0755 for /root/node_modules/protractor/node_modules/webdriver-manager/selenium/geckodriver-v0.19.1
[12:50:45] Finished 'webdriver-update' after 22 s
[12:50:45] Starting 'protractor:local'...
(node:39) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[12:50:46] I/launcher - Running 1 instances of WebDriver
[12:50:46] I/local - Starting selenium standalone server...
[12:50:46] I/local - Selenium standalone server started at http://192.168.1.15:41366/wd/hub
[12:51:06] E/launcher - Timed out waiting for driver server to start.
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:15.31Z'
System info: host: 'ultra', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.13.0-36-generic', java.version: '1.8.0_121'
Driver info: driver.version: unknown
[12:51:06] E/launcher - WebDriverError: Timed out waiting for driver server to start.
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:15.31Z'
System info: host: 'ultra', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.13.0-36-generic', java.version: '1.8.0_121'
Driver info: driver.version: unknown
    at Object.checkLegacyResponse (/root/node_modules/selenium-webdriver/lib/error.js:546:15)
    at parseHttpResponse (/root/node_modules/selenium-webdriver/lib/http.js:509:13)
    at doSend.then.response (/root/node_modules/selenium-webdriver/lib/http.js:441:30)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
From: Task: WebDriver.createSession()
    at Function.createSession (/root/node_modules/selenium-webdriver/lib/webdriver.js:769:24)
    at Function.createSession (/root/node_modules/selenium-webdriver/chrome.js:761:15)
    at createDriver (/root/node_modules/selenium-webdriver/index.js:170:33)
    at Builder.build (/root/node_modules/selenium-webdriver/index.js:626:16)
    at Local.getNewDriver (/root/node_modules/protractor/built/driverProviders/driverProvider.js:53:33)
    at Runner.createBrowser (/root/node_modules/protractor/built/runner.js:195:43)
    at q.then.then (/root/node_modules/protractor/built/runner.js:339:29)
    at _fulfilled (/root/node_modules/q/q.js:834:54)
    at self.promiseDispatch.done (/root/node_modules/q/q.js:863:30)
    at Promise.promise.promiseDispatch (/root/node_modules/q/q.js:796:13)
    at /root/node_modules/q/q.js:604:44
    at runSingle (/root/node_modules/q/q.js:137:13)
    at flush (/root/node_modules/q/q.js:125:13)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
[12:51:06] E/launcher - Process exited with error code 199

/root/gulp/e2e-tests.js:21
                throw err;
                ^
Error: protractor exited with code 199
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! dpe2etests@0.0.1 e2e:local: `gulp protractor:local`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the dpe2etests@0.0.1 e2e:local script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-03-12T12_51_06_758Z-debug.log
benjaminapetersen commented 6 years ago

You probably want to do webdriver-update in your Dockerfile so that the drivers are built into the image & that component doesn't need to be done every time you run the image. I don't think that will solve all your problems, but it may help some.

vjbhaskar commented 6 years ago

@benjaminapetersen Thank you for the suggestion will try it tomorrow!

vjbhaskar commented 6 years ago

Running docker run -d --rm --net=host --name chrome selenium/standalone-chrome-debug:3 this and specifying seleniumaddress in my configfile solved the issue. Thank you!

mneetha commented 6 years ago

@vjbhaskar in the seleniumaddress what did u mention? http://

vjbhaskar commented 6 years ago

exports.config = { seleniumAddress: 'http://localhost:4444/wd/hub' }