How to run a single e2e test with grunts and protractor

I guess this is possible and actually quite simple, but I'm new to both grunts and protractors, and I could not find the answer online (maybe I used the wrong search criteria).

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

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

I am currently doing this:

 grunt e2e 

My protractor configuration 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, these are all my tests, but while I am developing a special test, I do not want to run the entire battery of tests. I want to run this file.

How can i do this? Is there any flag or something else?

thanks

+7
javascript angularjs gruntjs protractor end-to-end
source share
4 answers

You just need to pass the specs parameter to the protractor CLI. The specs option expects a list of JS files to be launched, separated by commas.

You will need to edit the Gruntfile.js file to pass this parameter to the transporter.

+7
source share

As an alternative, organize your tests as a test suite:

 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 the --suite command line --suite :

 protractor protractor.conf.js --suite homepage 

See also: Protractor for AngularJS .

+9
source share

You simply prefix x before the description, which you do not need to run. If you do not want to run a test suit, use the following:

 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
source share

Since you use Grunt + Protractor, I would suggest installing single tests not in 'protractor.conf.js', but in 'Gruntfile.js', using the Grunt-grract-protractor-runner module. This way you can configure as many single or multiple tests as you want with a different configuration

Basically you include it at the top:

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

then configure your task in the grunt.initConfig file as follows:

 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 the Grunt task in the same file:

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

and then run this task with:

 grunt run-test 
0
source share

All Articles