7

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

4

4 回答 4

9

或者,将您的测试组织为一组测试套件

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 }
};

并且只运行特定的测试套件,使用--suite命令行参数:

protractor protractor.conf.js --suite homepage

另请参阅:AngularJS 量角器

于 2014-08-04T06:19:25.503 回答
8

您只需将specs选项传递给量角器 CLI。specs 选项需要以逗号分隔的 JS 文件列表来运行。

您需要编辑 Gruntfile.js 以将此选项传递给量角器。

于 2014-04-23T11:45:58.293 回答
1

由于您使用的是 Grunt+Protractor,我建议不要在“protractor.conf.js”中设置单个测试,而是在“Gruntfile.js”中使用“grunt-protractor-runner”Grunt 模块。因此,您可以使用不同的配置设置任意数量的单个或多个测试

基本上,您将其包含在顶部:

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

然后,像这样在 grunt.initConfig 中设置你的任务:

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
                },
            }
        }
    },
},
.....
.....
.....
});

然后,在同一个文件中注册 Grunt 任务:

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

然后,使用以下命令运行此任务:

grunt run-test
于 2017-04-07T20:29:12.463 回答
0

您只是在不需要运行的描述之前添加了 x 前缀。例如,如果您不需要运行测试套件,请按如下方式使用,

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);
});

});

于 2014-04-23T09:56:41.250 回答