4

テストに nightwatch フレームワークを使用しています。このコマンドを使用して selenium-server をプロジェクト フォルダー「npm install --save-dev selenium-server」にインストールし、chromedriver を 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 個のテストを 1 つずつ実行すると、10 個の chromedriver が起動します。

ファイルを追加globals.jsしてパスを my に入れる場合nightwatch.json:

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

    chromedriver.start();

    done();
  },

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

    done();
  }
};  

それは別の chromedriver を開きます (つまり、1 つのテストに対して 2 つの chromedrivers を意味します) が、1 つの chromedriver は終了し、別の chromedriver はまだ終了していません。

1 つのテストのログは次のとおりです。

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 に答える