I've selenium script which launches chrome browser, goes to a website and does basic checks.
When I tried running same script locally through jenkins I got error
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4),platform=Linux 4.13.0-17-generic x86_64)
This is resolved by Unknown error: Chrome failed to start: exited abnormally
I'm confused why Jenkins can't launch real chrome browser on Ubuntu ?
Because Jenkins server normally does not have a graphical subsystem installed in the operating system. When a real browser (or any app) tries to create a window that fails.
You will need to run your tests on Jenkins using a headless browser - one that does not need a graphical subsystem. Chrome-headless is currently the preferred option, replacing the now abandoned PhantomJS.
Related
I've tried to search, but haven't found a definitive answer. On Windows Server 2016 WITHOUT Chrome Browser actually installed. I downloaded the correct "chromedriver.exe" and placed it in "D:\Apps\chromedriver.exe". I have added to my environment PATH the full path as "D:\Apps\chromedriver.exe".
When I attempt to start my Windows Service that utilizes the latest Selenium, I get the following error:
Exception occurred: Failed initializing web driver: Message: unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.14393 x86_64)
Question: Do I have to actually install the full-blown browser in addition to the chromedriver, or is this simply just not finding the chromedriver.exe in my Python code (included below for full disclosure):
def __init__(self, username, password, environment='cert'):
self.username = username
self.password = password
self.environment = environment
# Instantiate a chrome options object so you can set the size and headless preference
self.chrome_options = Options()
# Toggle Headless or not
if HEADLESS_TOGGLE == 1:
self.chrome_options.add_argument("--headless")
self.chrome_options.add_argument("--disable-gpu") # Disables "Lost UI Shared Context GPU Error on Windows"
self.chrome_options.add_argument('--disable-extensions') # Disables Extensions
self.chrome_options.add_argument("--disable-software-rasterizer") # Disables "Lost UI Shared Context GPU Error on Windows"
self.chrome_options.add_argument("--window-size=1024x768")
self.chrome_options.add_argument("--log-level=3") # Errors Only
self.chrome_options.add_argument("--incognito") # Keeps history and logs clear
self.chrome_options.add_argument("--no-sandbox")
self.chrome_options.add_argument("--mute_audio") # No loud surprises!
self.chrome_options.add_argument("--no-gpu") # Disables gpu-based errors (headless)
self.driver = webdriver.Chrome(chrome_options=self.chrome_options)
This error message...
Exception occurred: Failed initializing web driver: Message: unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.14393 x86_64)
...implies that the ChromeDriver was unable to find the Chrome binary while trying to initiate a new new Browsing Context i.e. Chrome Browser session.
As per the documentation with in the wiki page of ChromeDriver:
ChromeDriver is a standalone server which earlier implemented the WebDriver's wire protocol but slowly and gradually shifting it's implementation as per WebDriver standard.
The ChromeDriver consists of three separate pieces.
There is the browser itself i.e. chrome
The language bindings provided by the Selenium project i.e. the driver
An executable downloaded from the Chromium project which acts as a bridge between chrome and the driver which is called chromedriver and we refer to it as the server.
In generic scenarios the server expects you to have Chrome installed in the default location for each system:
Linux: /usr/bin/google-chrome 1
Mac: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
Windows XP: %HOMEPATH%\Local Settings\Application Data\Google\Chrome\Application\chrome.exe
Windows Vista and newer: C:\Users\%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe
Note: 1: For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.
You can find a detailed discussion on overriding the default Chrome binary location in WebDriverException: unknown error: cannot find Chrome binary error with Selenium in Python for older versions of Google Chrome
Solution
So ideally to execute your tests using ChromeDriver / Chrome combo you need to:
Install the full-blown google-chrome browser.
Download the compatible version of chromedriver.exe
Quick installation of ChromeDriver:
Mac users with Homebrew: brew tap homebrew/cask && brew cask install chromedriver
Debian based Linux distros: sudo apt-get install chromium-chromedriver
Windows users with Chocolatey installed: choco install chromedriver
You can find a couple of relevant discussions in:
How to work with a specific version of ChromeDriver while Chrome Browser gets updated automatically through Python selenium
Selenium for ChromeDriver and Chrome Browser and the log message “Only local connections are allowed”
WebDriverException: Message: Service /usr/lib/chromium-browser/chromedriver unexpectedly exited on Raspberry-Pi with ChromeDriver and Selenium
Reference
You can find a detailed discussion in:
WebDriverException: unknown error: cannot find Chrome binary error with Selenium in Python for older versions of Google Chrome
Users provided relevant link to confirm that, "YES" a full Chrome installation is needed in addition to the actual chromedriver.
Link: https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver
In my case, I am using PowerShell. I figured out that you need to put the correct chromedriver.exe version, according to the installed Chrome browser, in the path under Selenium Module installation folder, and replace the existing file.
Check this answer for details:
I cannot start chrome instant using PowerShell and Selenium module
I do it with the same code. Also add no --no-sandbox.
But not working.
I get this one:
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(chrome not reachable)
(The process started from chrome location /usr/bin/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 5.4.0-1038-aws x86_64)
In general, when you are getting a crash starting Chrome on PythonAnywhere, it's because you have been leaving processes running by not properly closing the browser in your code. Search for "selenium" on the PythonAnywhere help pages for example code that properly closes Chrome and also shows parameters that you should use.
I want to launch Chrome as real browser, with Selenium.
I want to use Chrome extensions, so I want to launch a real browser instead of headless Chrome.
On Mac, this code will successfully launch the Chrome browser
# Selenium ruby
options = Selenium::WebDriver::Chrome::Options.new
::Selenium::WebDriver.for :chrome, options: options
However, when I run the same code on Ubuntu, I get an error.
# error
unknown error: Chrome failed to start: exited abnormally. (Selenium::WebDriver::Error::UnknownError)
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
When I tried to call the command directly to chrome, I got the following error.
$ google-chrome
No protocol specified
[16445:16445:0220/022600.429383:ERROR:browser_main_loop.cc(1438)] Unable to open X display.
Please Help me.
I get errors while running WCT in the Jenkins pipeline. I share that errors detail on the bottom. These errors may be related to Openshift. Maybe you can share your opinion.
Note: My tests are running at Openshift.
First case:
-> I running with a chrome configuration. In this case, I get the following error. This error message is clear. We must install chrome. But I don't know how to do it.
Error:
The following browsers were not found: chrome. (All installed browsers found: firefox)
Error image:
Second case:
-> Because of the above error I changed browser configuration to firefox. But I take a different error this time. This error is complicated for me. I need more detail about this error. According to my research, there may be many reasons for this. Maybe we should add/change some options on Openshift.
Note:
Picked up JAVA_TOOL_OPTIONS: -XX:+UnlockExperimentalVMOptions
-XX:+UseCGroupMemoryLimitForHeap -Dsun.zip.disableMemoryMapping=true 10:12:47.767 INFO [GridLauncherV3.parse] - Selenium server version:
3.141.59, revision: e82be7d358 10:12:47.857 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone
Selenium Server on port 33226 2019-11-12 10:12:47.903:INFO::main:
Logging initialized #385ms to org.seleniumhq.jetty9.util.log.StdErrLog
10:12:48.154 INFO [WebDriverServlet.] - Initialising
WebDriverServlet 10:12:48.252 INFO [SeleniumServer.boot] - Selenium
Server is up and running on port 33226
Waiting on this line too much. After that, I aborted the manual pipeline. Because the process does not continue.
Error:
Selenium exited before it could start
Error image:
This error message...
10:12:48.252 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 33226
Error: Selenium exited before it could start
...implies that the Selenium Server can't be started for some reasons (e.g. port 4444 is blocked).
As per the discussion Selenium exited before it could start this error can be observed when Selenium Server is started in another process before running npm/wdio and hence selenium standalone service will fail to start.
Solution
The simplest solution would be to check for a running selenium process or try killall selenium / java processes.
I have selenium 2.53.1.jar, platform-Windows, Java- 1.8, chrome = 52.0, chrome-driver.exe-2.23.
I am seeing the following message when trying to run Night watch test on Jenkins.
org.openqa.selenium.WebDriverException: unknown error: unable to
discover open pages (Driver info: chromedriver=2.23.409699
(49b0fa931cda1caad0ae15b7d1b68004acd05129),platform=Windows NT
6.3.9600 x86_64)
Please note that the test is running correctly from the command line- all paths given are same as in the Jenkins job.
I also tried a previous version 2.22 of Chrome driver. Still see the same error.
Test is running correctly on FF.
Even I'm getting the same error. Maybe you can try putting sand-box for chrome. Maybe that might help you out temporarily.