简体   繁体   English

在Visual Studio中停止两者之间的调试时,Chromedriver.exe在任务管理器中保持打开状态

[英]Chromedriver.exe remains open in task manager when stopping the debugging in between in Visual Studio'

调试/运行测试按钮显示为禁用,我发现这是因为chromedriver.exe已打开,如何通过硒C#代码关闭chromedriver.exe?

Try the following: 请尝试以下操作:

Process[] chromeDriverProcesses = Process.GetProcessesByName("chromedriver");
foreach (var chromeDriverProcess in chromeDriverProcesses)
{
    chromeDriverProcess.Kill();
}

I always do quit, dispose and set to null to keep it from leaving processes open: 我总是退出,处理并设置为null,以防止进程保持打开状态:

                _driver.Quit();
                _driver.Dispose();
                _driver = null;

I recommend against using Kill like the other answer states because it will kill all the chrome processes - which can be adverse if you're running multiple tests in parallel or have other processes using chromedriver running on the same machine. 我建议不要像其他答案状态那样使用Kill,因为它会杀死所有chrome进程-如果并行运行多个测试,或者在同一台计算机上运行使用chromedriver的其他进程,这可能是不利的。

Do you call Driver.Quit() or Driver.Close() in your Cleanup? 您在清理中调用Driver.Quit()或Driver.Close()吗?

Close() will close the Window and Quit() will end the Process. Close()将关闭窗口,Quit()将结束进程。 I've seen a lot of tutorials using "Close", where in my opinion "Quit" would be the better choice. 我看过很多使用“ Close”的教程,我认为“ Quit”是更好的选择。

This will no help you if you are debugging and stop the debugger with code changes or the red square, but it will help if the test completes (either positive or negative) 如果您要调试,并通过代码更改或红色方块停止调试器,这将无济于事,但如果测试完成(肯定或否定),这将有所帮助

This method is my cleanup. 此方法是我的清理工作。

/// <summary>
/// Cleanup that stops the chrome browser
/// </summary>
[TestCleanup]
public void CloseBrowser()
{
    Driver.Quit();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM