Skip to content

Conversation

@anirudh-modi
Copy link
Contributor

@anirudh-modi anirudh-modi commented May 28, 2021

Problem

I am trying to use a helper in our BeforeSuite, however, when I run the tests in UI, I am getting an error named testStartedAt. Below is the error for the same.

Screenshot 2021-05-28 at 12 42 25 PM

Some observations

  • The same test is passing when i run the codecept without electron
  • When I run the same test by replacing the BeforeSuite with Before it works in ui mode also

What do you get instead?

 "before all" hook: BeforeSuite for "Homepage":
     testStartedAt is required
      at RealtimeReporterHelper._mapStep (node_modules/@codeceptjs/ui/lib/codeceptjs/realtime-reporter.helper.js:209:5)
      at /Users/anirudhmodi/Documents/hackit/codecept-demo/node_modules/@codeceptjs/ui/lib/codeceptjs/realtime-reporter.helper.js:137:16
// example_test.js
Feature('Github homepage');

BeforeSuite(async ({ I }) => {

    // Will wait for 3000ms and then load
    await I.performSetup(3000);
    I.amOnPage('https://github.com/codeceptjs/ui');
});

Scenario('Homepage', ({ I }) => {
    I.grabAttributeFrom('.author');
});
// PageHelper.js

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

class PageHelper extends Helper {
    performSetup(n) {
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve();
            },n);
        });
    }
}
module.exports = PageHelper;

Sample repo for the problem

The problem can be replicated by running the npm run codeceptjs:ui in this repo.
https://github.com/anirudh-modi/codecept-demo

Solution

After looking at the code I found that for the function _mapSteps, testStartedAt is a required param.

assert(testStartedAt, 'testStartedAt is required');

this.testStartedAt is only initialized during _before function present in the file realtime-reporter.helper.js. Below is the code

async _before(t) {
    if (!this._isEnabled(t)) return;

    t.retries(0); // disable retries in web ui
    this.test = t;
    this.testStartedAt = Date.now();
    this.step = undefined;
    this.metaStep = undefined;
    this.loggedMetaSteps = [];
    this.cachedStackFrameInTest = undefined;

    wsEvents.rtr.testBefore(mapSuiteAndTest(this.testStartedAt, this.suite, this.test));
  }

However for the _beforeSuite it is not initialized

async _beforeSuite(suite) {

async _beforeSuite(suite) {  
    if (!this._isEnabled()) return;
    this.suite = suite; 

    wsEvents.rtr.suiteBefore(mapSuiteAndTest(Date.now(), this.suite, this.test));
  }

Simply, declaring this.testStartedAt in _beforeSuite was not sufficient, as, _mapSteps is dependent on the this.test.id which remains undefined as during the _beforeSuite this.test is not initialized.

testId: this.test.id,

return {
      id: step.id,
      testId: this.test.id,
      at: Date.now() - testStartedAt,
      startedAt: step.startTime,
      duration: Date.now() - step.startTime,
      actor: 'I',
      humanized: step.humanize(),
      humanizedArgs: step.humanizeArgs(),
      status: step.status,
      name: step.name,
      args: mapArgs(step.args),
      store: Object.assign({}, store),
      snapshot,
      logs: step.logs || [],
      section: this._generateSection(step.metaStep),
      metaStep: this._mapMetaStep(step.metaStep),
      returnValue: step.returnValue,
      command: step.command,
      stack
    };

@anirudh-modi anirudh-modi changed the title Fixes issue in electron when using beforeSuite Fixes testStartedAt issue in electron when using beforeSuite May 28, 2021
@anirudh-modi
Copy link
Contributor Author

Hi, what is the procedure to get reviews on this PR and ensuring it gets merged? I have explained the problem I had faced, and also given a sample repository where the problem can be replicated.

@DavertMik @hubidu

@DavertMik
Copy link
Contributor

@anirudh-modi Thanks for a very deep investigation! The PR looks good to me.

@DavertMik DavertMik merged commit 1a02040 into codeceptjs:master May 29, 2021
@DavertMik
Copy link
Contributor

I will also make a patch release right now

@anirudh-modi
Copy link
Contributor Author

@DavertMik Thanks alot!!! I really appreciate the merge!!
Please, let me know if anything else needs to be done from my side.. I will ensure the same..

@github-actions
Copy link

github-actions bot commented Feb 8, 2024

🎉 This PR is included in version 1.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants