7

I am successfully able to run the protractor scripts. Below is the protractor.config.js file which I am using to run the protractor scripts.

var Jasmine2Reporter = require('protractor-jasmine2-screenshot-reporter');
var HtmlReporter = require('protractor-html-screenshot-reporter');

var jReporter=new Jasmine2Reporter({
    dest: './protractor-result', 
    fileName:    'protractor-demo-tests-report.html'
});

var reporter=new HtmlReporter({
    baseDirectory: './protractor-result', // a location to store screen shots.
    docTitle: 'Protractor Demo Reporter',
    docName:    'protractor-demo-tests-report.html'
});

exports.config = {
  allScriptsTimeout: 11000,

  specs: [
    'testCaseOne.spec.js'   // Hardcoded to run single script.
    '*.spec.js'            // to run all scripts.

  ],

  capabilities: {
    'browserName': 'chrome'
  },

 baseUrl: 'http://localhost:8000/app/',

  framework: 'jasmine2',

};

I am successfully able to run the protractor scripts. Below is the protractor.config.js file which I am using to run the protractor scripts To run above file, I used below command.

$ npm run protractor

My Expectation: Now, I would like to run the single protractor script from command prompt. How this can be achieved? This will be useful when I will try to run the protractor test cases from any test management tool.

Can anyone please help me on this.

3 Answers 3

12

Additionally to the given answers, you can use suites, which are sets of specs:

You can have suites which consist only of one spec. You can run particular spec like this:

protractor --suite=my-suite-name

Also you can temporarily exclude suite or spec in Jasmine using xdescribe and xit (just type x before describe or it).

Also you can focus on particular suite or spec in Jasmin using fdescribe and fit (just type f before describe or it).

2
  • Thanks for reply. Yes, protractor --suite=my-suite-name command is working fine for me. Thanks for your help
    – Durgesh
    May 29, 2015 at 4:33
  • 2
    Your link points at a premium site. It offers no info to those who aren't willing to pay money. Oct 8, 2015 at 15:09
12

Try this:

protractor protractor.conf.js --specs='specs/run-just-this-spec.js'

If you want to run a specific test you need use jasmine2 and pass the grep option. https://github.com/angular/protractor/blob/19139272d190dd9c1888d9c3fc2f480f7c6c8edb/docs/jasmine-upgrade.md

1
  • In case you need to run multiple specs in this fashion: protractor protractor.conf.js --specs='myfirstspec.js','mysecondspec.js' Aug 6, 2018 at 20:31
1

Use the node.js process.env object.

    var w00t = process.env.TESTED || '*';

    exports.config = {
     allScriptsTimeout: 11000,

     specs: [
      w00t + '.spec.js'
     ],

Prepend TESTED=testCaseOn when you start protractor to execute the desired spec. To execute all scripts add nothing so that *.spec.js will be called.

6
  • Thanks for reply. I did exact settings above and executed below command "npm run protractor -TESTED=testcaseone". However it has executed all the test cases. Not sure why. Can you pls help me.
    – Durgesh
    May 22, 2015 at 11:37
  • FYI..... when I tried to get the value of {console.log(process.env.TESTED);} it is giving the value as undefined. How to solve this? May be this is the problem at my end.
    – Durgesh
    May 22, 2015 at 12:03
  • Sorry for the late answer. Try to call the TESTED variable at the beginning of the command: TESTED=testCaseOne npm run protractor.
    – mschoe
    May 26, 2015 at 6:27
  • It is giving me below error message 'TESTED' is not recognized as an internal or external command,
    – Durgesh
    Jun 1, 2015 at 4:55
  • @Durgesh The right command to execute after having made the changes (mentioned by @mschoe) will be TESTED=name-of-your-test npm run protractor. Where "name-of-your-test" is taken from "name-of-your-test.spec.js"
    – zeropaper
    Jun 2, 2015 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.