nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.83k stars 1.32k forks source link

.frame() does not change focus to browser top-level default context #2047

Closed liunate closed 5 years ago

liunate commented 5 years ago

What the issue is

Either .frame() or .frame(undefined) or .frame(null) is supposed to switch browser context to default top-level one but receives missing 'id' or no such frame error with or without selenium server.

The line https://github.com/nightwatchjs/nightwatch/blob/848b1347ad7a84263d93c40223c9f7a40530a5ee/lib/transport/jsonwire/actions.js#L154 should POST with { id: null } in request body given either .frame arguments listed above per W3C spec https://www.w3.org/TR/webdriver/#switch-to-frame:

  1. Let id be the result of getting the property "id" from the parameters argument.
  2. If id is not null, a Number object, or an Object that represents a web element, return error with error code no such frame.

Simple test showing the issue:

Repo https://github.com/liunate/nightwatch-issue-frame-missing-id

Nightwatch Config

{
  "src_folders": [
    "tests"
  ],
  "webdriver": {
    "start_process": true,
    "server_path": "node_modules/.bin/chromedriver",
    "port": 9515
  },
  "test_settings": {
    "default": {
      "launch_url": "https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe",
      "silent": false,
      "screenshots": {
        "enabled"    : true,
        "on_failure" : true,
        "on_error"   : true,
        "path"       : "tests_output/screenshots"
      },
      "globals": {
        "abortOnAssertionFailure": false
      },
      "desiredCapabilities": {
        "browserName": "chrome"
      }
    }
  }
}

Test Case

  showMissingIdError: (client) => {

    const elementOutSideOfIFrame = '#Result_2'; // Title 'Result' just above iframe element on page

    const iframeId = 'frame_Example2';
    const deeperIframeId = 'Example2';
    const elementWithinIFrame = '#mapDiv';

    client.
      url(client.launch_url).
      waitForElementVisible(elementOutSideOfIFrame).
      frame(iframeId).
      frame(deeperIframeId).
      waitForElementVisible(elementWithinIFrame). 
      frame(null). // Error while running .switchToFrame() protocol action: invalid argument: missing 'id'
      frame(). // Error while running .switchToFrame() protocol action: invalid argument: missing 'id'
      waitForElementVisible(elementOutSideOfIFrame).
      waitForElementNotVisible(elementWithinIFrame);
  }

Verbose nightwatch output

 → Running command: frame ()
   Request POST  /session/3e9e8d20ed874049d3ff2f79b3988324/frame  
   { id: 'null' }
   Response 200 POST /session/3e9e8d20ed874049d3ff2f79b3988324/frame (6ms)
   { sessionId: '3e9e8d20ed874049d3ff2f79b3988324',
     status: 8,
     value: 
      { message: 'no such frame',
        error: 
         [ '  (Session info: chrome=72.0.3626.121)',
           '  (Driver info: chromedriver=2.46.628411 (3324f4c8be9ff2f70a05a30ebc72ffb013e1a71e),platform=Mac OS X 10.14.1 x86_64)' ] } }
 Error while running .switchToFrame() protocol action: no such frame

 → Completed command frame () (6ms)
 → Running command: frame ()
   Request POST  /session/3e9e8d20ed874049d3ff2f79b3988324/frame  

   Response 200 POST /session/3e9e8d20ed874049d3ff2f79b3988324/frame (4ms)
   { sessionId: '3e9e8d20ed874049d3ff2f79b3988324',
     status: 61,
     value: 
      { message: 'invalid argument: missing \'id\'',
        error: 
         [ '  (Session info: chrome=72.0.3626.121)',
           '  (Driver info: chromedriver=2.46.628411 (3324f4c8be9ff2f70a05a30ebc72ffb013e1a71e),platform=Mac OS X 10.14.1 x86_64)' ] } }
 Error while running .switchToFrame() protocol action: invalid argument: missing 'id'

 → Completed command frame () (8ms)

versions

nightwatch 1.0.19 chrome=72.0.3626.121 chromedriver=2.46.628411 (3324f4c8be9ff2f70a05a30ebc72ffb013e1a71e),platform=Mac OS X 10.14.1 x86_64) macOS Majove 10.14.1 (18B75) Node v8.11.2 Selenium not used

liunate commented 5 years ago

PR #2048 is sent to correct the behavior.

VasylQA commented 5 years ago

I'm having the same issue after update to 1.0.19 version

joshden commented 5 years ago

Thanks @liunate. For now I'm installing Nightwatch NPM with git+https://github.com/nightwatchjs/nightwatch.git#612ae4b4388e1221704b2e3908547c0178bdc5ec to have this fix where I'm testing upgrading my tests to use Nightwatch 1.x.x. Hopefully it will be merged and included in a build soon.