本文介绍了使用Nightwatch测试Vue项目时出现TypeError ERR_UNESCAPED_CHARACTERS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用Vue CLI设置Nightwatch环境时遇到问题.此时,我只想使其与Chrome一起使用(我们将很快在Firefox中看到它),但是当我运行简单的测试时,它不起作用.

I have a problem trying to setup my Nightwatch environment with Vue CLI. At this point, I just want to make it work with Chrome (we'll see for Firefox soon) but when I run a simple test, It doesn't work.

这是我的测试文件:

module.exports = {
  'default e2e tests': browser => {
    browser
      .url("http://localhost:8080")
      .waitForElementVisible('#app', 5000)
      .assert.ok(true)
      .end()
  }
}

引发以下错误:

Error while running .isElementDisplayed() protocol action: TypeError [ERR_UNESCAPED_CHARACTERS]: Error while trying to create HTTP request for "/wd/hub/session/28a21f6ed7009d54e70663e3ed407eb6/element/[object Object]/displayed": Request path contains unescaped cha
racters
    at new ClientRequest (_http_client.js:115:13)
    at Object.request (http.js:42:10)
    at HttpRequest.createHttpRequest (C:\Users\john.doe\Desktop\Développement\App\vue\node_modules\nightwatch\lib\http\request.js:138:55)
    at HttpRequest.send (C:\Users\john.doe\Desktop\Développement\App\vue\node_modules\nightwatch\lib\http\request.js:217:29)
    at Promise (C:\Users\john.doe\Desktop\Développement\App\vue\node_modules\nightwatch\lib\transport\transport.js:193:15)
    at new Promise (<anonymous>)
    at Selenium2Protocol.sendProtocolAction (C:\Users\john.doe\Desktop\Développement\App\vue\node_modules\nightwatch\lib\transport\transport.js:191:12)
    at Selenium2Protocol.runProtocolAction (C:\Users\john.doe\Desktop\Développement\App\vue\node_modules\nightwatch\lib\transport\jsonwire.js:61:17)
    at Object.isElementDisplayed (C:\Users\john.doe\Desktop\Développement\App\vue\node_modules\nightwatch\lib\transport\actions.js:54:10)
    at Selenium2Protocol.executeProtocolAction (C:\Users\john.doe\Desktop\Développement\App\vue\node_modules\nightwatch\lib\transport\transport.js:239:48)

当我提供有效的选择器时出现此错误.我尝试使用不存在的选择器,在这种情况下,我得到一个简单的 ...预期为可见",但得到:未找到" .

I get this error when I provide a valid selector. I tried with a non existing selector and, in this case, I get a simple ... expected "visible" but got: "not found".

这是我的Nightwatch配置文件:

Here is my Nightwatch configuration file:

module.exports = {
  "src_folders": ["tests/e2e/specs"],
  "output_folder": "tests/e2e/reports",
  "page_objects_path": "tests/e2e/page-objects",
  "custom_assertions_path": "tests/e2e/custom-assertions",
  "custom_commands_path": "tests/e2e/custom-commands",
  "test_workers": {
    "enabled": true,
    "workers": "auto"
  },
  "selenium" : {
    "start_process" : true,
    "server_path" : "./node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-3.141.59.jar",
    "log_path" : "tests/e2e/logs",
    "host" : "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "./node_modules/chromedriver/lib/chromedriver/chromedriver.exe"
    }
  },
  "test_settings" : {
    "default" : {
      "launch_url": 'https://www.google.com',
      "selenium_port": 4444,
      "selenium_host": "localhost",
      "silent": true,
      "screenshots": {
        "enabled": true,
        "path": ""
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    },
    "chrome": {
      "desiredCapabilities": {
        "browserName": "chrome",
        "chromeOptions": {
          "w3c": false
        }
      },
      "webdriver": {
        "use_legacy_jsonwire": false
  }
    },
    "firefox": {
      "desiredCapabilities": {
        "browserName": "firefox",
        "alwaysMatch": {
          "acceptInsecureCerts": true,
          "moz:firefoxOptions": {
            "args": []
          }
        }
      }
    }
  }
};

任何可能导致此错误的想法?

Any ideas of what could produce this error?

让我知道是否应该从例如node_modules文件夹中提供其他文件.

Let me know if I should provide other files from the node_modules folder for instance.

推荐答案

按照Estus Flask的链接解决了我的问题:

Following the link of Estus Flask solved my problem:

只需在默认配置中添加此行

Simply add this lines in the default configuration

"chromeOptions": {
    "w3c": false
}

这篇关于使用Nightwatch测试Vue项目时出现TypeError ERR_UNESCAPED_CHARACTERS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 01:28