通过无头镀铬在jessie中运行守夜人

时间:2018-03-08 10:21:17

标签: selenium selenium-chromedriver nightwatch.js

我已经启动了一个jessie clean vps,然后我安装了node.js.之后我通过npm安装了守夜人和chromedriver。我制作了3个文件,它们是nightwatch.js,nightwatch.json和js样本测试。

这是我的nightwatch.json:

{
  "src_folders" : [""],
  "custom_commands_path" : "",
  "custom_assertions_path" : "",
  "page_objects_path" : "",
  "globals_path" : "",

  "selenium" : {
    "start_process" : true,
    "server_path" : "./selenium-server-standalone-3.0.1.jar",
    "log_path" : "",
    "host": "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : 
      "./node_modules/chromedriver/lib/chromedriver/chromedriver"
    }
  },

  "test_settings" : {
    "default" : {
      "launch_url" : "http://localhost",
      "selenium_port"  : 4444,
      "selenium_host"  : "localhost",
      "silent": true,
      "screenshots" : {
        "enabled" : false,
        "path" : ""
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "chromeOptions" : {
          "args" : ["headless", "--no-sandbox"]
        }
      }
    }
  }
}

对于样本测试,这只是一个简单的测试:

var chromedriver = require('chromedriver');
module.exports = {
  before : function(done) {
    chromedriver.start();
  },
  after : function(done) {
    chromedriver.stop();
  },
  'Trial' : function (browser) {
    browser
      .url('http://www.google.com')
      .waitForElementVisible('body', 1000)
      .setValue('input[type=text]', 'nightwatch')
      .waitForElementVisible('button[name=btnG]', 1000)
      .click('button[name=btnG]')
      .pause(1000)
      .assert.containsText('#main', 'Night Watch')
      .end();
  }
};

这是我得到的: enter image description here

每次我运行测试时,似乎无头浏览器都无法正常工作。 Nightwatch无法识别每个元素。当我执行.assert.title('Google')时,它会返回'Object not found'。我在Windows上测试过,它工作顺利。有什么我想念的吗?当我无头地运行时,是否有必要使用chrome二进制文件?

0 个答案:

没有答案