Search code examples
seleniumjenkinsprotractor

Getting SessionNotCreatedError when trying to run scripts from Jenkins pipeline


I am trying to run my protractor scripts on jenkins pipeline and getting the SessionNotCreatedError when it tries to access the Selenium address. When I run the same on local its working fine. Not sure what's going on.

Conf.js script

let domainName = util.domainName;
exports.config = {
  seleniumAddress: 'http://selenium-hub:4444/wd/hub', //for testing in the pipeline
  directConnect: false, // Set to true for local testing, or provide a link to a running selenium grid.
  // specs: ['e2e/**/mailbox-test.js', 'e2e/**/email-dumps-test.js'],
  specs: ['e2e/**/*-test.js'],
  capabilities: {
    browserName: 'chrome',
    acceptInsecureCerts: true,
    'goog:chromeOptions': {
      w3c: false,
      args: [
        '--no-sandbox',
        '--headless',
        '--disable-gpu',
        '--window-size=1200,1200',
        '--disable-dev-shm-usage',
        '--allow-insecure-localhost',
        '--allow-running-insecure-content',
        '--ignore_ssl',
        '--user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36',
      ],
    },
  },

  allScriptsTimeout: 600000,
  baseUrl: eaUrl,
  framework: 'jasmine',

  jasmineNodeOpts: {
    isVerbose: true,
    showColors: true,
    includeStackTrace: true,
    defaultTimeoutInterval: 600000,
    stackTrace: false
  },

Jenkins output error

[15:32:21] D/launcher - Protractor version: 5.4.2 10:31:59 [15:32:21] D/launcher - Your base url for tests is https://ea-webapp-int-raven.ocp-nonprod.ice.dhs.gov/ 10:31:59 [15:32:21] I/launcher - Running 1 instances of WebDriver 10:31:59 [15:32:21] I/hosted - Using the selenium server at http://selenium-hub:4444/wd/hub 10:37:05 [15:37:21] E/launcher - Could not start a new session. New session request timed out 10:37:05 Build info: version: '4.1.2', revision: '9a5a329c5a' 10:37:05 System info: host: 'eb3088c85a9d', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-1160.53.1.el7.x86_64', java.version: '11.0.13' 10:37:05 Driver info: driver.version: unknown 10:37:05 [15:37:21] E/launcher - SessionNotCreatedError: Could not start a new session. New session request timed out 10:37:05 Build info: version: '4.1.2', revision: '9a5a329c5a' 10:37:05 System info: host: 'eb3088c85a9d', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-1160.53.1.el7.x86_64', java.version: '11.0.13' 10:37:05 Driver info: driver.version: unknown 10:37:05
at Object.throwDecodedError (/app/test/node_modules/selenium-webdriver/lib/error.js:514:15) 10:37:05 at parseHttpResponse (/app/test/node_modules/selenium-webdriver/lib/http.js:519:13) 10:37:05 at doSend.then.response (/app/test/node_modules/selenium-webdriver/lib/http.js:441:30) 10:37:05 at process._tickCallback (internal/process/next_tick.js:68:7) 10:37:05 From: Task: WebDriver.createSession() 10:37:05 at Function.createSession (/app/test/node_modules/selenium-webdriver/lib/webdriver.js:769:24) 10:37:05 at Function.createSession (/app/test/node_modules/selenium-webdriver/chrome.js:761:15) 10:37:05 at createDriver (/app/test/node_modules/selenium-webdriver/index.js:170:33) 10:37:05
at Builder.build (/app/test/node_modules/selenium-webdriver/index.js:626:16) 10:37:05
at Hosted.getNewDriver (/app/test/node_modules/protractor/built/driverProviders/driverProvider.js:53:33) 10:37:05 at Runner.createBrowser (/app/test/node_modules/protractor/built/runner.js:195:43) 10:37:05
at q.then.then (/app/test/node_modules/protractor/built/runner.js:339:29) 10:37:05
at _fulfilled (/app/test/node_modules/q/q.js:834:54) 10:37:05 at /app/test/node_modules/q/q.js:863:30 10:37:05 at Promise.promise.promiseDispatch (/app/test/node_modules/q/q.js:796:13) 10:37:05 [15:37:21] E/launcher - Process exited with error code 199 10:37:05 10:37:05 exitStatus=$? 10:37:05 10:37:05 # Allow the Jenkin pipeline to access and archive any test output. 10:37:05 chmod -R 777 ./test_output/


Solution

  • I am adding my observations as others might need if they get similar issues and this might help them too. After a long long investigation of the console output in Jenkins with my docker installation scripts, I noticed that we are trying to install the latest version of the selenium hub and chrome node but the docker command doesn't include the SE_EVENT_BUS_HOST information. After changing my code from

    docker run -d --name selenium-node-chrome -e HUB_HOST=selenium-hub --shm-size="2g" nexus2.xxx.com:18443/selenium/node-chrome

    to

    docker run -d --name selenium-node-chrome -e SE_EVENT_BUS_HOST=selenium-hub --shm-size="2g" -e SE_EVENT_BUS_PUBLISH_PORT=4442 -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 nexus2.xxx.com:18443/selenium/node-chrome

    Then it started working for me.