1
votes

I have a Grunt task called "test". The responsibility of this task is the execute end-to-end tests. Currently, I can run my tests if I start the grunt-protractor-runner in a seperate command-line window. I start that by executing the following command:

node_modules\grunt-protractor-runner\node_modules\protractor\bin\webdriver-manager start

My question is, is there a way I can start this as part of my grunt task if the webdriver-manager hasn't already been started? If so, how? I've seen tasks like grunt-contrib-connect, yet I don't see how those allow me to get my test server running as part of a task.

2

2 Answers

2
votes

protractor will take care of starting the selenium server for you if you don't define seleniumAddress in the protractor config file.

It seems like you're pretty much there. Your 'test' task should first start up a server using grunt-contrib-connect to serve the app you want to test. That task should then use grunt-protractor-runner to start protractor and protractor will start the selenium server (assuming seleniumAddress=null).

Something like the following:

connect: {
  test: {
    options: {
      port: 9001,
      base: [
        'app'
      ]
    }
  }
}

protractor: {
  options: {
    keepAlive: true,
    configFile: 'protractor.conf.js'
  },
  run: {}
}

grunt.registerTask('test', [
  'connect:test',
  'protractor:run'
]);
0
votes

To start webdriver automatically put following in your grunt file:

grunt.initConfig: ({
    ..
    protractor: {
        test: {
            options: {
                configFile: 'protractor.conf.js'
            }
        }
    },
    ..    
}    
..
grunt.registerTask('test': ['protractor:test']);

and following in your ./protractor.conf.js

    var chromeDriver =  
        './node_modules/protractor/selenium/chromeDriver';
    var platform = require('os').platform();
    var fs = require('fs');

    var platformChrome = chromeDriver + '-' + platform;
    if (fs.existsSync(platformChrome)){
        log.console('Using ' + platform + ' specific driver ');
        chromeDriver = platformChrome;
    }

    exports.config = {

        directConnect: true,
        chromeDriver: chromeDriver,
        // Capabilities to be passed to the webdriver instance
        capabilities: {
            'browserName': 'chrome',
            'chromeOptions': {
                args: ['--no-sandbox']
            }    
        },
        ..
}

Start your grunt server:

grunt serve;

and in another terminal start your tests:

grunt test