简体   繁体   English

如何使用grunt和量角器进行单e2e测试

[英]How to run single e2e test with grunt and protractor

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 : 我在文件test/e2e/Recipients.js有以下e2e测试:

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 谢谢

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: 并使用--suite命令行参数仅运行特定的测试套件:

protractor protractor.conf.js --suite homepage

See also: Protractor for AngularJS . 另请参见: AngularJS的量角器

You just have to pass the specs option to the protractor CLI. 您只需将specs选项传递给量角器CLI即可。 The specs option expects a comma-separated list of JS files to run. specs选项需要运行以逗号分隔的JS文件列表。

You'll need to edit your Gruntfile.js to pass this option to protractor. 您需要编辑Gruntfile.js以将此选项传递给量角器。

You just prefixed x before the describe which you no need to run. 您只需在描述之前为x添加前缀,而不需要运行。 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);
});

}); });

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. 由于您正在使用Grunt + Protractor,我建议不要在'protractor.conf.js'中设置单个测试,而在'Gruntfile.js'中使用'grunt-protractor-runner'Grunt模块设置。 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中设置你的任务,如下所示:

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任务:

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

and then, run this task with: 然后,运行此任务:

grunt run-test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM