Selenium chromedriver that does not depend on current Chrome installation - selenium

Due to organization policy, the Chrome browser installation on my Windows Server machine is automatically updated. I have some processes that rely on python Selenium and chromedriver. Because of this, my process breaks whenever my org decides to push out an update.
Is it possible to have chromedriver depend on some binary other than Chrome browser that will not be managed by my organization so that this doesn't happen?

Few of the workarounds to resolve the issue:
We have kept the chrome exe file in an artifactory and we download and install that particular chrome version every time before our execution through automation (our requirement is like that).
As #Corey is suggesting you can webdrivermanager, PFB link for more details
https://github.com/bonigarcia/webdrivermanager
You can try Dockerized Selenium, there you'll have the control in the docker-compose.yml file.

Related

How to find the web browser version without setup() method using WebDriverManager

I am interested in getting the browser Version
I've two questions-
Question 1:- is there is a way to find out the browser version without setting up the browser?
or can we force stop the downloading of the Driver in the first place.
It is possible with the below code but the driver will be downloaded in this case.
WebDriverManager.chromedriver().setup(); //without doing this step
WebDriverManager.chromedriver().getDownloadedDriverVersion();
Question 2:-
Currently I am using wmic commands for browser detection which is used in WebDriverManager but it is failing on some systems.
what more alternatives ways are used in the WebDriverManager to fetch the browser version. I am curious to know about this as I've disabled wmic on my system still webDriverManager is working as usual(I guess with alternative methods within WebDriverManager).I am facing difficulties in understand the code. Please help me to understand the flow of the WebDriverManager like which methods/ways are used to detect the browser version and in what order.
Any help would be appreciated!
WebDriverManager
WebDriverManager is the open-source Java library that maintains the configuration management of the drivers required by Selenium WebDriver (e.g., chromedriver, geckodriver, msedgedriver, etc.) in a fully automated fashion.
Additionally, WebDriverManager provides other relevant features, such as the capability to discover browsers installed in the local system, building WebDriver objects (such as ChromeDriver, FirefoxDriver, EdgeDriver, etc.), and running browsers in Docker containers seamlessly.
The primary use of WebDriverManager is the automation of driver management (i.e., download, setup, and maintenance) of the drivers involved in your Test Automation Suite. Hence using WebDriverManager it's highly unlikely you can force stop the downloading of the Driver in the first place.
However, when you use a specific browser version for the first time in a while the matched driver version is downloaded and saved within the cache which is pretty much evident from the generated logs.
====== WebDriver manager ======
Current google-chrome version is 98.0.4758
Get LATEST chromedriver version for 98.0.4758 google-chrome
There is no [win32] chromedriver for browser in cache
Trying to download new driver from https://chromedriver.storage.googleapis.com/98.0.4758.102/chromedriver_win32.zip
Driver has been saved in cache [C:\Users\Sadanand.Kolhe\.wdm\drivers\chromedriver\win32\98.0.4758.102]
Moving forward, if the browser version and the matched driver version remains unchanged and at the same time the previous version of the downloaded version of the driver is available within the cache, the fresh downloading is avoided, which is evident from the logs generated from two back to back test execution.
====== WebDriver manager ======
Current google-chrome version is 98.0.4758
Get LATEST chromedriver version for 98.0.4758 google-chrome
Driver [C:\Users\Sadanand.Kolhe\.wdm\drivers\chromedriver\win32\98.0.4758.102\chromedriver.exe] found in cache
Regarding Q1, as of version 5, WebDriverManager allows detecting if a given browser is installed or not in the local system. To this aim, each manager provides the method getBrowserPath(). This method returns an Optional<Path>, which is empty if a given browser is not installed in the system or the browser path (within the optional object) when detected. See doc.
Regarding Q2, WebDriverManager uses internally a knowledge database called commands database. This database is a collection of shell commands used to discover the version of a given browser in the different operating systems (e.g., google-chrome --version for Chrome in Linux). This database contains WMIC commands for Windows but also queries to the registry. See doc again.

Why is chromedriver tied to chrome version?

I'm starting to use selenium and ChromeDriver in order to automate tasks in Chrome. I'm interested in scaling the task across multiple managed windows PC's.
I understand that updates of Chrome might break functionality in ChromeDriver. But I'm concerned it's the right tool because manually updating based on the chrome version results in a lot of maintenance as we'd have to manually place the executable on each system.
Is ChromeDriver really "whitelisting" with which chrome version it works? and why is that?
Browsers would have updates, which the driver also must have in order to invoke and interact with the browser, and hence your driver version must be in sync with the browser version. It is not just for Chrome, but for Firefox, and Edge also. One thing you can do is to use the ChromeDriverManager by installing the webdriver-manager library.
In Python, you do like this:
pip install webdriver-manager
In the py file, you can invoke the chromedriver:
from webdriver_manager import ChromeDriverManager
Then, when you initialize the driver, you can pass in the ChromeDriverManager:
driver = webdriver.Chrome(ChromeDriverManager().install())
With this, your driver and browser would be in sync. You need not worry about the incompatibility of driver-browser versions.
Please note: you would get a depcration warning with the above driver line of code, for which you need to include Service object; however, for now, it is a warning and not an error, so your code would not hamper the execution, but sooner or later, you must use Service object.
Here is a good article you can refer to Medium

Selenium performance with InternetExplorerDriver and IE11

I am facing a very slow response when running my scripts on IE11. Sometimes, I get FocusWindowsClosed, ElementIsNotClickable. I have changed the zoom settings for all zones, created feature BFCACHE for IE in feature control, added capabilities into my code but nothing works for me. If anyone has any idea why I am facing this issue. Do i need to downgrade window or IE versions? I have also downloaded the same version of selenium client server with same IEDriver which is (3.8.0).
To start with, Selenium v3.8.0 of 2017-11-30 is more then 2 years older. Even the error trace logs would be difficult to debug. So as per best practices you may like to:
First of all, the fact that ...64-bit IEDriverServer executable populate the input fields with the character sequence very slowly as compared to 32-bit IEDriverServer executable.... is a known issue.
You can find a detailed discussion in IEDriverServer sends text very slowly using Selenium to the search field
Ensure the Internet Explorer Protective mode setting are properly configured.
Ensure the Zoom level is properly configured.
Ensure ignoreProtectedModeSettings is properly confugured.
Ensure setting up selenium to work with internet explorer.
Ensure FEATURE_BFCACHE is properly confugured.
Upgrade Selenium to current levels Version 3.141.59.
Upgrade IEDriverServer to latest IEDriverServer v3.150.1 level.
Note: As per best practices as Selenium Client and InternetExplorerDriver are released in sync and you must try to use both the binaries from the same major release.
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
Execute your #Test.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
tl;dr
A couple of references:
Internet Explorer 11 getting stuck randomly while executing tests through IEDriverServer and Selenium
HTTP Status: '500' -> incorrect JSON status mapping for 'timeout' (408 expected) while clicking element with IEDriverServer Selenium and Java

Firefox spontaneous launch in Selenium

Environment:
selenium-server-standalone-3.8.1.jar
geckodriver-v0.24.0
firefox 60.6.1
Everything was set up 6 months ago and everything worked well, the tests passed through the Selenium and there were no problems.
Since 08/23/2019 problems began. Without any launches test inside the Selenium process, started to run spontaneously browsers (firefox) and did not turn off.
These processes overload the processor on the server, after which the server starts to brake and also the site that is on the server. These "browser launches" continue until Selenium is reloaded by open browsers after which our automatic tests are blocked and display an error: "unable to create new native thread".
As soon as one such browser spontaneously opens, the processor load becomes 100%.
These browser launches occur approximately 1 time in 4-5 minutes.
All tests are disabled, but Selenium lives its own life, and continues to launch the browsers.
Maybe someone faced a similar problem? Any ideas why this is happening and how to fix it?
The launch of selenium occurs on command:
su screener -c "/usr/bin/java -Dwebdriver.gecko.driver=/usr/local/bin/geckodriver -jar /usr/lib/selenium/selenium-server-standalone-3.8.1.jar -enablePassThrough false -port 4444 >/var/log/selenium/selenium_std.log 2>/var/log/selenium/selenium_error.log &"
Term yourself lucky to have sailed smoothly with geckodriver-v0.24.0 and selenium-server-standalone-3.8.1.jar till 08/23/2019.
As per the documentation:
To work with geckodriver-v0.24.0 you need:
Selenium Python client version greater then 3.14
Firefox client version minimum 57 (which seems to be okay)
You can find the detailed GeckoDriver, Selenium and Firefox Browser compatibility chart in the discussion Which Firefox browser versions supported for given Geckodriver version?
Additional considerations
As a part of the best practices:
Upgrade JDK to recent levels JDK 8u222.
Upgrade Selenium to current levels Version 3.141.59.
Upgrade GeckoDriver to GeckoDriver v0.24.0 level.
GeckoDriver is present in the desired location.
GeckoDriver is having executable permission for non-root users.
Upgrade Firefox version to Firefox v65.0.2 levels.
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
http://www.yourownlinux.com/2013/10/how-to-free-up-release-unused-cached-memory-in-linux.html) before and after the execution of your Test Suite.
If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your Test as a non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
You can find a detailed discussion in PhantomJS web driver stays in memory
If the stale WebDriver instances still persist you may require to forcefully remove them.
You can find a detailed discussion in Selenium : How to stop geckodriver process impacting PC memory, without calling driver.quit()?
Outro
Limit chrome headless CPU and memory usage

Jenkins with Xvfb and Selenium - Firefox started but nothing executed

I have a problem with Selenium under Jenkins 1.446 together with Xvfb: It looks like firefox is started correctly because I let my failing tests record screenshots. These screenshots all show the same failing page, which in my case is the starting page where the tests should begin. So I gues the selenium WebDriver commands do not arrive. What could be the reason? By the way, the tests are running perfectly on my local machine.
I'm using Firefox 9.0.1 with no specific test profile and no AddOns, Ubuntu 10.04, Senlenium 2.16.1
Log entry: com.thoughtworks.selenium.SeleniumException: Timed out waiting for action to finish
Thanks!
EDIT: Issue seems to be fixed by a system reboot ...
I experienced a very similar issue with FF9.0.1 and Selenium 2.16.1 running through JUnit launched by Maven SureFire plugin run by Jenkins on a WinXP node.
2.17.0 fixed the issue for me. Try updating to the latest Selenium.
Through RDP, I was able to watch the tests running. The tests appeared to be partially blocked by a prompt from Firefox asking about collecting anonymous usage statistics. Manually answering the prompt would allow the test to continue but because Selenium creates a new profile each time by default, the prompt would return on the next browser launch. Running the tests locally with a pre-configured FF profile allowed me to persist that the prompt had been answered. This isn't possible on my XP node because the tests are running as 'System'.
Selenium/WebDriver would normally take care of this for you by marking the prompt as already answered in a temporary FF profile configuration but a bug was causing the value to be set to the wrong value. You can inject a profile configuration to the Selenium FirefoxDriver driver to pragmatically configure stuff like this prompt but the bug appeared to prevent this as well. This has been resolved in Selenium 2.17.0 (http://selenium.googlecode.com/svn/trunk/java/CHANGELOG see 2.17.0 WebDriver bug fixes).