chromedriver.exe 运行约 8 个 chrome.exe 实例 [英] chromedriver.exe runs ~8 chrome.exe instances

查看:73
本文介绍了chromedriver.exe 运行约 8 个 chrome.exe 实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Selenium 编写 UI 自动化测试.我注意到当我创建一个 chromedriver.exe 实例时 -> ~8 chrome.exe 进程出现在任务管理器中.

I write UI automation tests using Selenium. And I noticed that when I create an instance of chromedriver.exe -> ~8 chrome.exe processes appear in the Task Manager.

运行 1 次测试时的任务管理器截图:

Task Manager screenshot when running 1 test:

所以,当我并行运行时,比如说 8 个测试,任务管理器中有很多 chrome.exe 实例,它们使用一些端口并加载 CPU 和内存.

So, when I run in parallel, let's say, 8 tests there are a lot of chrome.exe instances in the Task Manager that use some ports and load a CPU and a memory.

它是按设计工作的吗?为什么一个 chromedriver.exe 需要这么多 chrome.exe 实例?这是可配置的吗?

Does it work by design? Why so much chrome.exe instances are needed for one chromedriver.exe? Is this configurable?

在我的代码中,我只有一个Chrome"类.它的构造函数创建了一个新的 chromedriver.exe 实例:

In my code, I just have a "Chrome" class. Its constructor creates a new chromedriver.exe instance:

Chrome chrome = new Chrome();

public class Chrome
{
    public OpenQA.Selenium.Chrome.ChromeDriver Driver;

    public Chrome(bool incognitoMode = false, bool maximizeWindow = true)
    {
        ChromeOptions options = new ChromeOptions();
        if (incognitoMode)
        {
            options.AddArguments("--incognito");
        }

        Driver = new ChromeDriver(options);
        Driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(360);
        if (maximizeWindow)
            Driver.Manage().Window.Maximize();
    }
  /////////////////////////////////////////////
}

推荐答案

当使用 Google Chrome 执行 自动化测试 时,您一定已经观察到可能有几十个 Google Chrome 进程正在运行,可以通过 Windows 任务管理器的 Processes 选项卡观察.

When automated tests are executed using Google Chrome you must have observed that there are potentially dozens of Google Chrome processes running which can be observed through Windows Task Manager's Processes tab.

快照:

根据这篇文章 为获得更好的用户体验 Google Chrome 为您打开的每个 TABS 启动大量后台进程@Tests.Google 试图通过将每个网页分成它认为合适的多个进程来保持 chrome 浏览器的稳定性,以确保如果一个进程在页面上失败,则可以终止或刷新该特定进程,而无需终止或刷新整个页面.

As per this article for a better user experience Google Chrome initiates a lot of background processes for each of the TABS that have been opened by your @Tests. Google tries to keep the chrome browser stable by separating each web page into as many processes as it deems fit to ensure that if one process fails on a page, that particular process(es) can be terminated or refreshed without needing to kill or refresh the entire page.

但是,从 2018 年起,Google Chrome 实际上已经重新设计,为以下每个实体创建了一个新流程:

However, from 2018 onwards Google Chrome was actually redesigned to create a new process for each of the following entities:

  1. 标签
  2. 页面上的 HTML/ASP 文本
  3. 加载那些插件
  4. 已加载的应用
  5. 页面内的框架

此外,在 Chromium 博客 中提到:

谷歌浏览器利用这些属性,将网络应用程序和插件置于与浏览器本身不同的进程中.这意味着一个 Web 应用程序中的渲染引擎崩溃不会影响浏览器或其他 Web 应用程序.这意味着操作系统可以并行运行 Web 应用程序以提高其响应能力,这意味着如果特定的 Web 应用程序或插件停止响应,浏览器本身不会锁定.这也意味着我们可以在限制性沙箱中运行渲染引擎进程,这有助于在漏洞发生时限制损害.

Google Chrome takes advantage of these properties and puts web apps and plug-ins in separate processes from the browser itself. This means that a rendering engine crash in one web app won't affect the browser or other web apps. It means the OS can run web apps in parallel to increase their responsiveness, and it means the browser itself won't lock up if a particular web app or plug-in stops responding. It also means we can run the rendering engine processes in a restrictive sandbox that helps limit the damage if an exploit does occur.

作为结论,您看到的许多流程都是按照设计并与 Google Chrome 的当前实施一致.

As a conclusion, the many processes you are seeing is as designed and in-line with the current implementation of Google Chrome.

这篇关于chromedriver.exe 运行约 8 个 chrome.exe 实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆