Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting started with Protractor, Travis and SauceLabs

I'm trying to get my open source project tests up and running within Travis CI. I have them working locally using a Selenium server.

Seems a relatively simple process but I am lacking some basic knowledge to complete the task.

I have my .travis.yml file:

language: node_js
node_js:
  - "0.10"

env:
  global:
    - SAUCE_USERNAME=[my-username]
    - SAUCE_ACCESS_KEY=[my-key]

addons:
  sauce_connect: true

before_install:
  - npm install -g grunt-cli

my Protractor config:

exports.config = {
    sauceUser: process.env.SAUCE_USERNAME,
    sauceKey: process.env.SAUCE_ACCESS_KEY,

    capabilities: {
      'browserName': 'chrome',
      'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER,
      'build': process.env.TRAVIS_BUILD_NUMBER,
      'name': 'ngValidation Protractor Tests'
    },

    specs: ['demo/app/features/home/specs/*.spec.js'],

    jasmineNodeOpts: {
  showColors: true,
      defaultTimeoutInterval: 30000
    },

    baseUrl: 'http://localhost:' + (process.env.HTTP_PORT || '8000')
};

and Gruntfile

protractor: {
    saucelabs: {
        options: {
            configFile: "saucelabs.spec.conf.js",
            args: {
                sauceUser: process.env.SAUCE_USERNAME,
                sauceKey: process.env.SAUCE_ACCESS_KEY
            }
        }
    }
}

...the problem

I think everything is setup correctly however something must be missing because when I push to Github and the Travis CI build kicks off I start getting this error in the Travis build logs:

Could not proxy http://localhost:8000....

What am I missing to get these two talking to each other and running my tests?

The Travis build logs for full info: https://travis-ci.org/GrumpyWizards/ngValidation/builds/23264543


Edit: based on the accepted answer:

I wasn't running a server to serve my files! I ended up installing https://www.npmjs.org/package/grunt-contrib-connect and set up my Grunt file like so:

connect: {
  server: {
    options: {
      hostname: 'localhost',
      port: 9001
    }
  }
}
...
grunt.registerTask('travis', ['connect:test', 'protractor:saucelabs']);

I then changed my protractor config file like this:

baseUrl: 'http://localhost:9001/'

Hey presto I can now run a local server on either my machine or on Travis that now serves my files, files that SauceLabs can gain access to...

like image 260
Greg Avatar asked Apr 18 '14 08:04

Greg


1 Answers

Basing on the logs you provided, I can see that Selenium is trying to connect to localhost:8000 where your application should be. Yet I don't see travis running the server there first.

According to the Sauce Labs Travis integration guide:

Make sure you make Travis start your webapp before the tests start. Your application needs to be serving pages to be able to test it using our browsers.

You can run commands in the background by appending & to them:

before_script:
  - ./my_server &
  - sleep 2 # give it some time to start
like image 69
Michał Miszczyszyn Avatar answered Sep 28 '22 06:09

Michał Miszczyszyn