Getting started with Protractor, Travis and SauceLabs
Asked Answered
M

1

7

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...

Maccaboy answered 18/4, 2014 at 8:42 Comment(4)
I think it would be even more helpful if you showed full Travis log. It may contain something you might have missed. It's also important at which stage this message is shown?Delvalle
@Miszy ok updated the question with a link at the bottom. Is that correct?Maccaboy
"Request started: GET localhost:8000/demo/index.html" I don't see the server running on port 8000. Are you sure it's there?Delvalle
Ah, ok, that makes more sense. The server runs on Travis not on SauceLabs, how do I get a server running on Travis that SauceLabs connects to? grunt express?Maccaboy
R
5

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
Railway answered 18/4, 2014 at 9:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.