【问题标题】:Codeceptjs Headless tests with https do not work使用 https 的 Codeceptjs 无头测试不起作用
【发布时间】:2019-03-03 10:03:17
【问题描述】:

当我使用 https 无头运行测试时,会出现以下错误

bash Error: move target out of bounds: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.

在没有 --headless 选项的情况下运行,它可以工作但速度较慢。 使用 --headless 以 http 方式运行也可以

  • CodeceptJS 版本:最新
  • NodeJS 版本:4.2.6
  • 操作系统:薄荷
  • WebDriverIO:最​​新
  • 配置文件:

```json

{
  "tests": "./**/*_test.js",
  "timeout": 10000,
  "output": "output",
  "helpers": {
    "WebDriverIO": {
      "smartWait": 50,
      "url": "https://172.17.0.1/",
      "browser": "chrome",
      "restart": false,
      "desiredCapabilities": {
        "chromeOptions": {
          "args":[
                  "--window-size=1200,1200",
                  "--headless"]
        }
      }
    }
  },
  "include": {
    "I": "./steps_file.js",
    "loginPage": "./pages/Login.js",
    "defaultData": "./Data/defaultData.js",
    "registerPage": "./pages/Register.js",
    "menu": "./pages/Menus.js",
    "profilePage": "./pages/Profile.js",
    "subscription": "./pages/Subscription.js",
    "recordsPage": "./pages/Records.js"
  },
  "bootstrap": true,
  "name": "CodeceptJS",
  "plugins": {
    "allure": {
      "enabled": "true"    }
  }
}

```

【问题讨论】:

    标签: selenium webdriver-io codeceptjs


    【解决方案1】:

    在指定窗口大小时,请尝试使用x 而不是逗号 (,)。 示例:

    --window-size=1920x1080
    

    【讨论】:

    • 这不是问题:/
    【解决方案2】:

    也许这与此有关:

    https://www.chromium.org/for-testers/bug-reporting-guidelines/uncaught-securityerror-failed-to-read-the-localstorage-property-from-window-access-is-denied-for-this-document

    您可以创建 Chrome 配置文件,在其中关闭此选项并通过提供运行参数 (https://chromium.googlesource.com/chromium/src/+/HEAD/docs/user_data_dir.md) 来加载它:

    "chromeOptions": {
          "args":[
                  "--window-size=1200,1200",
                  "--headless",
                  "--user-data-dir=<YOURDIR>]
        }
    

    另一种解决方案,您可以检查无头的 UserAgent 字符串是否与普通浏览器不同,如果答案是肯定的,则使用 (Chrome 69 UA) 覆盖它:

        "chromeOptions": {
          "args":[
                  "--window-size=1200,1200",
                  "--headless",
                  "--user-agent="Mozilla/5.0 AppleWebKit (KHTML, like Gecko) Chrome/69.0 Safari"]
        }
    

    最后一个是通过提供参数来关闭安全策略:

    • --禁用网络安全
    • --allow-running-insecure-content

      "chromeOptions": {
        "args":[
                "--window-size=1200,1200",
                "--headless",
                "--disable-web-security",
                "--allow-running-insecure-content"]
      }
      

    您可以尝试其中一种可能的解决方案或将它们组合起来。

    【讨论】:

      猜你喜欢
      • 2020-03-07
      • 2017-05-03
      • 2020-08-02
      • 2018-11-29
      • 2018-05-05
      • 2019-01-15
      • 2021-10-19
      • 2023-02-01
      • 1970-01-01
      相关资源
      最近更新 更多