allure-framework / allure-js-commons

Deprecated, use https://github.com/allure-framework/allure-js instead
Other
27 stars 40 forks source link

Cannot read allure from beforeAll function for Jasmine tests #14

Closed irushah closed 8 years ago

irushah commented 8 years ago

If I call allure.createStep from beforeAll function, the test fails with error "Cannot read property 'addStep' of undefined". But it works if called from a testcase (it). Tests are written in Jasmine 2, that supports beforeAll/afterAll

just-boris commented 8 years ago

What exactly you are doing in beforeAll?

You cannot call step before tests will be actually started, but you can define them.

For example

var myStep;
beforeAll(function() {
    myStep = allure.createStep('my-step', function() {
      // actual step code
    });
});

it('is a spec', function() {
   myStep(); // you can call step here.
});

But you can't call steps in beforeAll, because there is no step, where the step can be attached.

irushah commented 8 years ago

I have common login function that adds step to the report. This login function I am calling from multiple places - from beforeAll and it as well. And it fails everytime if call login from beforeAll. Is there a way to tell allure dont add step if its a before function or something?

just-boris commented 8 years ago

If you do not want to log this in Allure, you can just call the login step directly

function doLogin() {
  //login actions
}

var loginStep = allure.createStep('login', doLogin);

beforeAll(function() {
   doLogin(); // clean function, no logging for Allure
});

it('test', function() {
  loginStep();
});

it looks a bit inconsistent because some login actions don't appear in the report, but some do. Maybe you want to get rid of logging this into Allure at all.

just-boris commented 8 years ago

Closing this issue as not an actual issue, but I am still open to further discussion.