4

我正在使用 nightwatch 框架进行测试。我已通过此命令将 selenium-server 安装到我的项目文件夹“npm install --save-dev selenium-server”中,并通过 npm install --save-dev chromedriver. 我用这个命令运行我的测试:./node_modules/.bin/nightwatch -e chrome --tag [test name]。我的 nightwatch.json 文件如下所示:

{
  "src_folders": [
    "tests"
  ],
  "output_folder": "reports/XMLReports",
  "custom_commands_path": [
    "commands",
    "node_modules/nightwatch-custom-commands-assertions/js/commands",
    "./node_modules/nightwatch-commands/commands"
  ],
  "custom_assertions_path": "node_modules/nightwatch-custom-commands-assertions/js/assertions",
  "page_objects_path": [
    "pages_lms",
    "pages_app"
  ],
  "globals_path": "./globalsModule.js",
  "selenium": {
    "start_process": true,
    "server_path": "./node_modules/selenium-server/lib/runner/selenium-server-standalone-3.11.0.jar",
    "log_path": "log/",
    "host": "127.0.0.1",
    "end_session_on_fail" : true,
    "port": 4444,
    "cli_args": {
      "webdriver.chrome.driver": "./node_modules/chromedriver/lib/chromedriver/chromedriver",
      "webdriver.ie.driver": "",
      "webdriver.firefox.profile": ""
    }
  },
  "test_settings": {
    "chrome": {
      "selenium_port": 4444,
      "selenium_host": "localhost",
      "silent": true,
      "screenshots": {
        "enabled": true,
        "path": "screenshots/"
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "args": [
          "disable-web-security",
          "ignore-certificate-errors",
          "--test-type "
        ]
      }
    }
  }
}

问题是每次测试后chromedriver都不会退出,如果我一个接一个地运行10个测试,我会得到10个chromedriver。

如果我要添加globals.js文件并将路径放入我的nightwatch.json

   var chromedriver = require('chromedriver');
module.exports = {
  before : function(done) {

    chromedriver.start();

    done();
  },

  after : function(done) {
    chromedriver.stop();

    done();
  }
};  

这将打开另一个 chromedriver (这意味着一个测试有两个 chromedrivers ),但一个 chromedriver 将完成,另一个仍然没有。

以下是一项测试的日志:

2:26:09.135 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.11.0', revision: 'e59cfb3'
12:26:09.137 INFO [GridLauncherV3$1.launch] - Launching a standalone Selenium Server on port 4444
2018-04-13 12:26:09.292:INFO::main: Logging initialized @614ms to org.seleniumhq.jetty9.util.log.StdErrLog
12:26:09.629 INFO [SeleniumServer.boot] - Welcome to Selenium for Workgroups....
12:26:09.630 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
12:26:10.353 INFO [ActiveSessionFactory.apply] - Capabilities are: Capabilities {acceptSslCerts: true, args: [disable-web-security, ignore-certificate-errors, --test-type ], browserName: chrome, javascriptEnabled: true, name: Admin Login Test}
12:26:10.355 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
Starting ChromeDriver 2.37.544337 (8c0344a12e552148c185f7d5117db1f28d6c9e85) on port 12055
Only local connections are allowed.
12:26:11.893 INFO [ProtocolHandshake.createSession] - Detected dialect: OSS
12:26:12.491 INFO [RemoteSession$Factory.lambda$performHandshake$0] - Started new session 2325dacb5a5397552de3b69a52656fed (org.openqa.selenium.chrome.ChromeDriverService)
12:26:23.697 INFO [ActiveSessions$1.onStop] - Removing session 2325dacb5a5397552de3b69a52656fed (org.openqa.selenium.chrome.ChromeDriverService)

“nightwatch”:“^0.9.20”,“chromedriver”:“^2.37.0”,“selenium-server”:“^3.11.0”“Chrome”:65.0 Mac OS Sierra 10.13.4

你能告诉我怎么戒掉吗?谢谢。

4

1 回答 1

1

您可以像这样在每个测试中调用 after 方法:

`'after' : function(browser, done) {
        browser.end(function(){
            done();
        });
    },

实际测试的开始:`

于 2018-04-24T13:49:17.977 回答