Nightwatch: Execution is stopped after beforeEach method

Created on 18 Dec 2018  ยท  7Comments  ยท  Source: nightwatchjs/nightwatch

I have a test which has a beforeEach method. I'm testing the new nightwatch version (1.0.16) and after the "beforeEach" method is ran the test execution is finished and the test is never executed.
The method that is called from the beforeEach is from another class.

var commonSteps = require("../globals/common/CommonSteps.js");

module.exports = {
    beforeEach: function(browser) {
        commonSteps.goToHomePage(browser);
    },
    after: function (browser, done) {
        commonSteps.closeDriver(browser, done);
    },
    'Example test' : function(client) {
        var welcomePage = client.page.WelcomePage();
        welcomePage.section.helloSection.waitPage();

        welcomePage.section.filterSection.clickOnOkButton();
        welcomePage.assert.visible("@helloButton", "Hello button is visible");
    }
}

This works great in Nightwatch 0.9.20, but it's not working in 1.0.15 and 1.0.16.
I'm using [email protected], [email protected], [email protected] on MacOS Mojave (10.14.1), Node 10.12.0 and NPM 6.4.1

My nightwatch config is like :

bug

Most helpful comment

I believe I encountered a similar (same?) issue.
The test code I have worked correctly up to nightwatch version 1.0.14 but is broken in 1.0.15 and 1.0.16.
I could oversimplify the test code up to this:

module.exports = {
  // before: browser => {
  //   browser.setWindowPosition(0, 0).resizeWindow(800, 800);
  // },
  // beforeEach: browser => {
  //   browser.init(browser.launchUrl).waitForElementPresent("#test");
  // },
  "Test": browser => {
    browser.assert.ok(true);
  }
};

If I enable either the before hook or the beforeEach hook (or both), then the test execution gets locked after the execution of the code inside the hook, with the console only displaying up to:

[General] Test Suite
====================

I checked and it happens both with the chrome and firefox driver.

Possibly relevant nightwatch config:

  selenium: {
    start_process: true,
    server_path: seleniumServer.path,
    host: "127.0.0.1",
    port: 4444,
    cli_args: {
      "webdriver.chrome.driver": chromedriver.path,
      "webdriver.gecko.driver": geckodriver.path
    },
    check_process_delay: 5000
  },
  test_settings: {
    chrome: {
      desiredCapabilities: {
        browserName: "chrome",
        javascriptEnabled: true,
        acceptSslCerts: true,
        chromeOptions: {
          args: [
            "no-sandbox",
            "allow-file-access-from-files",
            "use-fake-device-for-media-stream",
            "use-fake-ui-for-media-stream",
            "disable-translate",
            "no-process-singleton-dialog",
            "mute-audio"
          ]
        }
      }
    },
    firefox: {
      desiredCapabilities: {
        browserName: "firefox",
        javascriptEnabled: true,
        acceptSslCerts: true,
        marionette: true,
        "moz:firefoxOptions": {
          log: {
            level: "trace"
          },
          args: ["-no-remote"],
          prefs: {
            "browser.cache.disk.enable": false,
            "browser.cache.disk.capacity": 0,
            "browser.cache.disk.smart_size.enabled": false,
            "browser.cache.disk.smart_size.first_run": false,
            "browser.sessionstore.resume_from_crash": false,
            "browser.startup.page": 0,
            "media.navigator.streams.fake": true,
            "media.navigator.permission.disabled": true,
            "device.storage.enabled": false,
            "media.gstreamer.enabled": false,
            "browser.startup.homepage": "about:blank",
            "browser.startup.firstrunSkipsHomepage": false,
            "extensions.update.enabled": false,
            "app.update.enabled": false,
            "network.http.use-cache": false,
            "browser.shell.checkDefaultBrowser": false
          }
        }
      }
    }
  }

All 7 comments

I don't think we have enough here to properly diagnose the problem. Could you maybe include a better reproducible testcase and try to format the config so it's easier to read?

I believe I encountered a similar (same?) issue.
The test code I have worked correctly up to nightwatch version 1.0.14 but is broken in 1.0.15 and 1.0.16.
I could oversimplify the test code up to this:

module.exports = {
  // before: browser => {
  //   browser.setWindowPosition(0, 0).resizeWindow(800, 800);
  // },
  // beforeEach: browser => {
  //   browser.init(browser.launchUrl).waitForElementPresent("#test");
  // },
  "Test": browser => {
    browser.assert.ok(true);
  }
};

If I enable either the before hook or the beforeEach hook (or both), then the test execution gets locked after the execution of the code inside the hook, with the console only displaying up to:

[General] Test Suite
====================

I checked and it happens both with the chrome and firefox driver.

Possibly relevant nightwatch config:

  selenium: {
    start_process: true,
    server_path: seleniumServer.path,
    host: "127.0.0.1",
    port: 4444,
    cli_args: {
      "webdriver.chrome.driver": chromedriver.path,
      "webdriver.gecko.driver": geckodriver.path
    },
    check_process_delay: 5000
  },
  test_settings: {
    chrome: {
      desiredCapabilities: {
        browserName: "chrome",
        javascriptEnabled: true,
        acceptSslCerts: true,
        chromeOptions: {
          args: [
            "no-sandbox",
            "allow-file-access-from-files",
            "use-fake-device-for-media-stream",
            "use-fake-ui-for-media-stream",
            "disable-translate",
            "no-process-singleton-dialog",
            "mute-audio"
          ]
        }
      }
    },
    firefox: {
      desiredCapabilities: {
        browserName: "firefox",
        javascriptEnabled: true,
        acceptSslCerts: true,
        marionette: true,
        "moz:firefoxOptions": {
          log: {
            level: "trace"
          },
          args: ["-no-remote"],
          prefs: {
            "browser.cache.disk.enable": false,
            "browser.cache.disk.capacity": 0,
            "browser.cache.disk.smart_size.enabled": false,
            "browser.cache.disk.smart_size.first_run": false,
            "browser.sessionstore.resume_from_crash": false,
            "browser.startup.page": 0,
            "media.navigator.streams.fake": true,
            "media.navigator.permission.disabled": true,
            "device.storage.enabled": false,
            "media.gstreamer.enabled": false,
            "browser.startup.homepage": "about:blank",
            "browser.startup.firstrunSkipsHomepage": false,
            "extensions.update.enabled": false,
            "app.update.enabled": false,
            "network.http.use-cache": false,
            "browser.shell.checkDefaultBrowser": false
          }
        }
      }
    }
  }

If I enable either the before hook or the beforeEach hook (or both), then the test execution gets locked after the execution of the code inside the hook, with the console only displaying up to:

@Shyiy is that with --verbose?

Script run is hanging after 'before' step
v1.0.14 works fine, 1.0.16 - have this issue

This is the output wit the --verbose flag, I enabled the before hook here for instance:

 Starting Selenium Server on port 4444...
 Selenium Server up and running on port 4444 with pid: 48080 (5301ms).


[General] Test Suite
====================
   Request POST  /wd/hub/session
   { desiredCapabilities:
      { browserName: 'chrome',
        acceptSslCerts: true,
        platform: 'ANY',
        javascriptEnabled: true,
        chromeOptions:
         { args:
            [ 'no-sandbox',
              'allow-file-access-from-files',
              'use-fake-device-for-media-stream',
              'use-fake-ui-for-media-stream',
              'disable-translate',
              'no-process-singleton-dialog',
              'mute-audio' ] },
        name: 'General' } }
   Response 200 POST /wd/hub/session (1825ms)
   { status: 0,
     sessionId: 'd47d2af36ae7e40f12da59e0ed1de1bd',
     value:
      { acceptInsecureCerts: false,
        acceptSslCerts: false,
        applicationCacheEnabled: false,
        browserConnectionEnabled: false,
        browserName: 'chrome',
        chrome:
         { chromedriverVersion: '2.45.615355 (d5698f682d8b2742017df6c81e0bd8e6a3063189)',
           userDataDir:
            '/var/folders/fg/v035ljmx4zv478chk12m0s540000gn/T/.org.chromium.Chromium.DOoFz5' },
        cssSelectorsEnabled: true,
        databaseEnabled: false,
        'goog:chromeOptions': { debuggerAddress: 'localhost:49694' },
        handlesAlerts: true,
        hasTouchScreen: false,
        javascriptEnabled: true,
        locationContextEnabled: true,
        mobileEmulationEnabled: false,
        nativeEvents: true,
        networkConnectionEnabled: false,
        pageLoadStrategy: 'normal',
        platform: 'Mac OS X',
        proxy: {},
        rotatable: false,
        setWindowRect: true,
        strictFileInteractability: false,
        takesHeapSnapshot: true,
        takesScreenshot: true,
        timeouts: { implicit: 0, pageLoad: 300000, script: 30000 },
        unexpectedAlertBehaviour: 'ignore',
        version: '71.0.3578.98',
        webStorageEnabled: true,
        'webdriver.remote.sessionid': 'd47d2af36ae7e40f12da59e0ed1de1bd' } }
 Received session with ID: d47d2af36ae7e40f12da59e0ed1de1bd

 โ†’ Running [before]:

 โ†’ Running command: setWindowPosition (0, 0)

 โ†’ Running command: windowPosition ('current', 0, 0, [Function])
   Request POST  /wd/hub/session/d47d2af36ae7e40f12da59e0ed1de1bd/window/current/position
   { x: 0, y: 0 }
   Response 200 POST /wd/hub/session/d47d2af36ae7e40f12da59e0ed1de1bd/window/current/position (114ms)
   { sessionId: 'd47d2af36ae7e40f12da59e0ed1de1bd',
     status: 0,
     value: null }
 โ†’ Completed command windowPosition ('current', 0, 0, [Function]) (116ms)
 โ†’ Completed command setWindowPosition (0, 0) (117ms)

 โ†’ Running command: resizeWindow (800, 800)

 โ†’ Running command: windowSize ('current', 800, 800, [Function])
   Request POST  /wd/hub/session/d47d2af36ae7e40f12da59e0ed1de1bd/window/current/size
   { width: 800, height: 800 }
   Response 200 POST /wd/hub/session/d47d2af36ae7e40f12da59e0ed1de1bd/window/current/size (110ms)
   { sessionId: 'd47d2af36ae7e40f12da59e0ed1de1bd',
     status: 0,
     value: null }
 โ†’ Completed command windowSize ('current', 800, 800, [Function]) (111ms)
 โ†’ Completed command resizeWindow (800, 800) (113ms)

I am having the same issue on 1.0.16. Placing commands in a regular testcase works fine and executes without issue. Moving that same code into beforeEach, it will execute, but then the process will hang indefinitely. The test cases that should come after the hook never get called.

Edit: I am running it on Windows using Internet Explorer 11

I also see the same issue on 1.0.15 and 1.0.16. And as @Shyiy mentions, it works as expected in 1.0.14. Here is my test:

module.exports = {
    before(browser) {
        browser.url('/');
        browser.waitForElementVisible('div[class="page-wrapper"]', 'Page Wrapper visible');
    },

    after(browser) {
        browser.end();
    },

    testPlaySoundButton(browser) {
        browser
            .assert.containsText('table tr:first-child td:first-child', 'width')
            .assert.containsText('button', 'play sound');
    }
};

The last line in verbose output is:

โœ” Page Wrapper visible
 โ†’ Completed command waitForElementVisible ('div[class="page-wrapper"]', 'Page Wrapper visible') (32ms)

But the testCase testPlaySoundButton is never called.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dakebl picture dakebl  ยท  4Comments

manjero picture manjero  ยท  4Comments

chaseconey picture chaseconey  ยท  4Comments

jvlaar picture jvlaar  ยท  4Comments

Pieras2 picture Pieras2  ยท  3Comments