Skip to content

Instantly share code, notes, and snippets.

@jsheridanwells
Created June 5, 2018 18:01
Show Gist options
  • Save jsheridanwells/51870fd10371f0c73ce1fa95db55a0b0 to your computer and use it in GitHub Desktop.
Save jsheridanwells/51870fd10371f0c73ce1fa95db55a0b0 to your computer and use it in GitHub Desktop.
An example VSTS Build Definition with Protractor and Grunt

An example VSTS Build Definition with Protractor and Grunt

Let protractor conf call selenium server directly:

'use strict';

exports.config = {
    framework: 'jasmine',
    // seleniumAddress: 'http://localhost:4444/wd/hub',
    seleniumServerJar: '../node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.12.0.jar',
    specs: ['spec.js']
}

Gruntfile:

module.exports = function(grunt) {

    grunt.initConfig({
        protractor: {
            options: {
                configFile: 'tests/conf.js',
                noColor: false,
                args: {

                }
            },
            e2e: {
                options: {
                    keepAlive: false
                }
            },
            continuous: {
                options: {
                    keepAlive: true
                }
            }
        },

        watch: {
            options: {
                livereload: true
            },
            protractor: {
                files: ['tests/*.js'],
                tasks: ['protractor:continuous']
            }
        },

        run: {
            mock_server: {
                options: {
                    wait: false
                },
                args: []
                // args: ['app/mockApi/apiserver.js']
            }
        },

        connect: {
            options: {
                port: 9000,
                hostname: 'localhost'
            },
            livereload: {
                options: {
                    livereload: 35729,
                    open: true,
                    base: ['']

                }
            },
            test: {
                options: {
                    base: ['./']
                }
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.loadNpmTasks('grunt-protractor-runner');
    grunt.loadNpmTasks('grunt-run');

    grunt.registerTask('default', ['connect:test', 'protractor:e2e']);

};

package.json:

{
  "name": "calculator_protractor_demo",
  "version": "1.0.0",
  "description": "",
  "main": "src/app.js",
  "directories": {
    "test": "tests"
  },
  "scripts": {
    "grunt": "node_modules/.bin/grunt",
    "test": "node_modules/.bin/protractor tests/conf.js",
    "webdriver:update": "node_modules/.bin/webdriver-manager update",
    "webdriver:start": "node_modules/.bin/webdriver-manager start"
  },
  "repository": {
    "type": "git",
    "url": "https://jsheridanwells.visualstudio.com/Calculator_Protractor_Demo/_git/Calculator_Protractor_Demo"
  },
  "author": "jsheridanwells",
  "license": "MIT",
  "dependencies": {
    "angular": "^1.7.0",
    "protractor": "^5.3.2",
    "grunt": "1.0.3",
    "grunt-contrib-connect": "1.0.2",
    "grunt-contrib-watch": "1.1.0",
    "grunt-protractor-runner": "5.0.0",
    "grunt-run": "0.8.1",
    "grunt-cli": "1.2.0"
  }
}

Build Tasks

Select Grunt task template.

  1. npm install
  2. npm run webdriver:update
  3. Run Grunt Task
  4. Archive Files Publish Artifacts: drop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment