gpt4 book ai didi

javascript - 测试完成后 Chromedriver 不会退出

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:24:40 25 4
gpt4 key购买 nike

我正在使用 nightwatch 框架进行测试。我已通过此命令将 selenium-server 安装到我的项目文件夹“npm install --save-dev selenium-server”中,并通过 chromedrivernpm 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(这意味着两个 chromedriver 用于一次测试),但是一个 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 服务器”:“^3.11.0”“ Chrome ”:65.0Mac OS Sierra 10.13.4

你能告诉我如何退出吗?谢谢。

最佳答案

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

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

实际测试的开始:`

关于javascript - 测试完成后 Chromedriver 不会退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49821620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com