测试完成后,Chromedriver不会退出

时间:2018-04-13 16:38:32

标签: javascript selenium-chromedriver nightwatch.js selenium-server

我正在使用nightwatch框架进行测试。我通过这个命令将selenium-server安装到我的项目文件夹“npm install --save-dev selenium-server”中,并通过chromedriver via 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)

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

你可以告诉我如何退出吗?感谢。

1 个答案:

答案 0 :(得分:1)

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

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

开始实际的测试:`