chromedriver.exe runs ~8 chrome.exe instances - selenium

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.
Task Manager screenshot when running 1 test:
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.
Does it work by design? Why so much chrome.exe instances are needed for one chromedriver.exe? Is this configurable?
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();
}
/////////////////////////////////////////////
}

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.
Snapshot:
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.
However, from 2018 onwards Google Chrome was actually redesigned to create a new process for each of the following entities:
Tab
HTML/ASP text on the page
Plugin those are loaded
App those are loaded
Frames within the page
Further, in a Chromium Blog it is mentioned:
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.
As a conclusion, the many processes you are seeing is as designed and in-line with the current implementation of Google Chrome.

Related

I want to use multiple browsers using firefox on selenium but my speed is slowing down

I have a project that I've been working on for a few days. I want to open multi browser using proxy. When I use Chromedriver it starts to close itself after 10 tabs. I don't experience shutdown in Firefox, but it loads very slowly even though my proxy speed is high. It says no internet most of the time.
Firefox Example :
from seleniumwire import webdriver
options = {
'proxy': {
'http': 'http://username:password#host:port',
'https': 'https://username:password#host:port',
'no_proxy': 'localhost,127.0.0.1,dev_server:8080'
}
}
driver = webdriver.Firefox(seleniumwire_options=options)
driver.get("https://www.google.com")
If your computer or internet cant handle it maybe be try outsourcing it to a platform like AWS EC2. This will run your script off of computers in the cloud so you don't have to worry about computing power or internet speed. There is a free tier that you can create multiple instances of if needed.
EC2 link: https://aws.amazon.com/ec2/?ec2-whats-new.sort-by=item.additionalFields.postDateTime&ec2-whats-new.sort-order=desc

Many process of Google Chrome (32 bit)

When 2 tests are running in Chrome, i have observed that too many Google Chrome(32 Bit) processes are running in Task manager, Is this a correct behavior of Chome Driver
When multiple automated tests are getting executed through 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.
Snapshot:
As per the article SOLVED: Why Google Chrome Has So Many Processes for a better user experience Google Chrome initiates a lot of windows background processes for each tab that have been opened by your Automated Tests. Google tries to keep the 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.
However, from 2018 onwards Google Chrome was actually redesigned to create a new process for each of the following entities:
Tab
HTML/ASP text on the page
Plugin those are loaded
App those are loaded
Frames within the page
In a Chromium Blog Multi-process Architecture it is mentioned:
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.
As a conclusion, the many processes you are seeing is pretty much in line with the current implementation of google-chrome
Outro
You can find a relevant discussion in How to quit all the Firefox processes which gets initiated through GeckoDriver and Selenium using Python

Tests timeouts (Selenium+Jenkins+Grid)

We've started getting random timeouts, but can not get reasons of that. The tests run on remote machines on amazon using selenium grid. Here is how it is going on:
browser is opened,
then a page is loading, but can not load fully within 120 seconds,
then timeout exeption is thrown.
If I run the same tests localy then everything is ok.
The Error is ordinary timeout exception that is thrown if a page is not loaded completely during the period of time that is set in driver.manage().timeouts().pageLoadTimeout(). The problem is that a page of the site can not be loaded completely within that time. But, When period of time that is set in driver.manage().timeouts().pageLoadTimeout() is finished and, consequently, Selenium possession of a browser is finished, the page is loaded at once. The issue can not be reproduced manually on the same remote machines. We've tried different versions of Selenium standalone, Chromedriver, Selenium driver. Browser is Google Chrome 63. Would be happy to hear any suggestions about reasons.
When Selenium loads a webpage/url by default it follows a default configuration of pageLoadStrategy set to normal. To make Selenium not to wait for full page load we can configure the pageLoadStrategy. pageLoadStrategy supports 3 different values as follows:
normal (full page load)
eager (interactive)
none
Code Sample :
Java
capabilities.setCapability("pageLoadStrategy", "none");
Python
caps["pageLoadStrategy"] = "none"
Here you can find the detailed discussions through Java and Python clients.

Slow/incomplete page load in the browser launched by selenium webdriver

I am using selenium WebDriver using RobotFramework. The major problem we are facing is, my tests are timing out even after setting timeout as high as 10 minutes. It happen with any browser I use. These thing works much faster If I run test manually (with all browser cache/data/cookie cleared). These are the other things I have observing for few months.
Some component are never loaded (I check the call trace using BrowserMob Proxy and we found nothing unusual)
"Click Element" does not work in many cases. Clicking on element triggers some action but that action is not always trigerred in automation. Manually it works all the time.
Notes:
This is happening on FF and Chrome. (IE is not working for me at all)
App server and automation suite is in LAN so latency is not an issue
No other heavy process is running at this time
Issue persist even if with firefox default profile
I tried it with different selenium versions. (2.45 - 2.52)
I took latest driver for chrome. Broweser: FF 40+ and GC 48
This does not look application issue as we spent 2 month confirming that. Let me know if you need any other detail.

Run Selenium tests in one browser while using a second browser window

I am running Selenium automation test in one browser, but at the same time, I want to open the browser in another window and do something like checking mail, googling email then active mode or focus is coming to the current working window, not the automation test run browser.
Is it possible to work on the browser while automation test is run?
In general, when doing UI automation, you cannot use the test machine to do any other tasks that involve using the keyboard or mouse.
Since WebDriver automation performs keyboard and mouse input, such as typing text and clicking items, you will be constantly interfering by taking focus away from the WebDriver instance of the browser and doing your own mouse and keyboard interaction in other applications.
This will adversely affect both you and the automation, with neither being able to do what they want to do!
You should either use a separate test machine, or setup a virtual machine using software such as VirtualBox (free).
Did you try doing that?
Selenium uses WebDriver to communicate with a specific instance of a browser, not the currently focused window. So you should be able do continue to use other instances of browser windows. The best thing to do would be try.
If it isn't working, I would recommend getting a VM up and running and using that as your test environment. Generally that is the way I work to keep everything separate.
I ran my tests on Firefox and then used chrome on the side. Otherwise, run your tests on a remote machine.
You can do 2 things
1. Use a third tool to run test cases like Jenkins. so that test will run in memory.
2. If you are using firefox you can create a seperate firefox profile so that if you use firefox at the same time there should be any issue.
To Create new FF profile use below code:
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(false);
profile.setAssumeUntrustedCertificateIssuer(true);
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(FirefoxDriver.PROFILE, profile);
WebDriver driver = new FirefoxDriver(dc);