Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: socket hang up OR Error: connect ECONNREFUSED 127.0.0.1:42395 - when 'docker' and 'devtools' services are used together. #78

Open
Pratikhanagodimath opened this issue Mar 17, 2020 · 7 comments

Comments

@Pratikhanagodimath
Copy link

I am attempting to use docker and devtools service together to evaluate performance of a page. Running locally. I am running into issues when I include ‘devtools’ as a service along with docker service, without ‘devtools’ the test just runs fine. Below is the error I see. What am I missing?. Seems like same issue mentioned here by prathameshnyt -> #3744 (comment)

Error without the mention of chrome debuggerAddress

2020-03-16T22:29:25.397Z DEBUG @wdio/utils:initialiseServices: initialise wdio service "docker"
2020-03-16T22:29:25.405Z DEBUG @wdio/utils:initialiseServices: initialise wdio service "devtools"
2020-03-16T22:29:25.702Z INFO @wdio/cli:launcher: Run onPrepare hook
2020-03-16T22:29:25.703Z DEBUG wdio-docker-service: Docker command: docker run --cidfile /Users/phanagodimath/Desktop/Projects/Martech-Performance/selenium_standalone_chrome.cid --rm -p 4444:4444 --shm-size 2g selenium/standalone-chrome
2020-03-16T22:29:25.710Z WARN wdio-docker-service: Connecting dockerEventsListener: 6138
2020-03-16T22:29:25.712Z INFO wdio-docker-service: Shutting down running container
2020-03-16T22:29:26.074Z INFO wdio-docker-service: Cleaning up CID files
2020-03-16T22:29:26.127Z INFO wdio-docker-service: Launching docker image 'selenium/standalone-chrome'
2020-03-16T22:29:26.471Z INFO wdio-docker-service: Container started: {
"args": "",
"image": "selenium/standalone-chrome",
"timeStamp": "2020-03-16T22:29:26.480Z",
"type": "container.start",
"status": "start",
"detail": {
"id": "3c9d234b53b5e9ff0997826cff84b8dd5b378595ea1da0363f205f56dbc94a0d",
"scope": "local",
"actor": {
"ID": "3c9d234b53b5e9ff0997826cff84b8dd5b378595ea1da0363f205f56dbc94a0d",
"Attributes": {
"authors": "SeleniumHQ",
"image": "selenium/standalone-chrome",
"name": "musing_elbakyan"
}
}
}
}
2020-03-16T22:29:26.587Z DEBUG wdio-docker-service: 2020-03-16 22:29:26,597 INFO Included extra file "/etc/supervisor/conf.d/selenium.conf" during parsing

2020-03-16T22:29:26.588Z DEBUG wdio-docker-service: 2020-03-16 22:29:26,598 INFO supervisord started with pid 7

2020-03-16T22:29:27.592Z DEBUG wdio-docker-service: 2020-03-16 22:29:27,603 INFO spawned: 'xvfb' with pid 10

2020-03-16T22:29:27.594Z DEBUG wdio-docker-service: 2020-03-16 22:29:27,605 INFO spawned: 'selenium-standalone' with pid 11

2020-03-16T22:29:28.066Z DEBUG wdio-docker-service: 22:29:28.075 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
2020-03-16 22:29:28,078 INFO success: xvfb entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2020-03-16 22:29:28,078 INFO success: selenium-standalone entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)

2020-03-16T22:29:28.222Z DEBUG wdio-docker-service: 22:29:28.234 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone Selenium Server on port 4444

2020-03-16T22:29:28.322Z DEBUG wdio-docker-service: 2020-03-16 22:29:28.327:INFO::main: Logging initialized @710ms to org.seleniumhq.jetty9.util.log.StdErrLog

2020-03-16T22:29:28.735Z DEBUG wdio-docker-service: 22:29:28.745 INFO [WebDriverServlet.] - Initialising WebDriverServlet

2020-03-16T22:29:28.896Z DEBUG wdio-docker-service: 22:29:28.908 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444

2020-03-16T22:29:29.249Z INFO wdio-docker-service: Docker container is ready
2020-03-16T22:29:29.251Z INFO @wdio/local-runner: Start worker 0-0 with arg: config/wdio.conf.docker.js
[0-0] 2020-03-16T22:29:29.475Z INFO @wdio/local-runner: Run worker command: run
[0-0] RUNNING in chrome - /test/specs/basic_docker.js
[0-0] 2020-03-16T22:29:29.553Z DEBUG @wdio/utils:initialiseServices: initialise wdio service "docker"
[0-0] 2020-03-16T22:29:29.558Z DEBUG @wdio/utils:initialiseServices: initialise wdio service "devtools"
[0-0] 2020-03-16T22:29:29.840Z DEBUG @wdio/local-runner:utils: init remote session
[0-0] 2020-03-16T22:29:29.841Z INFO webdriverio: Initiate new session using the webdriver protocol
[0-0] 2020-03-16T22:29:29.843Z INFO webdriver: [POST] http://127.0.0.1:4444/wd/hub/session
[0-0] 2020-03-16T22:29:29.843Z INFO webdriver: DATA {
capabilities: { alwaysMatch: { browserName: 'chrome' }, firstMatch: [ {} ] },
desiredCapabilities: { browserName: 'chrome' }
}
2020-03-16T22:29:29.989Z DEBUG wdio-docker-service: 22:29:30.002 INFO [ActiveSessionFactory.apply] - Capabilities are: {
"browserName": "chrome"
}

2020-03-16T22:29:29.992Z DEBUG wdio-docker-service: 22:29:30.005 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)

2020-03-16T22:29:30.032Z DEBUG wdio-docker-service: Starting ChromeDriver 80.0.3987.106 (f68069574609230cf9b635cd784cfb1bf81bb53a-refs/branch-heads/3987@{#882}) on port 7411

2020-03-16T22:29:30.037Z DEBUG wdio-docker-service: Only lo[c1a5l8 4c3o9n7n7e7c0t.i0o4n5s] [aSrEeV EaRlEl]o:w ebdi.n
Pdl(e)a sfea iplreodt:e cCta npnoortts used by C harsosmiegDnr irveerq uaensdt erde laadtderde stse s(t9 9f)r

2020-03-16T22:29:30.038Z DEBUG wdio-docker-service: ameworks to prevent access by malicious code.

2020-03-16T22:29:30.855Z DEBUG wdio-docker-service: 22:29:30.870 INFO [ProtocolHandshake.createSession] - Detected dialect: W3C

2020-03-16T22:29:30.919Z DEBUG wdio-docker-service: 22:29:30.934 INFO [RemoteSession$Factory.lambda$performHandshake$0] - Started new session 29c930f81189207ce9af3ddeadcf1107 (org.openqa.selenium.chrome.ChromeDriverService)

[0-0] (node:6155) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:34783
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1126:14)
[0-0] (node:6155) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:6155) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
^Z
[5]+ Stopped npm run test:docker

Error running with chrome debuggerAddress

2020-03-16T22:05:09.898Z DEBUG @wdio/utils:initialiseServices: initialise wdio service "docker"
2020-03-16T22:05:09.903Z DEBUG @wdio/utils:initialiseServices: initialise wdio service "devtools"
2020-03-16T22:05:10.176Z INFO @wdio/cli:launcher: Run onPrepare hook
2020-03-16T22:05:10.177Z DEBUG wdio-docker-service: Docker command: docker run --cidfile /Users/phanagodimath/Desktop/Projects/Martech-Performance/selenium_standalone_chrome.cid --rm -p 4444:4444 -p 9222:9222 --shm-size 2g --hostname selenium selenium/standalone-chrome
2020-03-16T22:05:10.182Z WARN wdio-docker-service: Connecting dockerEventsListener: 5857
2020-03-16T22:05:10.185Z INFO wdio-docker-service: Shutting down running container
2020-03-16T22:05:10.529Z INFO wdio-docker-service: Cleaning up CID files
2020-03-16T22:05:10.581Z INFO wdio-docker-service: Launching docker image 'selenium/standalone-chrome'
2020-03-16T22:05:10.979Z INFO wdio-docker-service: Container started: {
"args": "",
"image": "selenium/standalone-chrome",
"timeStamp": "2020-03-16T22:05:11.004Z",
"type": "container.start",
"status": "start",
"detail": {
"id": "ec657e32cce91f66e021b65a52364b800b5ff2fbccbaad281b97cf9be7924ca3",
"scope": "local",
"actor": {
"ID": "ec657e32cce91f66e021b65a52364b800b5ff2fbccbaad281b97cf9be7924ca3",
"Attributes": {
"authors": "SeleniumHQ",
"image": "selenium/standalone-chrome",
"name": "focused_dirac"
}
}
}
}
2020-03-16T22:05:11.084Z DEBUG wdio-docker-service: 2020-03-16 22:05:11,109 INFO Included extra file "/etc/supervisor/conf.d/selenium.conf" during parsing

2020-03-16T22:05:11.085Z DEBUG wdio-docker-service: 2020-03-16 22:05:11,110 INFO supervisord started with pid 7

2020-03-16T22:05:12.095Z DEBUG wdio-docker-service: 2020-03-16 22:05:12,118 INFO spawned: 'xvfb' with pid 10
2020-03-16 22:05:12,120 INFO spawned: 'selenium-standalone' with pid 11

2020-03-16T22:05:12.548Z DEBUG wdio-docker-service: 22:05:12.572 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358

2020-03-16T22:05:12.548Z DEBUG wdio-docker-service: 2020-03-16 22:05:12,575 INFO success: xvfb entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2020-03-16 22:05:12,575 INFO success: selenium-standalone entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)

2020-03-16T22:05:12.703Z DEBUG wdio-docker-service: 22:05:12.730 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone Selenium Server on port 4444

2020-03-16T22:05:12.805Z DEBUG wdio-docker-service: 2020-03-16 22:05:12.826:INFO::main: Logging initialized @694ms to org.seleniumhq.jetty9.util.log.StdErrLog

2020-03-16T22:05:13.207Z DEBUG wdio-docker-service: 22:05:13.232 INFO [WebDriverServlet.] - Initialising WebDriverServlet

2020-03-16T22:05:13.362Z DEBUG wdio-docker-service: 22:05:13.389 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444

2020-03-16T22:05:13.706Z INFO wdio-docker-service: Docker container is ready
2020-03-16T22:05:13.708Z INFO @wdio/local-runner: Start worker 0-0 with arg: config/wdio.conf.docker.js
[0-0] 2020-03-16T22:05:13.937Z INFO @wdio/local-runner: Run worker command: run
[0-0] RUNNING in chrome - /test/specs/basic_docker.js
[0-0] 2020-03-16T22:05:14.024Z DEBUG @wdio/utils:initialiseServices: initialise wdio service "docker"
[0-0] 2020-03-16T22:05:14.030Z DEBUG @wdio/utils:initialiseServices: initialise wdio service "devtools"
[0-0] 2020-03-16T22:05:14.312Z DEBUG @wdio/local-runner:utils: init remote session
[0-0] 2020-03-16T22:05:14.313Z INFO webdriverio: Initiate new session using the webdriver protocol
[0-0] 2020-03-16T22:05:14.315Z INFO webdriver: [POST] http://127.0.0.1:4444/wd/hub/session
[0-0] 2020-03-16T22:05:14.315Z INFO webdriver: DATA {
capabilities: { alwaysMatch: { browserName: 'chrome' }, firstMatch: [ {} ] },
desiredCapabilities: { browserName: 'chrome' }
}
2020-03-16T22:05:14.461Z DEBUG wdio-docker-service: 22:05:14.490 INFO [ActiveSessionFactory.apply] - Capabilities are: {
"browserName": "chrome"
}

2020-03-16T22:05:14.464Z DEBUG wdio-docker-service: 22:05:14.493 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)

2020-03-16T22:05:14.508Z DEBUG wdio-docker-service: Starting Chro[m1e5D8r4i3v9e6r3 1840.529].[0S.E3V9E8R7E.]1:0 6b i(nfd6(8)0 6f9a5i7l4e6d0:9 2C3a0ncnfo9tb 6a3s5scidg7n8 4rcefqbu1e
2020-03-16T22:05:14.509Z DEBUG wdio-docker-service: bf81bb53a-refs/branch-heads/3987@{#882}) on port 31965

2020-03-16T22:05:14.509Z DEBUG wdio-docker-service: Only local connections are allowed.
Please protect ports used by ChrosmeDtreidv eard darneds sr e(l9a9t)e

2020-03-16T22:05:14.510Z DEBUG wdio-docker-service: d test frameworks to prevent access by malicious code.

2020-03-16T22:05:15.313Z DEBUG wdio-docker-service: 22:05:15.342 INFO [ProtocolHandshake.createSession] - Detected dialect: W3C

2020-03-16T22:05:15.374Z DEBUG wdio-docker-service: 22:05:15.403 INFO [RemoteSession$Factory.lambda$performHandshake$0] - Started new session 0488ca55b2f225efc8fbb340896f129b (org.openqa.selenium.chrome.ChromeDriverService)

[0-0] (node:5874) UnhandledPromiseRejectionWarning: Error: socket hang up
at connResetException (internal/errors.js:561:14)
at Socket.socketOnEnd (_http_client.js:440:23)
at Socket.emit (events.js:214:15)
at Socket.EventEmitter.emit (domain.js:476:20)
at endReadableNT (_stream_readable.js:1178:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
[0-0] (node:5874) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:5874) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
^Z
[4]+ Stopped npm run test:docker

Config of WebdriverIO

exports.config = {
    runner: 'local',
    sync: true,
    path: '/wd/hub',
    specs: [
        './test/specs/basic_docker.js'
    ],
    maxInstances: 10,
    capabilities: [{
        browserName: 'chrome',
    }],
    logLevel: 'debug',
    bail: 0,
    baseUrl: '',
    waitforTimeout: 10000,
    connectionRetryCount: 3,
    services: ['docker', ['devtools', { debuggerAddress: 'localhost:9222' }]],
    dockerOptions: {
        image: 'selenium/standalone-chrome',
        healthCheck: {
            url: 'http://localhost:4444',
            maxRetries: 3,
            inspectInterval: 1000,
            startDelay: 2000
        },
        options: {
            p: ['4444:4444', '9222:9222'],
            shmSize: '2g',
            hostname: 'selenium'
        }
    },
    framework: 'mocha',
    reporters: [
        ['allure', { outputDir: 'allure-results' }]
    ],
    mochaOpts: {
        ui: 'bdd',
        timeout: 180000
    },
    afterTest: function(test, context, { error, result, duration, passed, retries }) {
        if (!passed) {
            browser.takeScreenshot();
        }
    },
}

package.json file

{
    "name": "performance",
    "version": "1.0.0",
    "description": "Performance test for web pages",
    "main": "index.js",
    "scripts": {
        "test:sauce": "wdio ./wdio.conf.sauce.js",
        "test:docker": "wdio config/wdio.conf.docker.js",
        "test:local": "wdio config/wdio.conf.ori.js",
        "test:compose": "wdio wdio.conf.compose.js"
    },
    "author": "Pratik",
    "license": "ISC",
    "devDependencies": {
        "@wdio/allure-reporter": "^5.18.6",
        "@wdio/cli": "^5.15.1",
        "@wdio/devtools-service": "^5.16.16",
        "@wdio/local-runner": "^5.18.7",
        "@wdio/mocha-framework": "^5.18.7",
        "@wdio/sauce-service": "^5.16.10",
        "@wdio/spec-reporter": "^5.18.7",
        "@wdio/sync": "^5.18.7",
        "chromedriver": "^80.0.1",
        "selenium-standalone": "^6.17.0",
        "wdio-chromedriver-service": "^5.0.2",
        "wdio-docker-service": "^2.3.0",
        "wdio-selenium-standalone-service": "0.0.12",
        "webdriverio": "^5.20.2"
    }
}

Test

const assert = require('assert')

describe('Test page - ', () => {
    before(() => {
        browser.enablePerformanceAudits({
            //[offline, GPRS, Regular 2G, Good 2G, Regular 3G, Good 3G, Regular 4G, DSL, Wifi and online]
            networkThrottling: 'Regular 4G',
            // cpuThrottling: 4,
            cacheEnabled: true
        })
    })

    it('Performance test', () => {
        browser.url('https://www.google.com')
        console.log(browser.getMetrics())
        console.log(browser.getDiagnostics())
    })

    after(() => {
        browser.disablePerformanceAudits()
    })
})

Steps to reproduce the behavior

In wdio config, use services: ['docker', ['devtools', { debuggerAddress: 'localhost:9222' }]] and run any simple test.

Expected behavior
Test should run in the docker container along with devtools service which will provide performance metrics.

@stsvilik
Copy link
Collaborator

@Pratikhanagodimath I don't believe Chrome runs debugger by default. You may need to turn it on through flags (Ex. --remote-debugging-port=9222)

@Pratikhanagodimath
Copy link
Author

@stsvilik thanks!. I have tried it but seem to be getting "Error: socket hang up". Below is my config and error message.

config

exports.config = {
    runner: 'local',
    sync: true,
    path: '/wd/hub',
    specs: [
        './test/specs/basic_docker.js'
    ],
    maxInstances: 10,
    capabilities: [{
        browserName: 'chrome',
        'goog:chromeOptions': {
            args: ['--remote-debugging-port=9222', '--whitelisted-ips', '--disable-gpu', '--no-sandbox', '--disable-extensions', '--disable-dev-shm-usage', '--headless']
        },
    }],
    logLevel: 'debug',
    bail: 0,
    baseUrl: '',
    waitforTimeout: 10000,
    connectionRetryCount: 3,
    services: ['docker', ['devtools', { debuggerAddress: 'localhost:9222' }]],
    dockerOptions: {
        image: 'selenium/standalone-chrome',
        healthCheck: {
            url: 'http://localhost:4444',
            maxRetries: 3,
            inspectInterval: 1000,
            startDelay: 2000
        },
        options: {
            p: ['4444:4444', '9222:9222'],
            shmSize: '2g'
        }
    },
    framework: 'mocha',
    reporters: [
        ['allure', { outputDir: 'allure-results' }]
    ],
    mochaOpts: {
        ui: 'bdd',
        timeout: 180000
    },
    afterTest: function(test, context, { error, result, duration, passed, retries }) {
        if (!passed) {
            browser.takeScreenshot();
        }
    },
}

ERROR

2020-03-18T03:04:51.237Z DEBUG @wdio/utils:initialiseServices: initialise wdio service "docker"
2020-03-18T03:04:51.242Z DEBUG @wdio/utils:initialiseServices: initialise wdio service "devtools"
2020-03-18T03:04:51.501Z INFO @wdio/cli:launcher: Run onPrepare hook
2020-03-18T03:04:51.502Z DEBUG wdio-docker-service: Docker command: docker run --cidfile /Users/phanagodimath/Desktop/Projects/Martech-Performance/selenium_standalone_chrome.cid --rm -p 4444:4444 -p 9222:9222 --shm-size 2g selenium/standalone-chrome
2020-03-18T03:04:51.507Z WARN wdio-docker-service: Connecting dockerEventsListener: 14852
2020-03-18T03:04:51.510Z INFO wdio-docker-service: Cleaning up CID files
2020-03-18T03:04:51.567Z INFO wdio-docker-service: Launching docker image 'selenium/standalone-chrome'
2020-03-18T03:04:54.692Z INFO wdio-docker-service: Docker container is ready
2020-03-18T03:04:54.694Z INFO @wdio/local-runner: Start worker 0-0 with arg: config/wdio.conf.docker.js
[0-0] 2020-03-18T03:04:54.923Z INFO @wdio/local-runner: Run worker command: run
[0-0] RUNNING in chrome - /test/specs/basic_docker.js
[0-0] 2020-03-18T03:04:55.001Z DEBUG @wdio/utils:initialiseServices: initialise wdio service "docker"
[0-0] 2020-03-18T03:04:55.006Z DEBUG @wdio/utils:initialiseServices: initialise wdio service "devtools"
[0-0] 2020-03-18T03:04:55.283Z DEBUG @wdio/local-runner:utils: init remote session
[0-0] 2020-03-18T03:04:55.284Z INFO webdriverio: Initiate new session using the webdriver protocol
[0-0] 2020-03-18T03:04:55.286Z INFO webdriver: [POST] http://127.0.0.1:4444/wd/hub/session
[0-0] 2020-03-18T03:04:55.286Z INFO webdriver: DATA {
capabilities: {
alwaysMatch: { browserName: 'chrome', 'goog:chromeOptions': [Object] },
firstMatch: [ {} ]
},
desiredCapabilities: { browserName: 'chrome', 'goog:chromeOptions': { args: [Array] } }
}
[0-0] (node:14867) UnhandledPromiseRejectionWarning: Error: socket hang up
at connResetException (internal/errors.js:561:14)
at Socket.socketOnEnd (_http_client.js:440:23)
at Socket.emit (events.js:214:15)
at Socket.EventEmitter.emit (domain.js:476:20)
at endReadableNT (_stream_readable.js:1178:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
[0-0] (node:14867) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14867) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
^Z
[8]+ Stopped npm run test:docker

@stsvilik
Copy link
Collaborator

@Pratikhanagodimath just for the sake of following order of elimination - a) did you try running tests w/o devtools and b) have tried running docker image selenium/standalone-chrome with debugging enabled in a stand-alone mode?

@Pratikhanagodimath
Copy link
Author

@stsvilik
a)

  • The test runs fine when I do not use 'devtools' as a service.

  • On using devtools as a service, if I do not mention debuggerAddress, I get error --> "UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:34783
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1126:14)". Full details of error is mentioned in the question above.

  • On using devtools as a service with debugger address and the remote port option as suggested by you, I get the error --> "UnhandledPromiseRejectionWarning: Error: socket hang up" as mentioned in the comment above.

b)

  • I added the automation files to selenium/standalone-chrome and below is the dockerfile I used. The devtools was enabled as a service and the test ran fine within the container running the image created by the dockerfile.

Dockerfile

FROM selenium/standalone-chrome

RUN sudo apt-get -qqy update
RUN sudo apt-get -qqy install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
RUN curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
RUN sudo apt-get -qqy update
RUN curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
RUN sudo apt-get -qqy --no-install-recommends install \
  nodejs
RUN export DISPLAY=:99.0
RUN Xvfb :99 -shmem -screen 0 1366x768x16 &
ADD . /app
WORKDIR /app
RUN sudo npm install

Output when tests ran within the container

[0-0] RUNNING in chrome - /test/specs/basic_docker.js
[0-0] { estimatedInputLatency: 17,
  timeToFirstByte: 107,
  domContentLoaded: 400,
  firstVisualChange: 358,
  firstPaint: 324,
  firstContentfulPaint: 324,
  firstMeaningfulPaint: 369,
  lastVisualChange: 11025,
  firstCPUIdle: 994,
  firstInteractive: 994,
  load: 1103,
  speedIndex: 684 }
[0-0] { numRequests: 26,
  numScripts: 5,
  numStylesheets: 0,
  numFonts: 2,
  numTasks: 893,
  numTasksOver10ms: 16,
  numTasksOver25ms: 5,
  numTasksOver50ms: 3,
  numTasksOver100ms: 1,
  numTasksOver500ms: 0,
  rtt: 18.903,
  throughput: 12683378.552524548,
  maxRtt: 24.676000000000002,
  maxServerLatency: 73.99599999999998,
  totalByteWeight: 475705,
  totalTaskTime: 867.3350000000004,
  mainDocumentTransferSize: 62701 }
[0-0] PASSED in chrome - /test/specs/basic_docker.js

@stsvilik
Copy link
Collaborator

@Pratikhanagodimath for b) I meant starting a docker image with Chrome exposing debugger interface on port 9222. If port is active and mapped properly to localhost, you can hit it to see if its working with something like http://localhost:9222/json/version.

My suspicion is that devtools service is designed to work with local binary files via puppeteer and thus can't hit a remote debug interface exposed via docker.

@Pratikhanagodimath
Copy link
Author

@stsvilik Sorry for my delayed response. I tried what you asked and got back a response. Detailed below:

  • Ran the image: docker run -p 4444:4444 -p 9222:9222 selenium/standalone-chrome
  • Started chrome: /usr/bin/google-chrome-stable --headless --no-sandbox --remote-debugging-port=9222 --remote-debugging-address=0.0.0.0 --disable-gpu
  • Got below response by hitting http://localhost:9222/json/version
{
   "Browser": "HeadlessChrome/80.0.3987.106",
   "Protocol-Version": "1.3",
   "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/80.0.3987.106 Safari/537.36",
   "V8-Version": "8.0.426.19",
   "WebKit-Version": "537.36 (@f68069574609230cf9b635cd784cfb1bf81bb53a)",
   "webSocketDebuggerUrl": "ws://localhost:9222/devtools/browser/5c03c503-52c4-4a45-9bb2-62925ca04a09"
}

So it does work. Strange that it did not work as per wdio config mentioned above. I still get "socket hung up" error.

@hugoeanogueira
Copy link

@Pratikhanagodimath Any luck?

We had some troubles configuring docker and devtools services together, because there were a lot of hidden details we were not figuring out at first.

For our setup, we want to run the wdio process in the host machine, pointing to a docker instance with Chrome. Ideally, the browser can also access our development webpack instance (host machine) for better DX. Recapping, we have our host machine running 2 processes, webpack in dev mode (optional) and wdio tests, and the docker instance running Google Chrome, with exposed devtools to the network.

From what we understood, you need to take into account:

  • devtools can only be accessed from the network when the browser is headless (0.0.0.0:9200 alone is not enough).
  • if you want to access something running in the host machine from within docker, you cannot override the localhost even with addHost argument, so it's better to use a custom domain pointing back to the host machine.

I think the minimum configs we need for this setup are the following:

module.exports = {
  runner: 'local',
  sync: true,
  hostname: '127.0.0.1',
  port: 4444,
  protocol: 'http',
  path: '/wd/hub',
  capabilities: [
    {
      maxInstances: 1,
      browserName: 'chrome',
      'goog:chromeOptions': {
        args: [
          '--no-sandbox',
          '--disable-gpu',
          '--incognito',
          '--remote-debugging-address=0.0.0.0', // expose to calls from the host machine!
          '--remote-debugging-port=9222',
          '--headless', // must be headless to use the the docker service with devtools support!
          '--window-size=1366,768'
        ]
      }
    }
  ],
  baseUrl: 'http://custom-local-domain.com:8080', // running webpack on the host machine
  services: [
    [ 'devtools', { debuggerAddress: `localhost:9222` } ],
    'docker'
  ],
  dockerLogs: './',
  dockerOptions: {
    image: 'selenium/standalone-chrome-debug:3.141.59-20200826', // contains Chrome 85.0.4183.83
    healthCheck: {
      url: 'http://localhost:4444',
      maxRetries: 3,
      inspectInterval: 1000,
      startDelay: 2000
    },
    options: {
      // VNC and Selenium hub are already exposed in docker image, so we only need to add the
      // port for devtools
      expose: [ 9222 ],
      p: [
        '4444:4444',
        '5900:5900',
        '0.0.0.0:9222:9222' // 0.0.0.0 to expose devtools debugger from any location
      ],
      addHost: [
        // optional -> expose webpack from host machine (192.168.1.10)
        `custom-local-domain.com:192.168.1.10`,
      ],
      shmSize: '2g'
    }
  },
  onDockerReady: () => {
    console.log('Ready to connect VNC client on localhost:5900');
  }
}

The VNC configuration is included too, because some of our tests can run with open browser, as they don't require devtools access.
Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants