Nightwatch: switchWindow not working on Firefox v57 + geckodriver v1.19.1

Created on 10 Dec 2017  Â·  12Comments  Â·  Source: nightwatchjs/nightwatch

switchWindow doesn't seem to work in Firefox 57. Although no errors are thrown/logged, the browser never switches focus to the passed window.

Steps to reproduce

  • Open www.google.com,
  • Write something in the search box
  • Open a new tab at www.google.com
  • Focus to new tab, using switchWindow.
  • Write something in search box

Expected behaviour

  • 'hello world - tab 1' is written in search box of Tab 1 (original tab)
  • 'hello world - tab 2' is written in search box of Tab 2 (newly opened tab)

Actual behaviour

  • 'hello world - tab 1 - hello world - tab 2'' is written in search box of Tab 1 (original tab)
  • Nothing is written in search box of Tab 2

The browser never focuses to Tab 2, even after adding an extended pause() to make sure the tab has opened and loaded.

MCVE

'use strict'

module.exports = {
  'Firefox not focusing window test case' : function (browser) {
    browser
      // Tab 1, write something in search box
      .url('https://www.google.com')
      .waitForElementVisible('body', 5000)
      .setValue('#lst-ib', 'hello world - tab 1')

      // Tab 2, write something in search box
      .execute(function () {
        window.open('https://www.google.com')
      }, [])
      .pause(2000)
      .window_handles(function(result) {
        this.switchWindow(result.value[1])
      })
      .waitForElementVisible('body', 5000)
      .setValue('#lst-ib', 'hello world - tab 2')

      .pause(20000)
      .end()
  }
}

Logs

Running the above MCVE with --verbose shows a POST 500 Error when attempting to switchWindow

INFO Request: POST /wd/hub/session/7c3873ed-1dae-3143-9124-f104f8e6ee19/window 
 - data:  {"name":{"handle":"2147483653"}} 
 - headers:  {"Content-Type":"application/json; charset=utf-8","Content-Length":32}
ERROR Response 500 POST /wd/hub/session/7c3873ed-1dae-3143-9124-f104f8e6ee19/window (5071ms) { state: 'invalid argument',
  sessionId: null,
  hCode: 1180860869,
  value: 
   { additionalInformation: '\nDriver info: driver.version: unknown',
     localizedMessage: 'Missing \'handle\' parameter\nBuild info: version: \'3.7.1\', revision: \'8a0099a\', time: \'2017-11-06T21:07:36.161Z\'\nSystem info: host: \'Nicholass-iMac.local\', ip: \'192.168.0.10\', os.name: \'Mac OS X\', os.arch: \'x86_64\', os.version: \'10.12.6\', java.version: \'1.8.0_60\'\nDriver info: driver.version: unknown',
     systemInformation: 'System info: host: \'Nicholass-iMac.local\', ip: \'192.168.0.10\', os.name: \'Mac OS X\', os.arch: \'x86_64\', os.version: \'10.12.6\', java.version: \'1.8.0_60\'',
     supportUrl: null,
     cause: null,
     suppressed: [],
     message: 'Missing \'handle\' parameter\nBuild info: version: \'3.7.1\', revision: \'8a0099a\', time: \'2017-11-06T21:07:36.161Z\'\nSystem info: host: \'Nicholass-iMac.local\', ip: \'192.168.0.10\', os.name: \'Mac OS X\', os.arch: \'x86_64\', os.version: \'10.12.6\', java.version: \'1.8.0_60\'\nDriver info: driver.version: unknown',
     hCode: 722310431,
     class: 'org.openqa.selenium.InvalidArgumentException',
     buildInformation: null },
  class: 'org.openqa.selenium.remote.Response',
  status: 61 }
LOG     → Completed command window (5095 ms)

Notes

  • Works fine on both Chrome v62 and Safari 11

System Configuration

  • nightwatch v0.9.17
  • geckodriver v1.19.1
  • selenium-server-standalone-3.7.1
  • Node.js v7.6.0
  • Firefox v57.0.1 (Quantum)
  • MacOS Sierra v10.12.6

Nightwatch --env configuration

"firefox" : {
  "desiredCapabilities": {
    "browserName": "firefox",
    "marionette": true
  }
}

Most helpful comment

Unless I'm missing the purpose of this project, you seem to be closing issues and jumping to conclusions rather prematurely. I'm not sure why. Opening and tracking these issues helps your project.

I've included a snippet above that illustrates how this can be fixed in this project. I can issue a PR if you want me to.

All 12 comments

Continuing...

I'm not a WebDriver expert in any way (this is my first time working with the stuff) but..

If you add a handle parameter instead of name when POSTing, it works.

For example:

In nightwatch protocol.js:

function postRequest(path, data, callback) {

  // @NOTE Ridiculous monkey patch just for testing
  if (data.name) {
    data = Object.assign(data, {
      handle: data.name
    })  
  }
  // End of ridiculous monkey patch

  if (arguments.length === 2 && typeof data === 'function') {
    callback = data;
    data = '';
  }

  var options = {
    path : '/session/' + Nightwatch.sessionId + path,
    method : 'POST',
    data : data || ''
  };

  return sendRequest(options, function(result) {
    if (/\/element$/.test(options.path) && result.value) {
      result.value = validateElementEntry(result.value);
    } else if (/\/elements$/.test(options.path) && Array.isArray(result.value)) {
      result.value = result.value.map(function(entry) {
        return validateElementEntry(entry);
      });
    }

    if (typeof callback === 'function') {
      callback.call(this, result);
    }
  });
}

Having the same issue here. More or less same setup as @nicholaswmin

This is my system configuration:

  • nightwatch v0.9.19
  • geckodriver v0.19.1
  • selenium-server-standalone-3.8.1
  • Node.js v8.7.0
  • Firefox v57.0.1 (Quantum)
  • MacOS Sierra v10.12.6

I'm not sure whether the following issue could be related:
https://github.com/SeleniumHQ/selenium/issues/5064

Unless I'm missing the purpose of this project, you seem to be closing issues and jumping to conclusions rather prematurely. I'm not sure why. Opening and tracking these issues helps your project.

I've included a snippet above that illustrates how this can be fixed in this project. I can issue a PR if you want me to.

It is still an issue with

geckodriver v0.19.1
selenium-3.10.0
Firefox v59.0

Having same issue as above - Firefox can't switchWindow()

This workaround works for me:

https://github.com/dstepper/selenium/commit/2da01059bc3853f0d2a936a0bff18bd344d3aa95#diff-578329ec7273c4a024979fd0ebcda293

This is an issue in FF 62 and it is a blocker for us to be unable to extend our night watch test suite to run in FF...After investing so much time into nightwatch, I hate to see this basic functionality not compatible with one of the major browsers.

Just curious if anybody has any workarounds that work for them considering that https://github.com/dstepper/selenium/commit/2da01059bc3853f0d2a936a0bff18bd344d3aa95#diff-578329ec7273c4a024979fd0ebcda293 is not merged?

P.S. going round in circles here because @beatfactor closed this issue blaming it to be gecko specific but gecko shuttles us back to nightwatch: https://github.com/SeleniumHQ/selenium/issues/5831#issuecomment-384789011
What is next?

@kiran-ghe I'm sorry to hear about your frustration, but this issue should be fixed in the latest nightwatch version, v1.0.11. Could you please try upgrading?

Thanks @beatfactor we tried to use the Nightwatch version you mentioned but we can't even get the framework to launch, we get this error; it works fine in the current version 0.9.21:
Error reading external global file using "./environments/index"
Error: Cannot find module '/Users/michaeljk/workspace/nightwatchproject/configs/environments/index'
at Function.Module._resolveFilename (module.js:527:15)
at Function.Module._load (module.js:476:23)
at Module.require (module.js:568:17)
at require (internal/module.js:11:18)

@kiran-ghe would you mind sharing your nightwatch.json config?

@kiran-ghe please open a different ticket and include the above error and your config, if you don't mind.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lgaticaq picture lgaticaq  Â·  3Comments

antogyn picture antogyn  Â·  4Comments

betweenbrain picture betweenbrain  Â·  4Comments

maxgalbu picture maxgalbu  Â·  3Comments

manjero picture manjero  Â·  4Comments