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

not able to find frame with nightwatch v2 #3097

Closed kmahata closed 2 years ago

kmahata commented 2 years ago

Describe the bug

We are using nightwatch 1.7.12 and didnt face any issues in selecting frames. While running some tests with v2 we are noticing frame is throwing error. Tried to reproduce the issue with different test demo site which has iframe

error: InvalidArgumentError: invalid argument: 'id' can not be string
    (Session info: chrome=98.0.4758.102)
      at Object.throwDecodedError (/Users/***/Documents/workspace/seleniumExp/node_modules/selenium-webdriver/lib/error.js:539:15)
      at parseHttpResponse (/Users/***/Documents/workspace/seleniumExp/node_modules/selenium-webdriver/lib/http.js:647:13)
      at Executor.execute (/Users/***/Documents/workspace/seleniumExp/node_modules/selenium-webdriver/lib/http.js:573:28)
      at processTicksAndRejections (internal/process/task_queues.js:95:5)
      at async Driver.execute (/Users/***/Documents/workspace/seleniumExp/node_modules/selenium-webdriver/lib/webdriver.js:735:17)
      at async MethodMappings.switchToFrame (/Users/***/Documents/workspace/seleniumExp/node_modules/nightwatch/lib/transport/selenium-webdriver/method-mappings.js:337:11)
      at async /Users/***/Documents/workspace/seleniumExp/node_modules/nightwatch/lib/transport/selenium-webdriver/actions.js:67:18 {
    remoteStacktrace: ''
  },

Sample test

describe('Iframe issue', ()=>{
    it('iframe', (browser)=>{
        browser.url("https://demoqa.com/frames")
        browser.pause(10000)
        browser.frame('frame1')
        browser.frame('frame1', function(result){
            console.log(result)
        })

    })
})

BROWSER - chrome 98

// Please add the sample test here

Run with command

 node_modules/.bin/nightwatch -g firstTest.js --config nightwatch.conf.js
### Verbose output
⠋ Starting ChromeDriver on port 9515...
 Starting ChromeDriver with server_path=/Users/***/Documents/workspace/seleniumExp/node_modules/chromedriver/lib/chromedriver/chromedriver...
   Request POST /session  
   {
     desiredCapabilities: {
       browserName: 'chrome',
       name: 'Iframe issue',
       'goog:chromeOptions': {}
     },
     capabilities: { alwaysMatch: { browserName: 'chrome', 'goog:chromeOptions': {} } }
⠋ Starting ChromeDriver on port 9515...
   Response 200 POST /session (2351ms)
   {
     value: {
       capabilities: {
         acceptInsecureCerts: false,
         browserName: 'chrome',
         browserVersion: '98.0.4758.102',
         chrome: {
           chromedriverVersion: '98.0.4758.80 (7f0488e8ba0d8e019187c6325a16c29d9b7f4989-refs/branch-heads/4758@{#972})',
           userDataDir: '/var/folders/04/hfp8pt157rl8sqg9s9lhff3c0k1ts2/T/.com.google.Chrome.z4BzxX'
         },
         'goog:chromeOptions': { debuggerAddress: 'localhost:64621' },
         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: 'efb2737fbdbb80686c9a2f547f235d8e'
     }
ℹ Connected to ChromeDriver on port 9515 (2434ms).
  Using: chrome (98.0.4758.102) on MAC OS X.

 Received session with ID: efb2737fbdbb80686c9a2f547f235d8e

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

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

 → Running command: url ('https://demoqa.com/frames')
  ⠋ Loading url: https://demoqa.com/frames
   Request POST /session/efb2737fbdbb80686c9a2f547f235d8e/url  
  ⠧ Loading url: https://demoqa.com/frames
   Response 200 POST /session/efb2737fbdbb80686c9a2f547f235d8e/url (12704ms)
  ℹ Loaded url https://demoqa.com/frames in 12707ms
  → Completed command: url ('https://demoqa.com/frames') (12708ms)

 → Running command: pause (10000)
  → Completed command: pause (10000) (10001ms)

 → Running command: frame ('frame1')
   Request POST /session/efb2737fbdbb80686c9a2f547f235d8e/frame  
   { id: 'frame1' }
   Response 400 POST /session/efb2737fbdbb80686c9a2f547f235d8e/frame (7ms)
   {
     value: {
       error: 'invalid argument',
       message: "invalid argument: 'id' can not be string\n" +
         '  (Session info: chrome=98.0.4758.102)',
       stacktrace: ''
     }
  }
  → Completed command: frame ('frame1') (8ms)

 → Running command: frame ('frame1', [Function])
   Request POST /session/efb2737fbdbb80686c9a2f547f235d8e/frame  
   { id: 'frame1' }
   Response 400 POST /session/efb2737fbdbb80686c9a2f547f235d8e/frame (2ms)
   {
     value: {
       error: 'invalid argument',
       message: "invalid argument: 'id' can not be string\n" +
         '  (Session info: chrome=98.0.4758.102)',
       stacktrace: ''
     }
  }
{
  **error: InvalidArgumentError: invalid argument: 'id' can not be string
    (Session info: chrome=98.0.4758.102)
      at Object.throwDecodedError (/Users/***/Documents/workspace/seleniumExp/node_modules/selenium-webdriver/lib/error.js:539:15)
      at parseHttpResponse (/Users/***/Documents/workspace/seleniumExp/node_modules/selenium-webdriver/lib/http.js:647:13)
      at Executor.execute (/Users/***/Documents/workspace/seleniumExp/node_modules/selenium-webdriver/lib/http.js:573:28)
      at processTicksAndRejections (internal/process/task_queues.js:95:5)
      at async Driver.execute (/Users/***/Documents/workspace/seleniumExp/node_modules/selenium-webdriver/lib/webdriver.js:735:17)
      at async MethodMappings.switchToFrame (/Users/***/Documents/workspace/seleniumExp/node_modules/nightwatch/lib/transport/selenium-webdriver/method-mappings.js:337:11)
      at async /Users/***/Documents/workspace/seleniumExp/node_modules/nightwatch/lib/transport/selenium-webdriver/actions.js:67:18 {
    remoteStacktrace: ''
  },**
  status: -1,
  value: null
}
  → Completed command: frame ('frame1', [Function]) (5ms)
 → Running [afterEach]:
 → Completed [afterEach].
No assertions ran.

 → Running [after]:
 → Completed [after].

 → Running command: end ()

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

   Response 200 DELETE /session/efb2737fbdbb80686c9a2f547f235d8e (52ms)
   { value: null }
  → Completed command: session ('delete', [Function]) (54ms)
 Wrote log file to: /Users/***/Documents/workspace/seleniumExp/logs/firstTest_chromedriver.log.
  → Completed command: end () (59ms)
 ChromeDriver process closed.

Configuration

nightwatch.conf.js

```js { // Autogenerated by Nightwatch // Refer to the online docs for more details: https://nightwatchjs.org/gettingstarted/configuration/ const Services = {}; loadServices(); module.exports = { // An array of folders (excluding subfolders) where your tests are located; // if this is not specified, the test source must be passed as the second argument to the test runner. src_folders: ["./tests"], // See https://nightwatchjs.org/guide/working-with-page-objects/ page_objects_path: '', // See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands custom_commands_path: '', // See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-assertions custom_assertions_path: '', // See https://nightwatchjs.org/guide/#external-globals globals_path : '', webdriver: {}, test_settings: { default: { disable_error_log: true, launch_url: 'https://nightwatchjs.org', screenshots: { enabled: false, path: 'screens', on_failure: true }, desiredCapabilities: { browserName : 'chrome' }, webdriver: { start_process: true, server_path: (Services.chromedriver ? Services.chromedriver.path : '') } }, safari: { desiredCapabilities : { browserName : 'safari', alwaysMatch: { acceptInsecureCerts: false } }, webdriver: { port: 4445, start_process: true, server_path: '/usr/bin/safaridriver' } }, firefox: { desiredCapabilities : { browserName : 'firefox', alwaysMatch: { acceptInsecureCerts: true, 'moz:firefoxOptions': { args: [ // '-headless', // '-verbose' ] } } }, webdriver: { start_process: true, port: 4444, server_path: (Services.geckodriver ? Services.geckodriver.path : ''), cli_args: [ // very verbose geckodriver logs // '-vv' ] } }, chrome: { desiredCapabilities : { browserName : 'chrome', 'goog:chromeOptions' : { // More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/ // // This tells Chromedriver to run using the legacy JSONWire protocol (not required in Chrome 78) w3c: false, args: [ //'--no-sandbox', //'--ignore-certificate-errors', //'--allow-insecure-localhost', //'--headless' ] } }, webdriver: { start_process: true, port: 9515, server_path: (Services.chromedriver ? Services.chromedriver.path : ''), cli_args: [ // --verbose ] } }, edge: { desiredCapabilities : { browserName : 'MicrosoftEdge', 'ms:edgeOptions' : { w3c: false, // More info on EdgeDriver: https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium/capabilities-edge-options args: [ //'--headless' ] } }, webdriver: { start_process: true, // Download msedgedriver from https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium/ // and set the location below: server_path: '', cli_args: [ // --verbose ] } }, ////////////////////////////////////////////////////////////////////////////////// // Configuration for when using the browserstack.com cloud service | // | // Please set the username and access key by setting the environment variables: | // - BROWSERSTACK_USER | // - BROWSERSTACK_KEY | // .env files are supported | ////////////////////////////////////////////////////////////////////////////////// browserstack: { selenium: { host: 'hub-cloud.browserstack.com', port: 443 }, // More info on configuring capabilities can be found on: // https://www.browserstack.com/automate/capabilities?tag=selenium-4 desiredCapabilities: { 'bstack:options' : { userName: '${BROWSERSTACK_USER}', accessKey: '${BROWSERSTACK_KEY}', } }, disable_error_log: true, webdriver: { timeout_options: { timeout: 15000, retry_attempts: 3 }, keep_alive: true, start_process: false } }, 'browserstack.local': { extends: 'browserstack', desiredCapabilities: { 'browserstack.local': true } }, 'browserstack.chrome': { extends: 'browserstack', desiredCapabilities: { browserName: 'chrome', chromeOptions : { w3c: false } } }, 'browserstack.firefox': { extends: 'browserstack', desiredCapabilities: { browserName: 'firefox' } }, 'browserstack.ie': { extends: 'browserstack', desiredCapabilities: { browserName: 'internet explorer', browserVersion: '11.0' } }, 'browserstack.safari': { extends: 'browserstack', desiredCapabilities: { browserName: 'safari' } }, 'browserstack.local_chrome': { extends: 'browserstack.local', desiredCapabilities: { browserName: 'chrome' } }, 'browserstack.local_firefox': { extends: 'browserstack.local', desiredCapabilities: { browserName: 'firefox' } }, ////////////////////////////////////////////////////////////////////////////////// // Configuration for when using the Selenium service, either locally or remote, | // like Selenium Grid | ////////////////////////////////////////////////////////////////////////////////// selenium_server: { // Selenium Server is running locally and is managed by Nightwatch selenium: { start_process: true, port: 4444, server_path: (Services.seleniumServer ? Services.seleniumServer.path : ''), cli_args: { 'webdriver.gecko.driver': (Services.geckodriver ? Services.geckodriver.path : ''), 'webdriver.chrome.driver': (Services.chromedriver ? Services.chromedriver.path : '') } } }, 'selenium.chrome': { extends: 'selenium_server', desiredCapabilities: { browserName: 'chrome', chromeOptions : { w3c: false } } }, 'selenium.firefox': { extends: 'selenium_server', desiredCapabilities: { browserName: 'firefox', 'moz:firefoxOptions': { args: [ // '-headless', // '-verbose' ] } } } } }; function loadServices() { try { Services.seleniumServer = require('selenium-server'); } catch (err) {} try { Services.chromedriver = require('chromedriver'); } catch (err) {} try { Services.geckodriver = require('geckodriver'); } catch (err) {} } } ```

| nightwatch --version | VERSION | 2.0.9

| Browser driver | Version | | NAME | VERSION | | chromedriver | 98 |

-->

| OS | Version | Mac Monterey | NAME | VERSION |

vaibhavsingh97 commented 2 years ago

@kmahata Thanks for raising the issue, but in order to triage the issue, can you please reformat the issue. Please visit https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks for more information on how to format code blocks

kmahata commented 2 years ago

@vaibhavsingh97 - updated. Let me know if other details are needed

SDETQATestAutomation commented 2 years ago

I was just trying and got the working solution.

var switchToframe=false;
const resultElement = await browser.element("locateStrategy","locator");
await browser.frame(resultElement,function(result){
    var switchToSanboxframeStatus=result.status;
    console.log("switchToSanboxframeStatus "+ switchToSanboxframeStatus);
    if(switchToSanboxframeStatus==0){
        switchToframe=true;
    }
});
reallymello commented 2 years ago

I'm running into the same issue. In the older 1.x versions I could simply do browser.frame("FrameStringIdHere"); but in 2.0 it throws an error Error while running .switchToFrame() protocol action: invalid argument: 'id' can not be string (Session info: chrome=99.0.4844.83)