简体   繁体   English

在带有IE11的C#上使用IEDriverServer和Selenium时,内存泄漏

[英]Memory leaks when working with IEDriverServer and Selenium on C# with IE11

I am running C#-Selenium on IE11 on Windows 7/10. 我在Windows 7/10的IE11上运行C#-Selenium。 All the while when running the Script, the IE11 Memory keeps increasing until it reaches 1.5GB of Memory. 在运行脚本时,IE11内存一直保持增加,直到达到1.5GB内存为止。 Note I can't close or quit anything since I need my test to keep running. 注意由于我需要测试才能继续运行,因此我无法关闭或退出任何操作。 The Problem is IE11 keep getting bigger as the test progresses 问题是随着测试的进行,IE11越来越大

In comparison, When running the same script with QTP, none of it happens. 相比之下,当使用QTP运行相同的脚本时,没有任何反应。 32 bit WebDriver Version: 3.8 & 3.141 32位WebDriver版本:3.8和3.141

The Web Application itself is a propriety one Do you have any idea Where do I start looking to resolve the Issue? Web应用程序本身就是一个适当的应用程序。您有任何想法要从哪里着手解决该问题?

Thanks 谢谢

Tried reducing my code, sniffing for memory leaks 试图减少我的代码,嗅探内存泄漏

The issue might be that your test scripts actually don't close the browser(s). 问题可能是您的测试脚本实际上没有关闭浏览器。

I've experienced a bug in selenium IE that it doesn't close the browser with the .close, or .quite commants. 我遇到了selenium IE中的一个错误,即它无法使用.close或.quite commant关闭浏览器。 That means it will open a lot of windows and that could cause the memory leaks.. 这意味着它将打开很多窗口,并可能导致内存泄漏。

Some sample code snippet of WebDriver and Web Browser initialization/closure process would have given us some hint why using IEDriverServer and IE11 memory keeps increasing until it reaches 1.5GB . WebDriverWeb Browser初始化/关闭过程的一些示例代码片段将为我们提供一些提示,说明为什么使用IEDriverServerIE11 内存会一直增加,直到达到1.5GB为止

Perhaps as per best practices always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully as follows: 也许按照最佳实践,总是在tearDown(){}方法内调用driver.quit()来优雅地关闭和销毁WebDriverWeb Client实例,如下所示:

driver.quit() // Python
// or
driver.quit(); // Java
// or
driver.Quit(); // DotNet

You can find a detailed discussion in PhantomJS web driver stays in memory 您可以在PhantomJS Web驱动程序保留在内存中找到详细的讨论

Incase the IEDriverServer processes are still not destroyed and removed you may require to kill the processes from tasklist. 如果IEDriverServer进程仍然没有被销毁或删除,则可能需要从任务列表中杀死这些进程。

  • Python Solution( Cross Platform ): Python解决方案( 跨平台 ):

     import os import psutil PROCNAME = "IEDriverServer" # or chromedriver or geckodriver for proc in psutil.process_iter(): # check whether the process name matches if proc.name() == PROCNAME: proc.kill() 

You can find a detailed discussion in Selenium : How to stop geckodriver process impacting PC memory, without calling driver.quit()? 您可以在Selenium中找到详细的讨论:如何在不调用driver.quit()的情况下停止影响PC内存的geckodriver进程?

Additionally, 另外,

After a lot of searching I somewhat solve the issue by disabling the "Script Debugging (Internet Explorer)" in IE11 under Tools --> Options --> Advanced. 经过大量搜索之后,我通过在IE11中的“工具->选项->高级”下禁用“脚本调试(Internet Explorer)”来解决此问题。

on my Selenium Code there's a listening to this ScriptExecuted events (which is a must in my code): 在我的Selenium代码上,正在侦听此ScriptExecuted事件(在我的代码中这是必须的):

    firingDriver.ScriptExecuted += firingDriver_ScriptExecuted;

Can it be related? 可以关联吗?

So for now, I have no Idea why Disabling script debugging dramatically reduced the Memory Leaks. 因此,到目前为止,我不知道为什么禁用脚本调试会大大减少内存泄漏。 When running the same QTP scenario there is no Memory Leak. 当运行相同的QTP方案时,没有内存泄漏。

and If anyone has an Idea, I would love to hear it 如果有人有想法,我很想听听

Thanks! 谢谢!

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

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