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

Safari: Unknown error is thrown "[InvalidArgumentError] key is not a string: undefined" whenever we perform a key action using the new Actions API #3488

Open chriscuba23 opened 1 year ago

chriscuba23 commented 1 year ago

Description of the bug/issue

When I use a key action such as keyDown or keyUp on Safari then I get thrown an unknown error (not from the driver) and the command gets not completed

Steps to reproduce

  1. Open Safari
  2. Perform the COMMAND+OPTION+E keyDown/Up commands so as to clear the Safari cache using the new Actions API
  3. You are getting thrown an error

Sample test

module.exports = {

'Example': function(browser){

        browser
          .perform(function () {
            const actions = this.actions({ async: true });

            return actions
              .keyDown(Keys.COMMAND)
              .keyDown(Keys.OPTION)
              .keyDown('E')
              .keyUp(Keys.COMMAND)
              .keyUp(Keys.OPTION)
              .keyUp('E')
          })

}

}

Command to run

node nightwatch -e h_chrome tests/safariKeysExample.js --verbose

Verbose Output

[Safari Keys Example] Test Suite
────────────────────────────────────────────────────────────────
 Starting ChromeDriver with server_path=/Users/*/e2e_tests/node_modules/chromedriver/lib/chromedriver/chromedriver...
   Request POST /session  
   {
     capabilities: {
       firstMatch: [ {} ],
       alwaysMatch: {
         browserName: 'chrome',
         'goog:chromeOptions': {
           w3c: true,
           args: [
             '--no-sandbox',
             '--ignore-certificate-errors',
             '--allow-insecure-localhost',
             '--headless',
             '--disable-gpu',
             '--disable-software-rasterizer',
             '--window-size=1920,925',
             '--log-level=3',
             '--disable-logging'
           ],
           prefs: { 'profile.default_content_setting_values.cookies': 1 }
         }
       }
     }
  }
   Response 200 POST /session (528ms)
   {
     value: {
       capabilities: {
         acceptInsecureCerts: false,
         browserName: 'chrome',
         browserVersion: '107.0.5304.110',
         chrome: {
           chromedriverVersion: '107.0.5304.62 (1eec40d3a5764881c92085aaee66d25075c159aa-refs/branch-heads/5304@{#942})',
           userDataDir: '/var/folders/b4/664zl5gd713gcqvq6cgyh72r0000gn/T/.com.google.Chrome.sWQAdQ'
         },
         'goog:chromeOptions': { debuggerAddress: 'localhost:60765' },
         networkConnectionEnabled: false,
         pageLoadStrategy: 'normal',
         platformName: 'mac os x',
         proxy: {},
         setWindowRect: true,
         strictFileInteractability: false,
         timeouts: { implicit: 0, pageLoad: 300000, script: 30000 },
         unhandledPromptBehavior: 'dismiss and notify',
         'webauthn:extension:credBlob': true,
         'webauthn:extension:largeBlob': true,
         'webauthn:virtualAuthenticators': true
       },
       sessionId: '485608bf4aa73421dafae6b25d839302'
     }
  }
  Using: chrome (107.0.5304.110) on MAC OS X.

 Received session with ID: 485608bf4aa73421dafae6b25d839302

 → Running [before]:
 → Completed [before].

  Running Example:
───────────────────────────────────────────────────────────────────────────────────────────────────
 → Running [beforeEach]:
 → Completed [beforeEach].

 → Running command: perform ([Function])
  → Completed command: perform ([Function]) (8ms)

 → Running command: saveScreenshot ('/Users//e2e_tests/failures/safariKeysExample/Example_FAILED_Nov-21-2022-174448-GMT+0200.png', [Function])

 → Running command: screenshot (false, [Function])
   Request GET /session/485608bf4aa73421dafae6b25d839302/screenshot  

   Response 200 GET /session/485608bf4aa73421dafae6b25d839302/screenshot (745ms)
   {
     value: 'iVBORw0KGgoAAAANSUhEUgAADwAAAAc6CAYAAADINZKRAAABJmlDQ1BTa2lhAAAokX2RPUvDUBSGH9suoiCiooNDJnFR+6Gxg0sr...',
     suppressBase64Data: true
  }
  → Completed command: screenshot (false, [Function]) (754ms)
  → Completed command: saveScreenshot ('/Users//e2e_tests/failures/safariKeysExample/Example_FAILED_Nov-21-2022-174448-GMT+0200.png', [Function]) (757ms)
 → Running [afterEach]:
 → Completed [afterEach].

  FAILED: 1 errors (865ms)
 → Running [after]:
 → Completed [after].

 → Running command: end (true)

 → Running command: session ('delete', [Function])
   Request DELETE /session/485608bf4aa73421dafae6b25d839302  

   Response 200 DELETE /session/485608bf4aa73421dafae6b25d839302 (60ms)
   { value: null }
  → Completed command: session ('delete', [Function]) (67ms)
 Wrote log file to: /Users//e2e_tests/logs/safariKeysExample_chromedriver.log.
  → Completed command: end (true) (72ms)

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

  ️TEST FAILURE (2.074s): 
   - 1 error during execution; 
   - 0 tests failed; 
   - 0/1 tests passed

   ✖ 1) safariKeysExample

   – Example (865ms)

   InvalidArgumentError
   Error while running "perform" command: [InvalidArgumentError] key is not a string: undefined

    Error location:
    /Users//e2e_tests/tests/safariKeysExample.js:
    –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
     4 |     
     5 |             browser
     6 |               .perform(function () { 
     7 |                 const actions = this.actions({ async: true });
     8 |     
    –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

  - OTHER ERRORS:
  InvalidArgumentError
   Error while running "perform" command: [InvalidArgumentError] key is not a string: undefined

    Error location:
    /Users//e2e_tests/tests/safariKeysExample.js:
    –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
     4 |     
     5 |             browser
     6 |               .perform(function () { 
     7 |                 const actions = this.actions({ async: true });
     8 |     
    –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

Nightwatch Configuration

No response

Nightwatch.js Version

2.3.9

Node Version

17.7.2

Browser

Safari Version 16.0 (17614.1.25.9.10, 17614)

Operating System

macOS Ventura 13.0.1

Additional Information

No response

gravityvi commented 1 year ago

could you paste in verbose logs of the test run. That would help us rectify the issue faster

chriscuba23 commented 1 year ago

Hello, the verbose one is updated. You can find it at the respective section

gravityvi commented 1 year ago

@chriscuba23 Thanks for the details. We expose all the keys defined in w3c spec for keyboard input. Unfortunately, there is no built-in Option key but you can use "\u2325" directly as a string and supply it as an argument.

AutomatedTester commented 1 year ago

@chriscuba23 did the last comment help?

chriscuba23 commented 1 year ago

@AutomatedTester unfortunately not, since the codepoint didn't work. I am still trying to find a solution or a workaround for that. You can close the issue as stale if you want and I will create a new one if I cant solve it