在无头浏览器中运行polymer-3.x测试

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在无头浏览器中运行polymer-3.x测试相关的知识,希望对你有一定的参考价值。

我想在没有浏览器弹出的情况下运行测试。安装了wct-headless并配置了wct.config.json,如图所示

{
  "plugins": {
    "local": {
      "disabled": true
    },
    "headless": {
      "browsers": [
        "chrome",
        "firefox"
      ],
      "browsersOptions": {
        "chrome": [
          "headless",
          "disable-gpu",
          "no-sandbox"
        ],
        "firefox": [
          "--headless"
        ]
      }
    },
    "sauce": false,
    "xunit-reporter": {
      "output": "testfile.xml"
    }
  }
}

执行polymer test时,会出现以下错误

找不到名为“无头”的WCT插件

的package.json

"dependencies": {
  "@polymer/polymer": "^3.0.0"
},
"devDependencies": {
  "@polymer/iron-demo-helpers": "^3.0.0-pre.19",
  "@webcomponents/webcomponentsjs": "^2.0.0",
  "wct-browser-legacy": "^1.0.0",
  "wct-headless": "^2.2.2",
  "web-component-tester": "^6.8.0",
  "wct-xunit-reporter": "1.0.2"
}

我该如何配置wct.conf.json?

答案

无需安装wct-headless。只需使用以下内容创建文件wct.conf.json

{
 "plugins": {
   "local": {
     "browsers": [
       "chrome",
       "canary",
       "firefox"
     ],
     "browserOptions": {
       "chrome": [
         "headless",
         "disable-gpu",
         "start-maximized",
         "user-agent='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/68.0.3239.108 Safari/537.36'"
       ],
       "canary": [
         "headless",
         "disable-gpu",
         "start-maximized",
         "user-agent='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3239.108 Safari/537.36'"
       ],
       "firefox": [
         "-headless"
       ]
     } // browserOptions
   } // local
 } // plugins
}

以上是关于在无头浏览器中运行polymer-3.x测试的主要内容,如果未能解决你的问题,请参考以下文章

在 TFS 2017 中运行非无头自动化测试

真正的无头浏览器

如何在 Robot Framework 中运行无头测试

Jasmine 无头 webkit 中更好的故障报告

教你怎么用JavaScript检测当前浏览器是无头浏览器

无头浏览器是啥?它有啥用?