最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to run single e2e test with grunt and protractor - Stack Overflow

programmeradmin5浏览0评论

I'm assuming this is possible and actually pretty simple, but I'm new to both grunt and protractor and I was not able to find the answer online (maybe I used wrong search criteria).

I have the following e2e test in file test/e2e/Recipients.js:

describe('Recipients Tab', function() {

    beforeEach(function () {
        browser.get('#/recipients');
    });

    it('should have no e-mail list', function () {
        expect(element(by.css('accordion')).isPresent()).toBe(false);
    });
});

Currently, I'm doing this:

grunt e2e

My protractor config file:

exports.config = {
    seleniumAddress: 'http://localhost:4444/wd/hub',
    capabilities: {
        'browserName': 'chrome'
    },
    specs: ['../e2e/**/*.js'],
    baseUrl : 'http://localhost:8080/spr',

    jasmineNodeOpts: {
        showColors: true // Use colors in the command line report.
    }
};

Of course this runs all my tests, but while I'm developing a specific test, I don't want to run the entire battery of tests. I want to run this one file.

How can I do that? Is there any flag or something?

Thanks

I'm assuming this is possible and actually pretty simple, but I'm new to both grunt and protractor and I was not able to find the answer online (maybe I used wrong search criteria).

I have the following e2e test in file test/e2e/Recipients.js:

describe('Recipients Tab', function() {

    beforeEach(function () {
        browser.get('#/recipients');
    });

    it('should have no e-mail list', function () {
        expect(element(by.css('accordion')).isPresent()).toBe(false);
    });
});

Currently, I'm doing this:

grunt e2e

My protractor config file:

exports.config = {
    seleniumAddress: 'http://localhost:4444/wd/hub',
    capabilities: {
        'browserName': 'chrome'
    },
    specs: ['../e2e/**/*.js'],
    baseUrl : 'http://localhost:8080/spr',

    jasmineNodeOpts: {
        showColors: true // Use colors in the command line report.
    }
};

Of course this runs all my tests, but while I'm developing a specific test, I don't want to run the entire battery of tests. I want to run this one file.

How can I do that? Is there any flag or something?

Thanks

Share Improve this question edited May 26, 2015 at 13:12 alecxe 474k126 gold badges1.1k silver badges1.2k bronze badges asked Apr 23, 2014 at 9:25 redwulfredwulf 1,3173 gold badges13 silver badges36 bronze badges 3
  • What does your protractor.conf.js look like? Please edit it into your original question – Tim Commented Apr 23, 2014 at 9:30
  • You can use the specs protractor option to pass a comma-separated list of JS files to execute. You'll need to edit your Gruntfile.js to pass this option to protractor – JB Nizet Commented Apr 23, 2014 at 9:38
  • JB Nizet, I just tried that and it works. Thanks. Want to write an answer I can accept instead? – redwulf Commented Apr 23, 2014 at 10:39
Add a comment  | 

4 Answers 4

Reset to default 9

Alternatively, organize your tests as a set of test suites:

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  capabilities: { 'browserName': 'chrome' },

  suites: {
    homepage: 'tests/e2e/homepage/**/*Spec.js',
    search: ['tests/e2e/contact_search/**/*Spec.js']
  },

  jasmineNodeOpts: { showColors: true }
};

And run only specific test suites, using --suite command line argument:

protractor protractor.conf.js --suite homepage

See also: Protractor for AngularJS.

You just have to pass the specs option to the protractor CLI. The specs option expects a comma-separated list of JS files to run.

You'll need to edit your Gruntfile.js to pass this option to protractor.

Since you're using Grunt+Protractor, I would suggest having single tests setup not in 'protractor.conf.js' but in 'Gruntfile.js' using 'grunt-protractor-runner' Grunt module. So you can setup as many single or multiple tests as you want with different configuration

Basically, you include it at the top:

   grunt.loadNpmTasks('grunt-protractor-runner');

then, setup your task in grunt.initConfig like this:

grunt.initConfig({
.....
.....
.....
      protractor: {
      options: {
        configFile: "protractor.conf.js",
        keepAlive: true // If false, the grunt process stops when the test fails.
    },
    singleTestRun: {
        options: {
            args: {
                baseUrl: "http://yourDomain.com", // setting up base URL here
                specs: [
                    './specs/*.js',
                    './another/specs/*.js'
                ],
                capabilities: {
                    'browserName': 'chrome',
                    shardTestFiles: false
                },
            }
        }
    },
},
.....
.....
.....
});

then, register Grunt task in the same file:

grunt.registerTask('run-test', ['someTaskOne', 'protractor:singleTestRun', 'shell:someshellscript']);

and then, run this task with:

grunt run-test

You just prefixed x before the describe which you no need to run. For exanple if you do not need to run the test suit use as follows ,

xdescribe('Recipients Tab', function() {

beforeEach(function () {
    browser.get('#/recipients');
});

it('should have no e-mail list', function () {
    expect(element(by.css('accordion')).isPresent()).toBe(false);
});

});

发布评论

评论列表(0)

  1. 暂无评论