CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

async steps reset metaStep

Open 42Mo opened this issue 3 years ago • 4 comments

What are you trying to achieve?

I have page objects methods with bunch of grabbing steps (async). I want them display folded in test reports.

What do you get instead?

All steps after first async step dont have metaStep and stepShift properties thus test reports are hard to read.

Provide console output if related. Use --verbose mode for more details.

Test --
  Test
    I am on page "https://github.com/codeceptjs"
    testPageObject: syncTest
      I see "CodeceptJS"
      I see "Testing Framework"
      I see "examples"
    testPageObject: asyncTest
      I see "CodeceptJS"
      I see "Testing Framework"
      I see "examples"
      I grab text from "//ol/li[1]//p[1]"
    I grab text from "//ol/li[2]//p[1]"
    I grab text from "//ol/li[3]//p[1]"
    I see "CodeceptJS"
    I see "Testing Framework"
    I see "examples"
  √ OK in 1186ms
Test --
  Test
    I am on page "https://github.com/codeceptjs"
current metaStep actor: "testPageObject"
    testPageObject: syncTest
      I see "CodeceptJS"
current metaStep actor: "testPageObject"
      I see "Testing Framework"
current metaStep actor: "testPageObject"
      I see "examples"
current metaStep actor: "testPageObject"
    testPageObject: asyncTest
      I see "CodeceptJS"
current metaStep actor: "testPageObject"
      I see "Testing Framework"
current metaStep actor: "testPageObject"
      I see "examples"
current metaStep actor: "testPageObject"
      I grab text from "//ol/li[1]//p[1]"
    I grab text from "//ol/li[2]//p[1]"
    I grab text from "//ol/li[3]//p[1]"
    I see "CodeceptJS"
    I see "Testing Framework"
    I see "examples"
  √ OK in 1242ms

Provide test source code if related

test.js

Feature('Test');

Scenario.only('Test', async ({ I, testPageObject }) => {

  I.amOnPage("https://github.com/codeceptjs")

  // These steps are folded
  testPageObject.syncTest();

  // These steps lose folding
  await testPageObject.asyncTest();

});

test_page_object.js

const { I } = inject();

module.exports = {

  syncTest() {
    I.see("CodeceptJS");
    I.see("Testing Framework");
    I.see("examples");
  },

  async asyncTest() {
    // these steps keep metaStep
    I.see("CodeceptJS");
    I.see("Testing Framework");
    I.see("examples");
    // steps after first async step lose metaStep
    const repo1 = await I.grabTextFrom("//ol/li[1]//p[1]");
    const repo2 = await I.grabTextFrom("//ol/li[2]//p[1]");
    const repo3 = await I.grabTextFrom("//ol/li[3]//p[1]");
    I.see("CodeceptJS");
    I.see("Testing Framework");
    I.see("examples");
  },

};

utils_helper.js

const Helper = require('@codeceptjs/helper');
const output = require('codeceptjs').output;

class Utils extends Helper {

  _beforeStep(step) {
    if (step.metaStep) {
      output.print(`current metaStep actor: "${step.metaStep.actor}"`);
    }
  }

}

module.exports = Utils;

Details

  • CodeceptJS version: ^3.0.0
  • NodeJS Version: 12.18.0
  • Operating System: Windows
  • Playwright
  • Configuration file:
exports.config = {
  tests: './test.js',
  output: './output',
  helpers: {
    Playwright: {
      url: 'https://github.com/codeceptjs',
      browser: 'chromium',
      show: false,
      waitForTimeout: 10000, //10s
      waitForNavigation: 'load',
    },
    Utils: {
      require: './utils_helper.js',
    },
  },
  include: {
    testPageObject: './test_page_object.js',
  },
  name: 'tests',
  plugins: {
    allure: { enabled: true },
  }
}

42Mo avatar Nov 17 '21 08:11 42Mo

Allure report example image

42Mo avatar Nov 17 '21 08:11 42Mo

Thanks for a very detailed description. I will look at what I can do there.

DavertMik avatar Nov 17 '21 09:11 DavertMik

@DavertMik Any news on this? We are currently running into problems with the ReportPortal agent, because it stores information in the step object which gets lost and that lets our FAILED scenarios always shown as PASSED in ReportPortal... :/

cwolf24 avatar Feb 22 '22 19:02 cwolf24

@DavertMik I digged a little bit into that issue and also found the root cause, I think.

The run method in the MetaStep class doesn't handle async functions. If the fn.apply() method is called with an anync function the prepended listener gets removed as soon as the fn.apply() returns the promise.

I dont see any fast solution yet. Maybe someone else has an idea for a solution.

dwentland24 avatar Apr 27 '22 11:04 dwentland24