Nightwatch Chromedriver自签名SSL

时间:2018-11-28 18:26:30

标签: google-chrome nightwatch.js

我正在尝试使用 just chromedriver运行Nightwatch,并且可以使所有内容在没有 SSL的情况下正常运行。当我使用自签名证书加载我的应用程序(尽管它只是超时)时,我已经浏览了NightWatch和Chromedriver的无数文档,并且似乎无法正常工作。

  "desiredCapabilities": {
    "browserName": "chrome",
    "acceptSslCerts": true,
    "acceptInsecureCerts": true,
    "javascriptEnabled": true,
    "webStorageEnabled": true,
    "chromeOptions" : {
      "args": [
        "headless",
        "no-sandbox",
        "disable-gpu",
        "disable-web-security",
        "ignore-certificate-errors"
      ]
    }
  }

我的全局文件:

const chromedriver = require('./chromedriver.js');
module.exports = {
  before: (done) => {
    chromedriver.start()
    done()
  },
  after: (done) => {
    chromedriver.stop()
    done()
  }
}

和我的chromedriver文件:

const tcpPortUsed = require('tcp-port-used')

const getPortFromArgs = (args) => {
  const port = 9515
  if (!args) return port
  const portRegexp = /--port=(\d*)/
  const portArg = args.find((arg) => portRegexp.test(arg))
  return portArg ? parseInt(portRegexp.exec(portArg)[1]) : port
}

exports.start = (args, returnPromise) => {
  const cp = require('child_process').spawn('/usr/bin/chromedriver', args)
  cp.stdout.pipe(process.stdout)
  cp.stderr.pipe(process.stderr)
  exports.defaultInstance = cp
  if (!returnPromise) return cp
  const port = getPortFromArgs(args)
  const pollInterval = 100
  const timeout = 10000
  return tcpPortUsed.waitUntilUsed(port, pollInterval, timeout).then(() => cp)
}

exports.stop = () => {
  if (exports.defaultInstance != null) exports.defaultInstance.kill()
}

0 个答案:

没有答案