Angular + Protractor + Bamboo

2019-04-13 08:51发布

问题:

Has anyone setup Protractor e2e tests on Bamboo CI?

I've been running my WebDriver tests locally from Grunt via the grunt-protractor-runner / grunt-protractor-webdriver projects. Protractor config is standard. Relevant Grunt config:

grunt.initConfig({
    protractor: {
        options: {
            keepAlive: false,
            noColor: false
        },
        modules: {
            configFile: 'protractor.e2e.conf.js'
        }
    },
    protractor_webdriver: {
        modules: {
            options: {
                path: 'node_modules/protractor/bin/',
                command: 'webdriver-manager start'
            }
        }
    }
});

grunt.registerTask('e2e', [ 'protractor_webdriver', 'protractor' ]);

This works like a charm locally with a simple grunt e2e

Trying to get this working on Bamboo is less than effective. My tasks so far:

  • Checkout repo source
  • npm install
  • webdriver-manager update
  • grunt e2e

The log shows it starting up Selenium server, launching Firefox, then failing with the following error:

UnknownError: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
Error: no display specified

回答1:

When running this from bamboo you should also install something like Xvfb this enables you to start a headless screen that can be used from the commandline.

after installing Xvfb you can start a new screen by running

Xvfb :97 -ac -screen 0 1600x1200x24

in you grunt config you can add a new task

env : {
  xvfb: {
        DISPLAY: ':97'
  }
}

You shoud connect the screen before starting protractor. this can be done with

grunt.registerTask('e2e', [ 'env:xvfb','protractor_webdriver', 'protractor' ]);


回答2:

It might be related to Firefox being launched (by Bamboo) from the console outside of X environment.

You could try modyfing grunt command to tell it explicitely what the display is:

DISPLAY=:0 grunt e2e