Is it possible to force Protractor to pass or skip a test with a message to the console?
Asked Answered
P

2

6

I'm working with a system that has several external system dependencies. These external systems are only hooked into certain SDLC environments (local, dev, qa, and prod). Due to these restrictions, I have put environment checks in place on my some of my protractor tests to determine which environment they are in before executing.

For example:

'Test A' is being run, but it is dependent on interacting with 'external system 1' which is only enabled for the QA environment. So if 'Test A' is being run in Local, Dev, or Prod then the test will fail with a message to the console using fail().

My question is... Is there a way to force the test to Pass or be Skipped with a message similar to using fail()? I'm trying to delineate between tests actually passing or failing cause of functionality and if the test was simply skipped due to environment dependencies in my reports.

I know you can technically "skip" tests when your use "fdescribe" or "fit" and the console will print out something similar to the below

Executed 1 of 25 specs (1 FAILED) (24 SKIPPED) in 18 secs.

How can I invoke that skipping capability from with my tests?

Pettifogging answered 8/9, 2015 at 14:25 Comment(1)
You can add an if statement in your test where you will check the environment. If there are no expects Jasmine considers the test as passed. You can also write something to the console by using console.log().Powwow
L
10

Jasmine publishes a global function pending(message), which works pretty the same as fail(message). You should call it inside a spec to mark it as pending (to skip it):

it('should be skipped', function () {
    pending('Force skip');
    expect(true).toBe(true);
});

See a working sample

Here is a section in Jasmine docs about it.

Lugar answered 8/9, 2015 at 14:39 Comment(2)
Thanks Michael. I'll give that a shot.Pettifogging
This seems to do the trick for me. Although Protractor currently interprets tests marked "pending" as as failing with the below response in the console. Message: Failed: => marked Pending This has issue has been reported here. It is currently open and unassigned. I'm sure I'll get my desired reporting results once this bug is resolved in Protractor.Pettifogging
S
14

Add x before it{}

describe("", function() {
});

it('Would perform this test', function() {
});

xit('would skip this test', function() {
});
Spectre answered 10/1, 2017 at 12:18 Comment(2)
xit dont pass the test.Anear
Yes but it skips the testSpectre
L
10

Jasmine publishes a global function pending(message), which works pretty the same as fail(message). You should call it inside a spec to mark it as pending (to skip it):

it('should be skipped', function () {
    pending('Force skip');
    expect(true).toBe(true);
});

See a working sample

Here is a section in Jasmine docs about it.

Lugar answered 8/9, 2015 at 14:39 Comment(2)
Thanks Michael. I'll give that a shot.Pettifogging
This seems to do the trick for me. Although Protractor currently interprets tests marked "pending" as as failing with the below response in the console. Message: Failed: => marked Pending This has issue has been reported here. It is currently open and unassigned. I'm sure I'll get my desired reporting results once this bug is resolved in Protractor.Pettifogging

© 2022 - 2024 — McMap. All rights reserved.