2

After successfully finishing the scenarios, cucumberjs hangs - indefinitely. How can I get this to stop?

I've got a cucumberjs running on npm/nodejs.

package.json:

{
  "name": "foo-test-automation",
  "version": "1.1.0",
  "description": "Integration Regression UI Test Automation for Foo application",
  "main": "fooAutoTest.js",
  "scripts": {
    "start": ". .env; node ./node_modules/.bin/cucumber-js --tags @RegressionTestSuite --format json:./results/log_`date +\\\"%Y\\\\%m\\\\%d_%H%M\\\"`.json",
},

After finishing, cumber appears to be running in the background

$ npm run new
............................

5 scenarios (5 passed)
28 steps (28 passed)
0m37.701s

I looked for hanging processes:

Hucks-MacBook-Pro:~ huckcarignan$ ps aux | grep node
huckcarignan     25252   0.0  0.0  4287512    856 s004  S+   12:30PM   0:00.00 grep node
huckcarignan     18365   0.0  0.2  4652124  40804 s000  S+   11:33AM   0:02.64 node ./node_modules/.bin/cucumber-js --tags @New --format json:./results/log_"20190521_1133".json
huckcarignan     18362   0.0  0.0  4280924    868 s000  S+   11:33AM   0:00.01 sh -c . .env; node ./node_modules/.bin/cucumber-js --tags @New --format json:./results/log_`date +\"%Y\\%m\\%d_%H%M\"`.json

so nothing leaps out at me.

Am I missing something in my hooks.js:

 const { BeforeAll, AfterAll } = require('cucumber');
 const puppeteer = require('puppeteer');
 const timestamp = require('time-stamp');
 require('dotenv').config();

 BeforeAll(async function() {
     this.browser = await puppeteer.launch({
         headless: (process.env.HEADLESS === 'true'),
         slowMo: parseInt(process.env.SLOWMO),
         defaultViewport: {
             width: parseInt(process.env.SCREEN_SIZE_WIDTH),
             height: parseInt(process.env.SCREEN_SIZE_HEIGHT)
         }
     });
     this.page = await this.browser.newPage();
 });

 AfterAll(async function() {
     // Teardown browser
     if (this.browser) {
         await this.browser.close();
     }
 });

Any help would be appreciated.

UPDATE 1 I've tried replacing my AfterAll with: // Asynchronous Promise AfterAll(function () { return Promise.resolve(); });

but it still hangs (but with the browser open)

Huckleberry Carignan
  • 2,002
  • 4
  • 17
  • 33
  • There is [no `this`](https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/hooks.md#beforeall--afterall) in the `AfterAll` hook. How do you setup the browser? – Thomas Dondorf May 21 '19 at 16:48
  • Hmmm....I can't disagree with you, it's right there in the docs, but now I wonder why other references of _this_ works? – Huckleberry Carignan May 21 '19 at 17:26
  • If there is no `this` (no object the function was called via), `this` will point to the `global` object in Node.js. So both times you are putting the property `browser` on the `global` object. Do your tests actually work? Do you access the browser via `this.browser` there? Cause I cannot really see that working... – Thomas Dondorf May 21 '19 at 17:37
  • Yes, my tests do work. I'm able to make calls using puppeteer. I'll have to move the "this" to a before with a tag. – Huckleberry Carignan May 21 '19 at 17:40
  • Is `this.browser` then actually set inside the `AfterAll` call? Maybe you are never calling `this.browser.close()` there? – Thomas Dondorf May 21 '19 at 17:42
  • The browser does close. When I comment out the this.browser.close() , the browser doesn't close. – Huckleberry Carignan May 21 '19 at 17:50
  • Then you should probably provide the remaining code or a minimal code sample that reproduces the problem. Your problem might not be related to puppeteer. – Thomas Dondorf May 21 '19 at 17:55
  • Oh I think this is a cucumberJS thing, and yes I will add some more code. – Huckleberry Carignan May 21 '19 at 17:58

2 Answers2

1

According to the (CLI reference), you should be able to add "--exit" to the end of your npm command. So it would look like this:

./node_modules/.bin/cucumber-js --tags @RegressionTestSuite --format json:./results/log_`date +\\\"%Y\\\\%m\\\\%d_%H%M\\\"`.json --exit

There's some helpful hints there on finding out why the issue is occurring and how to fix it, as well.

Andrew Long
  • 91
  • 1
  • 4
0

By taking this page - https://www.npmjs.com/package/selenium-webdriver reference, you can create a separate class with the name driver-factory.js and build webdriver with the capabilities which ever you need.

Call this class from hooks and use it in AfterAll annotation. If driver already exists, try to quit it..

Sreenivasulu
  • 494
  • 2
  • 7