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.79k stars 1.31k forks source link

switchWindow not working with Safari when using remote Selenium #2494

Closed kretschmannj closed 3 years ago

kretschmannj commented 4 years ago

The switchWindow command is sending a 'handle' parameter rather than the expected 'name' parameter to the safari 'window' command. Here's the verbose output ...

→ Running command: switchWindow ('page-5967FDB0-FA72-4BE1-81C7-6E9A90FDDDBD')

 → Running command: window ('POST', 'page-5967FDB0-FA72-4BE1-81C7-6E9A90FDDDBD', [Function])
   Request POST http://hub.lambdatest.com /wd/hub/session/97B9D4DF-1D8C-4E05-92B4-A97EF0A5C374/window  
   { handle: 'page-5967FDB0-FA72-4BE1-81C7-6E9A90FDDDBD' }
   Response 400 POST http://hub.lambdatest.com/wd/hub/session/97B9D4DF-1D8C-4E05-92B4-A97EF0A5C374/window (347ms)
Request body does not contain required parameter 'name'.

Here's my code snippet ...

    before : (browser) => {
        browser.url("https://alaska.magellanrx.com/")
        browser.verify.elementPresent('ul+ span')
        browser.windowHandles( handles => { // doesn't work in firefox or Safari 12+
            console.log(handles)
            browser.switchWindow(handles.value[0]) // doesn't work in safari
        })
    },

Safari version 11 Nightwatch version 1.4.2

vicwomg commented 4 years ago

Could be related: switching frames seems broken in a similar way.

 → Running command: frame (0)
   Request POST  /session/60E92292-FF5B-4621-BF7C-54C23D07BBD1/frame  
{}
   Response 404 POST /session/60E92292-FF5B-4621-BF7C-54C23D07BBD1/frame (2ms)
   {
     value: {
       error: 'no such frame',
       message: "Request body does not contain required parameter 'id'.",
       stacktrace: ''
     }
}
 Error while running .switchToFrame() protocol action: Request body does not contain required parameter 'id'.

Safari 14 / Nightwatch 1.4.2

kretschmannj commented 4 years ago

Can the priority be bumped up on this? Unless someone has a workaround, there is no way to switch windows in Safari. Again, the problem appears to be that Safari driver is expecting a 'name' parameter but Nightwatch is sending a 'handle' parameter.

beatfactor commented 4 years ago

@kretschmannj @ArpitLT works fine on local Safari 14 and Firefox.

kretschmannj commented 4 years ago

@beatfactor Did you run the code snippet I included above? I just tried to run this code on Safari 14 and got this error ...

 → Running command: windowHandles ([Function])
  → Completed command: elements ('css selector', {name, __index, __selector, locateStrategy, pseudoSelector, parent, resolvedElement}, [Function]) (335ms)
   Request GET http://hub.lambdatest.com /wd/hub/session/FBDC5A98-B7F6-4751-A6A2-DFCEF36956D7/window_handles  
   Response 404 GET http://hub.lambdatest.com/wd/hub/session/FBDC5A98-B7F6-4751-A6A2-DFCEF36956D7/window_handles (245ms)
   {
     value: {
       error: 'unknown command',
       message: "The command 'GET /session/FBDC5A98-B7F6-4751-A6A2-DFCEF36956D7/window_handles' was not found.",
       stacktrace: ''
     }
}
 Error while running .getAllWindowHandles() protocol action: unknown command – The command 'GET /session/FBDC5A98-B7F6-4751-A6A2-DFCEF36956D7/window_handles' was not found.

{
  status: -1,
  code: '',
  state: '',
  value: {
    error: 'unknown command',
    message: "The command 'GET /session/FBDC5A98-B7F6-4751-A6A2-DFCEF36956D7/window_handles' was not found.",
    stacktrace: ''
  },
  errorStatus: '',
  error: "unknown command – The command 'GET /session/FBDC5A98-B7F6-4751-A6A2-DFCEF36956D7/window_handles' was not found.",
  httpStatusCode: 404
}
  → Completed command: windowHandles ([Function]) (269ms)
beatfactor commented 4 years ago

@kretschmannj The windowHandles command works fine on Safari and Firefox when run locally. You didn't make any mention that you're using as a cloud provider, as I can see from your log, and also didn't include any config (as it is required in the bug report template). This makes it quite difficult to identify the problem.

kretschmannj commented 4 years ago

@beatfactor Good to know that you're able to test Safari locally. I'm on Windows and unfortunately don't have the ability to test Safari on my local machine, so we're running the test on the LambdaTest grid. Here's the nightwatch.conf.js ....

nightwatch_config = {
  src_folders: ["tests"],
  page_objects_path: ["framework/pages"],
  custom_commands_path: ['custom_commands'],
  custom_assertions_path: ['custom_assertions'],
  test_settings: {
    default: {
      selenium_host: "hub.lambdatest.com",
      selenium_port: 80,
      username: 'kretschmannj',
      access_key: '---------------------------------------------',
    },
    safari: {
      desiredCapabilities: {
        "platform" : "High Sierra",
        "browserName" : "Safari",
        "version" : "latest",
        "resolution" : "1920x1080",
        "safari.cookies" : true
      }
    }
  }
}
module.exports = nightwatch_config
stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had any recent activity. If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.

kretschmannj commented 3 years ago

This issue has been fixed on the LambdaTest side by applying custom translations.

kmahata commented 3 years ago

Could be related: switching frames seems broken in a similar way.

 → Running command: frame (0)
   Request POST  /session/60E92292-FF5B-4621-BF7C-54C23D07BBD1/frame  
{}
   Response 404 POST /session/60E92292-FF5B-4621-BF7C-54C23D07BBD1/frame (2ms)
   {
     value: {
       error: 'no such frame',
       message: "Request body does not contain required parameter 'id'.",
       stacktrace: ''
     }
}
 Error while running .switchToFrame() protocol action: Request body does not contain required parameter 'id'.

Safari 14 / Nightwatch 1.4.2

Did you get any solution for it? I am using saucelabs and chrome,FF,Edge works fine in selecting frame but in safari it fails