question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Async/blocking BeforeSuite, Before, After, AfterSuite hooks

See original GitHub issue

What are you trying to achieve?

I would like to asynchronously create a test user and a test project over an XHR request before a collection of tests runs.

I expected one of the following to work:

BeforeSuite((I) => new Promise((resolve) => setTimeout(resolve, 5000)))
Before((I) => new Promise((resolve) => setTimeout(resolve, 5000)))
BeforeSuite(function* (I) {
  yield new Promise((resolve) => setTimeout(resolve, 5000))
})
Before(function* (I) {
  yield new Promise((resolve) => setTimeout(resolve, 5000))
})

What do you get instead?

Instead, the tests progress without any blocking/waiting. Is there any approach I can take to postbone test execution until my prerequisits are fulfilled?

Details

  • CodeceptJS version: v0.5.1
  • NodeJS Version: v7.2
  • Operating System: MacOS Sierra
  • WebDriverIO version: v4.6.2
  • Configuration file:
exports.config = {
  tests: './tests/src/end-to-end/**/*.[tj]s',
  timeout: 10000,
  output: './tests/output/end-to-end',
  helpers: {
    WebDriverIO: {
      url: process.env.GUI_HOST,
      browser: 'chrome',
      restart: true,
      desiredCapabilities: {
        browserName: 'chrome',
      },
      host: 'selenium',
      port: 4444,
    },
    TestUser: {
      "require": "./tests/config/codecept/TestUser.js",
    },
    TestBusinessEntity: {
      "require": "./tests/config/codecept/TestBusinessEntity.js",
    },
  },
  include: {
    I: './tests/config/codecept/custom_steps.js',
  },
  bootstrap: false,
  mocha: {},
  name: 'byll-gui',
};

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
DavertMikcommented, Mar 2, 2017

Ok, promises are stored in a global promise chain. There is a way to access it (I will post it below, however it is not documented and not recommended to do so). To attach a promise to a promise chain it should be implemented as a method inside a helper and called inside a test:

BeforeSuite((I) => {
   I.doSomethingBeforeStart();
});

doSomethingBeforeStart should be defined inside a custom helper as a regular method returning a promise:

doSomething() {
    new Promise((resolve) => setTimeout(resolve, 5000))
}

Once the helper is enabled you can use its method inside Before/BeforeSuite.


Alternatively you can access a promise chain on your own

const recorder = require('codeceptjs/lib/recorder');

Before(function() {
   recorder.add(new Promise((resolve) => setTimeout(resolve, 5000)));
});
1reaction
philipstanislauscommented, Jul 4, 2017

@sveneisenschmidt unfortunately I have not, I used a test to achieve what I wanted. Let us know if you find a solution!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Async/blocking BeforeSuite, Before, After, AfterSuite hooks #436
I would like to asynchronously create a test user and a test project over an XHR request before a collection of tests runs....
Read more >
Behat: BeforeSuite and AfterSuite Hooks - ProgramsBuzz
Suite hooks are run outside of the scenario context. It means that your context class (e.g. FeatureContext) is not instantiated yet and the ......
Read more >
How to use TestNG BeforeSuite and AfterSuite Hooks for ...
In this post, we will see, how to create a database connection only once and how to close the connection once using TestNG...
Read more >
Bountysource
Async/blocking BeforeSuite, Before, After, AfterSuite hooks. ... Help and Information. Frequently Asked Questions · Bugs and Feature Requests · Fees ...
Read more >
Cucumber Reports - BeforeSuite and AfterSuite methods
Standard Cucumber runner has functionality of hooks which is represented with @Before and @After annotations and which are running before and after each ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found