1
votes

I'm trying to build my testing environment using Jenkins, Selenium and Protractor. I decided to use selenium-plugin (selenium grid) to dispatch tests among remote machines (nodes). What I achieved till now is establishing connection between selenium hub and nodes.

Node.js version installed on Jenkins is 5.12.0, Protractor is 3.3.0. I also installed npm chromedriver and set a path to this driver in protractor.config.js like :

chromeDriver: '/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/chromedriver/bin/chromedriver'

Nodes are running selenium-standalone servers, installed globaly with npm.

When I'm executing my protractor.config.js file I have the following error :

    protractor /u01/apps/jenkins/data/workspace/Servers/testApp/protractor.conf.js
[14:49:08] I/direct - Using ChromeDriver directly...
[14:49:08] I/launcher - Running 1 instances of WebDriver

/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1329
      return callbackFn(this.value_);
             ^
Error: Server terminated early with status 127
    at Error (native)
    at /u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/remote/index.js:210:20
    at Promise.invokeCallback_ (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1329:14)
    at TaskQueue.execute_ (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2790:14)
    at TaskQueue.executeNext_ (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2773:21)
    at /u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2652:27
    at /u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:639:7
    at process._tickCallback (internal/process/next_tick.js:103:7)
From: Task: WebDriver.createSession()
    at acquireSession (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:62:22)
    at Function.createSession (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:295:12)
    at Driver (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/selenium-webdriver/chrome.js:778:38)
    at Direct.getNewDriver (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/built/driverProviders/direct.js:65:26)
    at Runner.createBrowser (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/built/runner.js:182:43)
    at /u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/built/runner.js:255:30
    at _fulfilled (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/q/q.js:834:54)
    at self.promiseDispatch.done (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/q/q.js:863:30)
    at Promise.promise.promiseDispatch (/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/q/q.js:796:13)
    at /u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/protractor/node_modules/q/q.js:556:49
[14:49:08] E/launcher - Process exited with error code 1

Here is my protractor config file:

exports.config = {
    directConnect: true,
    chromeDriver: '/u01/apps/jenkins/data/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_5.12.0/lib/node_modules/chromedriver/bin/chromedriver',
    framework: 'jasmine',
    capabilities: {
        'browserName': 'chrome',
        shardTestFiles: true,
        maxInstances: 3
    },
    specs: ['test/test_spec.js'],
    jasmineNodeOpts: {
        showColors: true,
        defaultTimeoutInterval: 30000,
    },
    seleniumAddress: 'http://HUB_IP:4444/wd/hub',
    onPrepare: function() {
        browser.driver.manage().window().maximize();
    },
    plugins: [{
        package: 'protractor-console',
        logLevels: ['severe', 'debug', 'info', 'warning']
    }]
};
1

1 Answers

2
votes

You need to directConnect: false, so it will use the selenium server through seleniumAddress: 'http://HUB_IP:4444/wd/hub', and given you are on Jenkins, probably in headless mode I recommend you to use docker-selenium

Start the local grid

CONTAINER_ID="grid_$BUILD_NUMBER"
docker run -d --name=$CONTAINER_ID -v /dev/shm:/dev/shm elgalu/selenium

Wait for it to start

docker exec $CONTAINER_ID wait_all_done 40s

Grab the IP

export HUB_IP=$(docker inspect -f='{{.NetworkSettings.IPAddress}}' $CONTAINER_ID)

Run your tests

protractor testApp/protractor.conf.js