Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execution is stopped after beforeEach method #1947

Closed
alexisrouse opened this issue Dec 18, 2018 · 7 comments
Closed

Execution is stopped after beforeEach method #1947

alexisrouse opened this issue Dec 18, 2018 · 7 comments
Labels

Comments

@alexisrouse
Copy link

alexisrouse commented Dec 18, 2018

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 nightwatch@1.0.16, chromedriver@2.44.0, chrome@70.0 on MacOS Mojave (10.14.1), Node 10.12.0 and NPM 6.4.1

My nightwatch config is like :

@beatfactor
Copy link
Member

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?

@Shyiy
Copy link

Shyiy commented Dec 20, 2018

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
          }
        }
      }
    }
  }

@beatfactor
Copy link
Member

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?

@sergiido
Copy link

sergiido commented Dec 20, 2018

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

@Shyiy
Copy link

Shyiy commented Dec 20, 2018

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)

@dmasters19
Copy link

dmasters19 commented Dec 20, 2018

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

@epihel
Copy link

epihel commented Dec 21, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants