nightwatch.js / Saucelabs - click() 不工作 [ 运行 .click() 命令在 <Element [name=@login_submitButton]> 上发生错误]

nightwatch.js / Saucelabs - click() not working [ An error occurred while running .click() command on <Element [name=@login_submitButton]>]

我一直在尝试 运行 使用 Nightwatch.js + Saucelabs 对 React 应用程序进行端到端测试用例,但在执行 .click() 方法时遇到以下错误。

错误: 运行ning .click() 命令发生错误:{"status":-1,"state":"","value":"{\"value\" : {\"stacktrace\": \"Backtrace:\n\tOrdinal0 [0x00E07DF3+1474035]\n\tOrdinal0 [0x00D807D1+919505]\n\tOrdinal0 [0x00D1CB43+510787]\n\tOrdinal0 [0x00CCDB60+187232]\n\tOrdinal0 [0x00CCD9B5+186805]\n\tOrdinal0 [0x00CA1BAB+7083]\n\tOrdinal0 [0x00CA2126+8486]\n\tOrdinal0 [0x00CA2F00+12032]\n\tGetHandleVerifier [0x00F6231C+1249612]\n\tGetHandleVerifier [0x00EB1575+525221]\n\tGetHandleVerifier [0x00EB1310+524608]\n\tOrdinal0 [0x00E15D28+1531176]\n\tGetHandleVerifier [0x00EB1D4A+527226]\n\tOrdinal0 [0x00D975F6+1013238]\n\tOrdinal0 [0x00D9746F+1012847]\n\tOrdinal0 [0x00CA1A16+6678]\n\tOrdinal0 [0x00CA174A+5962]\n\tGetHandleVerifier [0x0120992C+4032348]\n\tBaseThreadInitThunk [0x774438F4+36]\n\tRtlUnicodeStringToInteger [0x77B35E13+595]\n\tRtlUnicodeStringToInteger [0x77B35DDE+542]\n\", \"message\": \"invalid argument: missing command parameters\", \"error\": \"invalid argument\"}}","errorStatus":-1,"error":"An unknown error has occurred.","httpStatusCode":400}

下面是页面对象:

module.exports = {
  url: function () {
    return this.api.launchUrl
  },
  elements: {
    app: { selector: 'div[id="app"]' },
    login_usernameInput: { selector: 'input[id="user_id"]' },
    login_passwordInput: { selector: 'input[id="password"]' },
    login_submitButton: { selector: 'button[id="submit"]' }
  },
  commands: [
    {
      login () {
        return this
          .waitForElementPresent('span[id=welcomeToMyApp]')
          .setValue('@login_usernameInput', process.env.APP_USERNAME)
          .setValue('@login_passwordInput', process.env.APP_PASSWORD)
          .click('@login_submitButton')
          .waitForElementPresent('@app')
      }
    }
  ]
}

测试代码:

module.exports = {
  beforeEach: (browser, done) => {
    browser.page.loginPage()
      .navigate()
      .login()
    done()
  },

  'Test - DQM Page': function (browser) {
    const dqmPage = browser.page.dqmPage()

    dqmPage
      .navigate()
      .waitForElementVisible('body')
      .click('@nextCountryTab')
      .assert.visible('@nextCountry')
      .end()
  },

  afterEach: (browser, done) => {
    browser.custom().end()

    setTimeout(function () {
      done()
    }, 200)
  }
}

所有其他步骤,在 login() 方法中的 click() 之前工作得很好。甚至 setValue() 函数也执行得很好。

请注意,提交按钮非常明显且可点击。

我可以通过更新到最新版本的 Nightwatch 来解决这个问题。但是更新破坏了其他东西。这是一些关于更新后可能会出现问题的文档。

https://github.com/nightwatchjs/nightwatch/wiki/Migrating-to-Nightwatch-1.0

我通过指定使用以前版本的 Chrome(现在是 74)来解决这个问题。

"desiredCapabilities": {
  ... clipped out my other capabilities for brevity ...
  "version": "latest-1"
}

然后我将其更改为具体说明版本 74。这两个都有效,但我不希望 Chrome 升级到 76,然后如果我们还没有完成采用任何真正的版本,测试将再次失败修复是。

"desiredCapabilities": {
  ... again - clipped for brevity ...
  "browserName": "chrome",
  "version": "74.0"
}

SauceLabs 所说的应该工作如下。它对我不起作用。我从他们的博客 post https://wiki.saucelabs.com/pages/viewpage.action?pageId=88801611

得到了这个
"desiredCapabilities": {
  ... clipped other configs again ...
  "goog:chromeOptions": {"w3c": false}
}