Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Approach to nested step in async tests #6

Closed
ctapobep opened this issue Sep 4, 2015 · 6 comments
Closed

Approach to nested step in async tests #6

ctapobep opened this issue Sep 4, 2015 · 6 comments

Comments

@ctapobep
Copy link

ctapobep commented Sep 4, 2015

Currently it's impossible to nest steps in a lot of cases when async tests are used. Consider this Protractor code that uses Promises:

allure.createStep('Outer step', function() {
  element.click().then(function () {
    allure.createStep('Step inside of promise', function () {})();
  });
})();

While the code is nested, it's actually executed in Control Flow of WebdriverJS and therefore zeroes out all the nestiness.

Because this is a usual thing in WebdriverJS I'd think on general approach to address this.

@ctapobep
Copy link
Author

ctapobep commented Sep 4, 2015

Suggestion # 1 - add startStep(), endStep() methods

Example:

var step = allure.startStep('Outer step');
element.click().then(function () {
  //nesting - invoking createStep() on step, not on allure
  step.createStep('Step inside of promise', function () {})();
}).then(function(){
  step.endStep('pass');
}).thenCatch(function(){
  step.endStep('failed');
});

In the end all the non-finished steps are marked as passed (or as failed to notify about bugs in tests).

@just-boris
Copy link
Contributor

I got the point. I have the suggestion too:

Suggestion # 2 – await promise returned from a step function.

var bigStep = allure.createStep('make some clicks', function() {
    return clickStep()
       .then(clickStep)
       .then(clickStep);
});
var clickStep = allure.createStep('click', function() {
    return element.click(); // if promise returned, we will wait this before finish the step
});

it('should make three clicks', function() {
    return bigStep();
});

Most webdrivers libraries as far as I know, support promised interfaces, to that code would more natural for them

@just-boris
Copy link
Contributor

also, startStep and endStep methods already accessible via current API:

allure._allure.startStep('my step');
allure._allure.finishStep('broken'); 

You can play around that methods in existing tests code and find out better solution

@ctapobep
Copy link
Author

ctapobep commented Sep 5, 2015

Suggestion # 2 looks cool from the API perspective. These concerns come to my mind:

  • It will break backward compatibility since previously it was returning a straight value. This can be overcome with a configuration option defaulting to straight value instead of promises.
  • How would you technically recognize nested steps if they are inside of Promises?
  • Promises may not be enough since WebdriverJS uses an orchestrator (ControlFlow). Though I don't know what impact this can have.

PS: allure._allure may work.. Need to try it out.

@just-boris
Copy link
Contributor

Released as 1.1.0. If you want to use this, you should install it aside with reporter. In package.json

{
  "dependencies": {
    "jasmine-allure-reporter": "~0.2.0"
    "allure-js-commons": "~1.1.0"
  }
}

If you omit explicit allure-js-commons dependency, you will get version derived from jasmine-allure-reporter. Once you will test compatibility, please bump version declaration in jasmine-adapter dependency too.

@just-boris
Copy link
Contributor

also I am going to update my example with mocha – https://github.com/allure-examples/mocha-allure-example
Here you can see new features in action

link89 pushed a commit to link89/allure-js-commons that referenced this issue Jul 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants