protractor: Calling `pending` in a spec marks the spec as failed.

See the attached testcase

https://gist.github.com/sveneh/9c589d321e6fc31f7460

When I run this in protractor@2.1.0 using jasmine@2.3.1 I get this:

>protractor pending.conf.js
Starting selenium standalone server...
[launcher] Running 1 instances of WebDriver
Selenium standalone server started at http://192.168.88.100:60036/wd/hub
Started
F*

Failures:
1) a spec with pending should be pending
  Message:
    Failed: => marked PendingThis is pending.
  Stack:
    Error: Failed: => marked PendingThis is pending.
Pending:

1) a spec with pending should be also pending
  No reason given

2 specs, 1 failure, 1 pending spec
Finished in 0.006 seconds
Shutting down selenium standalone server.
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1

running the same spec in pure jasmine@2.3.1:

>jasmine 
Started
**

Pending:

1) a spec with pending should be pending
  This is pending.


2) a spec with pending should be also pending
  No reason given

2 specs, 0 failures, 2 pending specs
Finished in 0.002 seconds

Protractor should not fail specs that are marked as pending.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 8
  • Comments: 33 (3 by maintainers)

Most upvoted comments

As a workaround I introduced an own pending to use in my protractor tests (overwriting the jasmine pending), maybe that is helpful for somebody else as a workaround:

            // in my protractor onPrepare code:
            var _pending = pending;
            pending = function(pendingMessage) {

                return {

                    it: function(description, itFunction) {
                        var consoleColorYellowStart = '\u001B[33m';
                        var consoleColorYellowEnd = '\u001B[0m';
                        return xit(description + '\n  ' + consoleColorYellowStart + 'Marked as Pending: ' + pendingMessage + consoleColorYellowEnd, itFunction);
                    },

                    describe: function(description, describeFunction) {
                        return describe(description, function() {
                            _pending(pendingMessage);
                            return describeFunction();
                        });
                    },

                    here: function() {
                        return _pending(pendingMessage);
                    }

                };

            };

Usage: pending('my pending comment').describe('my describe block', function() { ... }); or pending('my pending comment').it('my it block', function() { ... }); or (just in case you still need the old pure jasmine pending implementation somewhere else, with all advantages and disadvantages) pending('my pending comment').here();

I took the implementation provided by sgibson21 and created a new project with Jasmine 3.6.3 and Protractor 7.0.0. Still, I was getting failures when using pending(); so, I went ahead and started to play around with the implementation. Following is what my confi.js file looks like: `// conf.js let Jasmine2HtmlReporter = require(‘protractor-jasmine2-html-reporter’); var SpecReporter = require(‘jasmine-spec-reporter’).SpecReporter;

let htmlReporter = new Jasmine2HtmlReporter({ savePath: ‘reports’, fileName: ‘e2e-report’, takeScreenshotsOnlyOnFailures: true, cleanDestination: false, fileNameDateSuffix: true });

exports.config = { framework: ‘jasmine’, specs: [‘spec.js’],

onPrepare() { var PendingSpecReporter = SpecReporter;

PendingSpecReporter.prototype.specDone = function (spec) {
  this.metrics.stopSpec(spec);
  var pending = false;
  var pendingReason;
  for(var i = 0; i < spec.failedExpectations.length; i++) {
	  var index = spec.failedExpectations[i].message.toLowerCase().indexOf('pending');
	if ( index >= 0){
		pendingReason = spec.failedExpectations[i].message.substring(index+7); // 7 = the length of the word "pending"
		pending = true;
	}
  }
  if (spec.status === 'pending' || pending) {
	this.metrics.pendingSpecs++;
	this.display.pending(spec);
	
	spec['failedExpectations'] = [];
	spec['passedExpectations'] = [];
	spec['status'] = 'pending';
	
	if(spec['pendingReason'] === 'undefined' || spec['pendingReason'] === ''){
		spec['pendingReason'] = pendingReason;
	}
	
  } else if (spec.status === 'passed') {
	this.metrics.successfulSpecs++;
	this.display.successful(spec);
  } else if (spec.status === 'failed') {
	this.metrics.failedSpecs++;
	this.display.failed(spec);
  }
};

module.exports = PendingSpecReporter;

jasmine.getEnv().addReporter(new PendingSpecReporter({ spec: { displayStacktrace: 'pretty' } }));
    // Assign the test reporter to each running instance
jasmine.getEnv().addReporter(htmlReporter);

let jasmineReporter = require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmineReporter.JUnitXmlReporter({
  consolidateAll: true,
  savePath: 'reports',
  filePrefix: 'e2e-report',
}));

} }`

Following is what my specs look like `// spec.js describe(‘Testing custom results’, function() { xit(‘shoud be skipped because we are using “x” in front of the spec’, function() { pending(‘Force skip’); expect(true).toBe(true); });

it('shoud be skipped using custom implementation', function() {	 
  expect(true).toBe(true);
  pending('My custom pending reason!');

});

it(‘shoud pass!’, function() { expect(true).toBe(true); });

it(‘shoud fail!’, function() { expect(true).toBe(false); });

});`

Following is what the XML report looks like `<?xml version="1.0" encoding="UTF-8"?>

-<testsuites disabled="0" time="0.028" tests="4" failures="1" errors="0">

-<testsuite disabled="0" time="0.028" tests="4" failures="1" errors="0" skipped="2" hostname="localhost" timestamp="2020-12-15T11:14:49" name="Testing custom results">

-<testcase time=“0.001” name=“shoud be skipped because we are using “x” in front of the spec” classname=“Testing custom results”>

<skipped message="Temporarily disabled with xit"/> </testcase>

-<testcase time="0.004" name="shoud be skipped using custom implementation" classname="Testing custom results">

<skipped message="My custom pending reason!"/> </testcase> <testcase time="0.002" name="shoud pass!" classname="Testing custom results"/>

-<testcase time="0.018" name="shoud fail!" classname="Testing custom results">

-<failure message="Expected true to be false." type="toBe">

-<![CDATA[Error: Failed expectation at UserContext.<anonymous> (C:\regUSA\Utilities\ProtractorTest\spec.js:18:17) at C:\regUSA\Utilities\ProtractorTest\node_modules\jasminewd2\index.js:112:25 at new ManagedPromise (C:\regUSA\Utilities\ProtractorTest\node_modules\selenium-webdriver\lib\promise.js:1077:7) at ControlFlow.promise (C:\regUSA\Utilities\ProtractorTest\node_modules\selenium-webdriver\lib\promise.js:2505:12) at schedulerExecute (C:\regUSA\Utilities\ProtractorTest\node_modules\jasminewd2\index.js:95:18) at TaskQueue.execute_ (C:\regUSA\Utilities\ProtractorTest\node_modules\selenium-webdriver\lib\promise.js:3084:14) at TaskQueue.executeNext_ (C:\regUSA\Utilities\ProtractorTest\node_modules\selenium-webdriver\lib\promise.js:3067:27) at asyncRun (C:\regUSA\Utilities\ProtractorTest\node_modules\selenium-webdriver\lib\promise.js:2974:25) at C:\regUSA\Utilities\ProtractorTest\node_modules\selenium-webdriver\lib\promise.js:668:7]]> </failure>

</testcase> </testsuite>

</testsuites>`

Following is what the HTML report looks like `` image

Short workaround: (environment.postDeployment ? xit : it)('should something', () => { expect(true).toBeTruthy(); });

I extended the jasmine-spec-reporter (https://www.npmjs.com/package/jasmine-spec-reporter)

var SpecReporter = require('jasmine-spec-reporter');
var PendingSpecReporter = SpecReporter;

PendingSpecReporter.prototype.specDone = function (spec) {
  this.metrics.stopSpec(spec);
  var pending = false;
  for(var i = 0; i < spec.failedExpectations.length; i++) {
    if ( spec.failedExpectations[i].message.toLowerCase().indexOf('pending') >= 0) pending = true;
  }
  if (spec.status === 'pending' || pending) {
    this.metrics.pendingSpecs++;
    this.display.pending(spec);
  } else if (spec.status === 'passed') {
    this.metrics.successfulSpecs++;
    this.display.successful(spec);
  } else if (spec.status === 'failed') {
    this.metrics.failedSpecs++;
    this.display.failed(spec);
  }
};

module.exports = PendingSpecReporter;

Specs marked as pending are displayed as pending in the report.

Still experiencing this, meanwhile the workaround works like a charm @bruderol thanks!