Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run particular protractor test case from command prompt

Tags:

protractor

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.

like image 457
Durgesh Avatar asked May 22 '15 06:05

Durgesh


People also ask

Which command is used to run the protractor test cases in command prompt?

Try to call the TESTED variable at the beginning of the command: TESTED=testCaseOne npm run protractor.

How do I run a specific block in protractor?

If want to execute a particular test suite or test case then we can be preceding with 'f' focus i.e., 'fdescribe' will execute that suite and 'fit' will execute that particular 'it' block.

How do you run multiple protractor tests?

When you want to run protractor scripts by opening a browser instance for each test, you should add two capabilities shardTestFiles and maxInstances in the Capabilities block of the conf. js file. This will help to execute your scripts on same browser with multiple instances.

How do I run protractor tests using the web driver?

Once Protractor is used to run any test, the web driver will automatically load and run the test in the relevant browser. To start the web driver manager, the following command needs to be executed from the command prompt.

How to run a test case at the command prompt?

To run a test case at the command prompt 1 On the taskbar, click Start, and then click Run. 2 Type cmd in the Run box and then click OK. 3 At the command prompt, type the following: ax32 -StartupCmd=RunTestProject_<name of test>#N#Note#N#When you use this... More ...

How to execute all scripts in protractor using testcaseon?

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.

How many files does protractor need to run?

Protractor needs the following two files to run − It is one of the important files to run Protractor. In this file, we will write our actual test code. The test code is written by using the syntax of our testing framework.


2 Answers

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).

like image 70
Igor Shubovych Avatar answered Jun 04 '23 19:06

Igor Shubovych


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

like image 45
Andres D Avatar answered Jun 04 '23 19:06

Andres D