Kenzitron / protractor-jasmine2-html-reporter

HTML reporter for Jasmine2 and Protractor
32 stars 53 forks source link

skipped tests #50

Open tamasmahr opened 7 years ago

tamasmahr commented 7 years ago

Hi,

I have a number of protractor tests that do not include any expect() call from Jasmine, but they use browser.wait() calls. When such tests pass, the report contains the Skipped text in the entry for the spec. The passed, failed, skipped counts for the suite are correct.

Does anybody has any idea why should these specs be marked as skipped?

I am using:

Thanks for the help!

rolobm commented 7 years ago

Same problem :(

tamasmahr commented 7 years ago

Since I left this comment we found that it is bad practice to have tests with no expect call in them. We should not just wait for something to appear in the dom, but we should make an assertion. As a side effect, this problem is solved as well. :)

hipschen commented 7 years ago

Protractor tests often use ExpectedCondition (EC) in place of an expect call. http://www.protractortest.org/#/api?view=ProtractorExpectedConditions

When a test has an EC, this reporter includes "Skipped" at the test level but not at the header level. image

Nez07 commented 7 years ago

How can we edit the reporter to disable Skipped text from being shown for such specs that do not include any expect() call from Jasmine, but use browser.wait() calls . Any help will highly appreciated.

Isaak-Malers commented 6 years ago

I've also been having this issue when "expect" calls are several files removed from the test that is running, for example:

config.js

runs

myTest.js

which requires

page-library.js

which requires

site-library.js

which requires

login.js

In the first describe for myTest;

User should automatically be re-directed to login page if they are unauthenticated

The only expect calls are in in login.js

I suppose the workaround is to put ```expect(true).toBe(true) everywhere where there isn't a naitive expect, but that is a clunky workaround for sure.

telangn commented 6 years ago

Can you elaborate or show code on how to fix this? All my functions have "expect(data).toBe(myData);" Is this why my html reports says Skipped for all my 'it''s? I call these functions from my 'it', they exist in another .js file. @tamasmahr @hipschen

Isaak-Malers commented 6 years ago

@telangn Certainly, I open sourced all of the code that I used to get around protractor deficiencies in general here:

https://github.com/Isaak-Malers/obverse

The part that you will be interested in is that I add a "step" level to my tests so that I can do the following:

describe(user accounts tests, function(){
    it("should be able to create a new user", function(){
        step("navigate to login page via a tracking link", function(){});
        step("create new account", function(){});
        step("verify account email received", function(){});
    });
});

This way I am still able to get more granular logging and control of my tests, without having to use "it" blocks with effectively no tests in them, which isn't really what the "it" function was meant to do.

telangn commented 6 years ago

@Isaak-Malers I've looked through your link. I cannot find the above code snippet. Can you direct me? Also, are you saying by doing the "step" the html report will produce results instead of "skipped"?

Can you show me the above file in addition to where the step is defined and executed?

Isaak-Malers commented 6 years ago

@telangn

Jasmine has limited support for "it" blocks that don't contain expect calls because the primary purpose of an it block is to contain assertions, as @tamasmahr noted here:

Since I left this comment we found that it is bad practice to have tests with no expect call in them. We should not just wait for something to appear in the dom, but we should make an assertion. As a side effect, this problem is solved as well. :)

I would expect anyone having this issue, is using "it" blocks for too granular of tasks. By adding a "step" function to provide a more granular level of testing, it is possible to consolidate all of the problematic "it" calls into a single block, and organize the test with "steps". For example:

should really be:

Note that in this second example, the first 3 "it" blocks which would have shown up as skipped have been replaced with "steps". The 4th it block has also been replaced with a step, and the assertions/expect performed inside that step will carry up to the parent "it" function, thus aligning with jasmines best practices.

As for code, I feel that the Read-Me/landing page on the obverse repository should be enough to get you started with that code base, but It is a lot of extra stuff beyond my code for test steps. I pulled all that code out into a separate sub-module for you here:

https://github.com/Isaak-Malers/serial-IOC

Specifically take a look at the example protractor test here:

https://github.com/Isaak-Malers/serial-IOC/blob/master/protractor-example/example.js

Note that this repository contains a super minimal amount of code. The full obverse repository has a lot more capability as far as test organization and reliability increase goes.

telangn commented 6 years ago

Wow, very interesting! @Isaak-Malers Thank you for this. Quick question, I see you new'd up IOC

var IOC = require("../src/serialIOC");
var test = new IOC();//new up an IOC object

And then you use test.step....but where do you declare require('step') ? Is stepjust understood by Jasmine? Do I need to do an npm install of it or something? bc in ../src/serialIOC, this is quite confusing for me - serialIOC.prototype.step = function (comment, functionToRun) { Is there an easier implementation?

Btw, I'm new to protractor/JS (I've been a Java dev for a while), so sorry for the basic questions.

Isaak-Malers commented 6 years ago

step is a function in the IOC class (or test object). It doesn't need to be required because it gets pulled in with IOC. The "test" object is using the step function to dynamically build promise chains, and the "test" object is where that promise chain is stored.

note that the signature for step is:

step("comment for logging", function);

The function passed into step MUST return a promise. It is just returning out the promise for the protractor API calls (such as browser.get())