[英]How to run single e2e test with grunt and protractor
我假设这是可能的,实际上非常简单,但我是咕噜咕噜和量角器的新手,我无法在网上找到答案(也许我使用了错误的搜索条件)。
我在文件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);
});
});
目前,我这样做:
grunt e2e
我的量角器配置文件:
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.
}
};
当然这会运行我所有的测试,但是当我开发一个特定的测试时,我不想运行整个测试。 我想运行这个文件。
我怎样才能做到这一点? 有旗帜还是什么?
谢谢
或者,将测试组织为一组测试套件 :
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的量角器 。
您只需将specs
选项传递给量角器CLI即可。 specs选项需要运行以逗号分隔的JS文件列表。
您需要编辑Gruntfile.js以将此选项传递给量角器。
您只需在描述之前为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);
});
});
由于您正在使用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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.