quirimmo
quirimmo

Reputation: 9988

Run selenium jar on travis CI from protractor node_modules folder

I am setting up Travis in order to execute e2e tests through protractor. On my protractor.config.js I have the following:

seleniumServerJar: './node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.5.0.jar'

So actually it refers to the selenium jar included by default inside the protractor plugin.

Then I use the plugin gulp-protractor in order to execute the tests pointing to the right protractor.config.js.

Locally everything works like a charm.

But when trying to execute this on Travis, I am getting the following error:

[18:59:15] I/launcher - Running 1 instances of WebDriver [18:59:15] E/local - Error code: 135 [18:59:15] E/local - Error message: No selenium server jar found at /home/travis/build/quirimmo/Qprotractor/node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.5.0.jar. Run 'webdriver-manager update' to download binaries.

Any idea why it looks like it cannot retrieve the jar from the node_modules subfolder please?

Here my .travis.yml configuration, which is actually pretty simple:

sudo: required
dist: trusty

addons:
  chrome: stable

language: node_js
node_js:
  - '6.11'

before_script:
  - export DISPLAY=:99.0
  - sh -e /etc/init.d/xvfb start
  - sleep 3

install:
  - npm install

script:
  - echo "Triggered!"
  - gulp protractor-test

Thanks a lot, any help would be really appreciated!

p.s. I already did it on other projects with Travis running manually the webdriver-manager and then pointing to the selenium address from the protractor.config.js, but I don't want that solution and I want to go on through the seleniumServerJar property, because in this way it will run everything alone without any need of starting manually the webdriver-manager

Upvotes: 0

Views: 362

Answers (2)

quirimmo
quirimmo

Reputation: 9988

Posting here the answer if this could be useful for someone else in the future. As explained very well in this link:

https://github.com/angular/protractor/issues/3225

You need to manually trigger the installation of the selenium server.

So in the install block of your travis file, you can simply add this:

install:
  - npm install
  - node_modules/protractor/bin/webdriver-manager update

And then inside the protractor.config.js, grab the current version of the installed selenium server:

const SELENIUM_FOLDER = './node_modules/protractor/node_modules/webdriver-manager/selenium';
const fs = require('fs');
let res, seleniumVersion;
fs.readdirSync(SELENIUM_FOLDER).forEach(file => {
    res = file.match(/selenium-server-standalone-(\d{1}.\d{1}.\d{1}).jar/i);
    if (res) {
        seleniumVersion = res[1];
    } 
})
if (!seleniumVersion) {
    throw new Error('No selenium server jar found inside your protractor node_modules subfolder');
}

And then execute it in this way:

seleniumServerJar: `./node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-${seleniumVersion}.jar`

I hope this will help someone else avoiding to lose few hours of time against this issue!

Upvotes: 0

Tarun Lalwani
Tarun Lalwani

Reputation: 146510

Fixed in your repo. You should change your before_script to below

before_script:
  - export DISPLAY=:99.0
  - sh -e /etc/init.d/xvfb start
  - sleep 3
  - npm install -g webdriver-manager
  - webdriver-manager update
  - webdriver-manager start &
  - sleep 3

And then in your protactor.confg.js add the seleniumAddress

exports.config = {
    seleniumAddress: 'http://127.0.0.1:4444/wd/hub/',
    specs: [
        './test/base-protractor.spec.js',
        './test/element-finder.spec.js',
        './test/element-array-finder.spec.js'
    ],
    onPrepare: function() {
        require('./index');
    }
};

Upvotes: 1

Related Questions