/usr/bin/google-chrome is no longer running - selenium

so I have this selenium and flask application that I deployed on digital ocean ubuntu VPS. when I run the application in development mode "main#ubutu$python3 pyfile.py" everything runs perfectly without throwing any error. But when I run the application on production mode, i.e when the app is deployed I get the following error.
The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed
I have the latest google-chrome and chromedriver.
main#ubuntu:~$ google-chrome --version
Google Chrome 102.0.5005.61
also in my code, I have included all the options that are required to run on a VPS without display.
option = Options()
service = Service("/home/path/to/chromedriver")
#option.binary_location = "/usr/bin/google-chrome-stable"
option.add_argument("--headless")
option.add_argument("--no-sandbox")
option.add_argument("--disable-extensions")
option.add_argument("--disable-setuid-sandbox")
option.add_argument("--remote-debugging-port=9222")
option.add_argument("--disable-gpu")
option.add_argument("--start-maximized")
option.add_argument("--disable-dev-shm-usage")
driver = webdriver.Chrome(service=service, options=option)
many people have experienced this problem but the option --no-sandbox and --headless seemed to have solved their problems. but even after that I still have the same issue.
google-chrome path /urs/bin/google-chrome.
any help will be appreciated thanks.

I was using digital ocean ubuntu VPS, so I followed their documentation on how to deploy flask applications on their servers. if at all you are following their documentation and you run into this. here is the solution.
thanks to #Lewis Morris
the problem was the path ENVIRONMENT_PATH that I used in the /etc/systemd/system/myapp.service, initially, it was
Environment="PATH=/home/main/searchapp/venv/bin
then I changed it to:
Environment="PATH=/home/main/searchapp/venv/bin:/usr/bin:/bin"
hope it helps someone in the future so they don't have to waste their time.

Related

user-data-dir not working anymore on selenium with chromedriver 90

user-data-dir not working anymore on selenium with chromedriver 90
already tried to reinstall chrome, redownload chromedriver and adding:
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
not working on win10 laptop and on win 8.1 laptop
I've not touched anything and yesterday was working. HELP ME PLEASE!
edit: when i try to run my pyhton script on windows 8.1 it says that chrome can't write or read in a directory (i'm italian, it's a translation) but when i run on win10 it says "Exception has occurred: WebDriverException
Message: unknown error: DevToolsActivePort file doesn't exist"
EDIT2: If you have one single script it works by adding chrome_options.add_argument("--remote-debugging-port=9292")
If you have to run more than one change --user-data-dir=profile to --user-data-dir=C:\Users\myuser\Desktop\profile
No promises that this will work for you, but my code did the same thing overnight and what fixed it was explicitly setting the remote debugging port:
options.add_argument("--remote-debugging-port=9292")
Seems to be either a Chrome 90 or Chromedriver issue/feature.

Openshift RHEL Containers - Problems running google-chrome

I am trying to run google chrome browser for headless testing in RHEL7 containers running in Openshift cluster. The idea is to use the browser for selenium automation.
The test runs perfectly in my local machine with Docker containers, I was able to get the screenshots - no issues. However, once I deploy them into OpenShift google chrome browser doesn't respond on time. Webdriver throws the below error.
> Webdriver error:
> {"message":"Unexpected data in simpleCallback.","data":"<html><body><h1>504 Gateway Time-out</h1>\nThe server didn't respond in time.\n</body></html>\n"}
Based on the message I failed to figure out the problem, I did run the google-chrome through CLI and below is what I get from within the container.
google-chrome-stable --no-sandbox --headless --disable-gpu
--window-size=1920,1080 --proxy-server=http://myproxy.net:9999 --screenshot="/tmp/sc1.png" http://www.mytestingsite.com
Fontconfig warning: "/etc/fonts/fonts.conf", line 86: unknown element "blank"
[1001/164944.431186:ERROR:gpu_process_transport_factory.cc(1007)] Lost UI shared context.
[1001/164944.450572:ERROR:zygote_host_impl_linux.cc(259)] Failed to adjust OOM score of renderer with pid 117: Permission denied (13)
Couple of things I suspect could be a problem, the permission denied error thrown by the non-privileged user or it is something else. I really need chrome to throw some verbose logging to figure this out. I tried enable '--enable-logging=v=1' doesn't help.
Could someone shed some light on how to debug this issue or any ideas what could cause such a thing in OpenShift platform?

Does Chromium headless work on Windows Server Core 2016?

Background
I am tasked with replacing our IE based printing logic with Chromium so that we can eventually support running our current server software on Windows Server Core or potentially other operating systems that support .Net Core. My current thought is to either use Chromium embedded framework or to make use of Puppeteer. I am leaning towards the later because I feel it would be easier to port between operating systems.
Issue
Originally it failed to start with an error about sandboxing so I added the no-sandbox flag. Now when I try to load Chromium it fails to start with the exception below stating that it cannot load chrome.dll
PS C:\Program Files (x86)\Google\Chrome\Application>> .\chrome --headless --enable-logging --disable-gpu --screenshot="C:\screen.png" "https://www.chromestatus.com/"
Which yields the following error in the debug.log file:
[0813/133208.016:ERROR:main_dll_loader_win.cc(134)] Failed to load Chrome DLL from c:\Program Files (x86)\Google\Chrome\Application\68.0.3440.106\chrome.dll: The specified module could not be found. (0x7E)
I have checked around the internet and found a few mentions of this error but the suggested fixes don't seem to fix the issue.
I was able to download Chromium 72.0.3592.0 via Chocolatey and the issue is resolved in that version. I tested using Server Core 2016 LTSB.
choco install chromium --pre -y
chrome --headless --disable-gpu --dump-dom --enable-logging https://www.chromestatus.com/ --no-first-run
Edit:
If you are attempting to run Selenium Tests using Docker windowsservercore and chromium: The command line tests of chromium chrome.exe appear to never work from the container command line.
However when you run dotnet test app.csproj or dotnet vstest app.dll inside the container the webdriver successfully starts and drives the browser
This has been reported to the Chromium team. It appears that Chromium 68+ might have issues with Windows Server 2016.
https://bugs.chromium.org/p/chromium/issues/detail?id=873097

Jenkins setup for running Selenium test on Ubuntu

I already tried a lot for Jenkins setup on Ubuntu for running selenium test cases. But each time i face problem Like Display error , chrome connection timeout. I tried all the solution on internet (debugging this from last one week). Someone please help in setting up by step by step process (including version compatibility).
Also, test-cases on Ubuntu Jenkins run only on display mode?

Setting up selenium, chromedriver, and wdio mixed with vagrant or docker

I started out trying to learn how to write automated tests for a small project but nothing was working right out of the box. After a couple hours of searching & experimenting I found the right configuration for my project & figured sharing it might help folks in the future.
Here's a small summary of the errors I encountered on this debugging journey:
Using Jasmine & WDIO, send_keys was crashing
It was a Firefox/geckodriver bug, or something like that
WDIO appeared to hang after switching from Firefox to Chrome
Chrome needed to be run in --no-sandbox mode, essentially
I figured my problem was probably stemming from having WDIO execute my tests on my local machine while Selenium was hammering on the browser in a Vagrant VM. So this will mainly be applicable for people using separate environments (vagrant->local, vagrant->vagrant, docker->local, etc) for WDIO & Selenium/Chromedriver. Here is a gist of the configuration file I ended up with.
I started with fanatique/vagrant-selenium-vm and modified it to use Chrome instead of Firefox because send_keys was broken with Firefox/geckodriver at the time of writing. After swapping out the packages, I'd start the tests with wdio but it would appear to hang. Turning on verbose logging showed it trying to start but failing with no explanation why.
[00:06:39] COMMAND POST "/wd/hub/session"
[00:06:39] DATA {"desiredCapabilities":{"javascriptEnabled":true,"locationContextEnabled":true,"handlesAlerts":true,"rotatable":true,"browserName":"chrome","loggingPrefs":{"browser":"ALL","driver":"ALL"},"requestOrigins":{"url":"http://webdriver.io","version":"4.6.2","name":"webdriverio"}}}
It took removing the & from the nohup java ... command in fanatique/vagrant-selenium-vm's setup.sh to see the logs from Selenium in real time, then I was able to see a "only local connections are allowed" message from chromedriver. That led me to a SO post that said to add --whitelisted-ips="" as an arg to chromedriver - but I was still getting the local connections error message. Chrome itself ended up needing a --no-sandbox flag - that allowed WDIO to connect to the chromedriver in Selenium and my tests ran from there.