Javascript 如何使用grunt和量角器运行单个e2e测试
我假设这是可能的,而且实际上相当简单,但我对grunt和Gradurator都是新手,我无法在网上找到答案(可能我使用了错误的搜索条件) 我在文件Javascript 如何使用grunt和量角器运行单个e2e测试,javascript,angularjs,gruntjs,protractor,end-to-end,Javascript,Angularjs,Gruntjs,Protractor,End To End,我假设这是可能的,而且实际上相当简单,但我对grunt和Gradurator都是新手,我无法在网上找到答案(可能我使用了错误的搜索条件) 我在文件test/e2e/Recipients.js中有以下e2e测试: describe('Recipients Tab', function() { beforeEach(function () { browser.get('#/recipients'); }); it('should have no e-mai
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.
}
};
当然,这会运行我所有的测试,但是当我开发一个特定的测试时,我不想运行所有的测试。我想运行这个文件
我该怎么做?有国旗什么的吗
谢谢您只需在“描述”前面加上前缀,无需运行。例如,如果您不需要运行测试套件,请按以下方式使用:
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);
});
})) 您只需将
specs
选项传递给量角器CLI即可。specs选项要求运行一个以逗号分隔的JS文件列表
您需要编辑Gruntfile.js以将此选项传递给量角器。或者,将测试组织为一组: 并使用
--suite
命令行参数仅运行特定的测试套件:
protractor protractor.conf.js --suite homepage
另请参见:.因为您使用的是Grunt+量角器,所以我建议不要在'pregrator.conf.js'中设置单个测试,而是在'Gruntfile.js'中使用'Grunt-pregrator-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
你的dragrator.conf.js看起来像什么?请将其编辑到原始问题中。您可以使用
specs
量角器选项传递要执行的JS文件的逗号分隔列表。您需要编辑Gruntfile.js,才能将此选项传递给grandorjb Nizet,我刚刚尝试了这个方法,效果很好。谢谢想写一个我可以接受的答案吗?我不知道这一点,它很有用,但据我所知,每次我想测试不同的东西,我需要在所有其他规格中添加x。我想要与maven类似的东西:mvn-Dtest=com.project.MyTestClasstest@redwulf您是否在Gragotor中发现了grunt可以像mvn一样执行单个测试的内容?谢谢你的帮助!grunt e2e--specs='js/test/e2e/PreviewSpec.js'适合我。谢谢,我不知道这件事。有用的东西
grunt run-test