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

[Firefox] Form submission not working with .submitForm(). Working with .click() #2937

Closed mwilc0x closed 2 years ago

mwilc0x commented 2 years ago

Hi,

Am seeing an error when using .submitForm() with firefox. Am not seeing this issue with chrome. Note: the form can be successfully submitted with click().

 Error while running .elementSubmit() protocol action: An unknown error has occurred.

   TimeoutError: An error occurred while running .submitForm() command on <input[value=Update]>: 
   {"status":-1,"value":null,"code":"","errorStatus":"","error":"An unknown error has occurred.","httpStatusCode":405}

Environment

nightwatch 1.7.11
node v16.13.0
firefox (78.15.0) on linux 5.10.46-5rodete1-amd64 platform
chrome (95.0.4638.69) on linux platform

Test Code

select: function (mode) {
  return this.log(`Selecting ${mode} JS mode`)
    .waitForElementVisible('form')
    .click(`input[value=${mode}]`)
    .submitForm('input[value=Update]');
},

HTML

  <form action="/examples/sample-pub/update-setup" method="post">
    <div>
      <h3>Script:</h3>
      <label>
        <input type="radio" name="script" value="autopush"
            <%#script_autopush%> checked<%/script_autopush%>> Autopush
      </label>
      <label>
        <input type="radio" name="script" value="tt"
            <%#script_tt%> checked<%/script_tt%>> TT
      </label>
    </div>
    <div class="buttons">
      <input type="submit" value="Update"></input>
    </div>
  </form>

Configuration

module.exports = {
  src_folders: ['test/e2e/tests'],
  globals_path: 'globals.js',
  page_objects_path: 'test/e2e/pages',

  test_settings: {
    default: {
      launch_url: 'http://localhost:8000/examples/sample-pub/1',
      custom_commands_path: 'test/e2e/commands',
      skip_testcases_on_fail: false,
    },

    chrome: {
      globals: {
        webdriverProcess: 'chromedriver',
      },

      desiredCapabilities: {
        browserName: 'chrome',
        chromeOptions: {
          args: ['--headless'],
          w3c: true
        },
      },

      webdriver: {
        start_process: true,
        server_path: Services.chromedriver ? Services.chromedriver.path : '',
        port: 9515,
      },
    },

    firefox: {
      globals: {
        webdriverProcess: 'geckodriver',
      },

      desiredCapabilities: {
        browserName: 'firefox',
        acceptInsecureCerts: true,
        alwaysMatch: {
          'moz:firefoxOptions': {
            args: ['-headless'],
          },
        },
      },

      webdriver: {
        start_process: true,
        server_path: 'node_modules/.bin/geckodriver',
        // server_path: Services.geckodriver ? Services.geckodriver.path : '',
        cli_args: ['--log', 'debug'],
        port: 4444,
      },
    },
  },
};
mwilc0x commented 2 years ago

Actually, it seems that .submitForm should not be used with w3c:true? Am now seeing this for chrome with w3c:true enabled (we have only just enabled):

TimeoutError: An error occurred while running .submitForm() command on <input[value=Update]>: unknown command; unknown command: Cannot call non W3C standard command while in W3C mode {"status":-1,"value":{"error":"unknown command","message":"unknown command: Cannot call non W3C standard command while in W3C mode","stacktrace":""},"code":"","errorStatus":"","error":"unknown command: Cannot call non W3C standard command while in W3C mode","httpStatusCode":404}e

Is this WAI? Is there a way that the error message could be updated in FF to provide same context as does Chrome?

AutomatedTester commented 2 years ago

We're going to need to add something like what selenium does.

gravityvi commented 2 years ago

The submitForm command is based on a legacy endpoint from the JsonWire protocol which was been removed in the W3C Webdriver spec. I don’t think we can do anything to resolve this in Nightwatch v1.x . The incompatibility has been fixed in Nightwatch v2. You can try that out

gravityvi commented 2 years ago

Nightwatch v2 is using selenium underneath for submitForm command.