Home > Back-end >  Issue trying to run javascript unit tests with Intern through a Chrome Driver on a Selenium Docker I
Issue trying to run javascript unit tests with Intern through a Chrome Driver on a Selenium Docker I

Time:11-12

I'm trying to run my javascript unit tests with Intern through a Chrome Driver on a Selenium Docker Image (Note: These tests run fine for me through local versions of Intern and Selenium). So far I have done the following 5 steps:

  1. Pulled down Standalone Chrome image: docker pull selenium/standalone-chrome

  2. Ran a Standalone Chrome container: docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-chrome

  3. Manually installed a Chrome Driver onto the Standalone Chrome image using a DockerFile:

# We need wget to set up the PPA and xvfb to have a virtual screen and unzip to install the Chromedriver
RUN sudo apt-get install -y wget xvfb unzip

# Set up the Chrome PPA
RUN sudo wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -

# Update the package list and install chrome
RUN sudo apt-get update -y
RUN sudo apt-get install -y google-chrome-stable

# Set up Chromedriver Environment variables
ENV CHROMEDRIVER_VERSION 2.19
ENV CHROMEDRIVER_DIR /chromedriver
RUN sudo mkdir $CHROMEDRIVER_DIR

# Download and install Chromedriver
RUN sudo wget -q --continue -P $CHROMEDRIVER_DIR "http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip"
RUN sudo unzip $CHROMEDRIVER_DIR/chromedriver* -d $CHROMEDRIVER_DIR

# Put Chromedriver into the PATH
ENV PATH $CHROMEDRIVER_DIR:$PATH 
  1. Set up my Intern configuration file:
        proxyPort: 9000,

        // A fully qualified URL to the Intern proxy
        proxyUrl: 'http://localhost:9000/',

        // Default desired capabilities for all environments. Individual capabilities can be overridden by any of the
        maxConcurrency: 3,

        // Whether or not to start Sauce Connect before running tests
        useSauceConnect: false,
        
        capabilities: {
            'selenium-version': '4.0.0',
            'seleniumProtocol': 'WebDriver',
            'browserName': 'chrome', 
            'platform': 'Linux',
            'version': '95.0',
            'ignoreProtectedModeSettings': true,
            'chromeOptions': {
              'args': [ '-incognito', '--no-sandbox', '--disable-dev-shm-usage', '--headless' ]
            }
        },

        environments: [
            { browserName: "chrome", 'platform': 'Linux', 'version': '95.0'}
        ],

        runnerClientReporter: {
            writeHtml: false
        },
    
        tunnel: 'NullTunnel',
    
        webdriver: {
            host: 'localhost',
            port: 4444,
        }, 
  1. Run the javascript tests which throws the following error:
[exec] [10:39:17] Starting 'intern-tests'...
     [exec] (node:80584) Warning: Accessing non-existent property 'VERSION' of module exports inside circular dependency
     [exec] (Use `node --trace-warnings ...` to show where the warning was created)
     [exec] SUITE ERROR
     [exec] UnknownError: [POST http://localhost:4444/wd/hub/session/b63ae473e271e0927ede8816720cf81e/url / {"url":"http://localhost:9000/__intern/client.html?config=intern-config/intern-config.js&reporters={"writeHtml":false,"id":"WebDriver"}&basePath=/&initialBaseUrl=/&rootSuiteName=chrome 95.0 on Linux - unit tests&sessionId=b63ae473e271e0927ede8816720cf81e"}] unknown error: net::ERR_CONNECTION_REFUSED
     [exec]   (Session info: headless chrome=95.0.4638.54)
     [exec] Build info: version: '4.0.0', revision: '3a21814679'
     [exec] System info: host: '64d03736d73e', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.47-linuxkit', java.version: '11.0.11'
     [exec] Driver info: driver.version: unknown

Based on the error saying Driver info: driver.version: unknown I tried Step 3 above (Manually installed a Chrome Driver) so I'm not sure if this error is giving out about a Chrome driver at all anymore, I think that may be set up correctly.

CodePudding user response:

Completely remove step 3

Official selenium docker images like selenium//standalone-chrome have the browser and respective driver installed.

Update Configuration for step 4

Remove all traces of the following variables with it's respective values:

platform; version;

Also noted the proxy configuration

// A fully qualified URL to the Intern proxy
        proxyUrl: 'http://localhost:9000/',

Based on the above you are declaring that the proxy is installed on your local machine, however when you send your driver request to the chrome node, the Chrome browser will translate that the proxy is implemented on localhost:9000 which is the platform that it is installed on (i.e. the Docker container).

You need to update the intern proxy config with the ip of your local machine which is hosting your proxy and Docker container (i.e. proxyUrl: 'http://192.168.111.222:9000/)

You could also update it with a domain name of your choice (e.g. my-machine), but you would need to update your Docker command with:

--add-host=my-machine:<ip-address>

so your docker run cmd would look like this:

docker run -d -p 4444:4444 -v /dev/shm:/dev/shm --add-host=my-machine:192.168.111.222 selenium/standalone-chrome

Local machine hosts file updated:

127.0.0.1       my-machine

Intern configuration:

// A fully qualified URL to the Intern proxy
        proxyUrl: 'http://my-machine:9000/',
  • Related