Openshift RHEL Containers - Problems running google-chrome - selenium

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?

Related

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

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.

Failed to open connection to "session" message bus: /usr/bin/dbus-launch terminated abnormally without any error message [duplicate]

I am using a very complex setup to test various non-public webpages. I use jenkins to run the python-selenium tests within a dockerimage. That way, I am completely independent of the jenkins environment and can create my own environment. In this environment I have the following software installed:
Ubuntu 16.04.3
Firefox: Mozilla Firefox 57.0.1
geckodriver: 0.18.0
nosetests: 1.3.7
selenium: 3.8.0
When running the tests, which mostly succeed, I see in the geckodriver.log output messages like
(firefox:55): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
/usr/bin/dbus-launch terminated abnormally without any error message
My questions:
What does this message mean?
Could that be an indication of the reason why sometimes the tests are failing?
If so, how to fix it?
The error you are seeing is :
(firefox:55): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
/usr/bin/dbus-launch terminated abnormally without any error message
So it is clear Firefox attempts to connect to D-BUS daemon and fails as dbus-launch gets terminated abnormally.
dbus-launch
dbus-launch is basically the utility to start a message bus by firefox through a shell script. It would normally be called from a user's login scripts. dbus-launch launches a session bus instance and print the address and pid of that instance to standard output.
You can read more about dbus-launch from the Linux man page
Root Cause
This error can arise if you use su (root), sudo, suedit, gksu. The main reason is DBUS_SESSION_BUS_ADDRESS retains its value when you su instead of picking up the value in /root/.dbus/session-bus.
Here you will find a detailed discussion on GConf Error: No D-BUS daemon running?! How to reinstall or fix?.
Another possible reason may be the base Firefox Browser version may be an older version on which updates were taken to reach the current version.
Solution :
There are a couple of solutions available to address this ubuntu related issue as follows :
Before you start Firefox you have to type export $(dbus-launch)
However this may result into another error with NSS_USE_SHARED_DB. So you have to use export NSS_USE_SHARED_DB=ENABLED as well.
The most convenient way would be to put all the configuration with in .bashrc file :
export $(dbus-launch)
export NSS_USE_SHARED_DB=ENABLED
firefox &
This discussion speaks about the solution in details.
If dbus-launch is not installed on your system you have to install dbus-x11 package which contains the dbus-launch program.
An effective solution would be to uninstall the older base version of Firefox Browser and install a recent released GA version of Firefox Browser.
Best Approach
The issue with dbus-launch was addressed properly by both Ubuntu and Mozila. To overcome this error you need to follow the below mentioned steps :
Keep your Ubuntu os updated with the Latest Patch Releases and updates.
Always use the latest released version of Selenium-Python client, WebDriver variant e.g. GeckoDriver and Web Browser, e.g. Firefox Browser.
Clean and Build the Project Workspace afresh through your IDE before and after executing your Test Suite.
Clear the Browser Cache before and after the execution of your Tests.
If you have to uninstall any of the Web Client variants (e.g. Mozilla Firefox) you can use Revo Uninstallar with Moderate Memory Scan so that the stale registry settings are discarded.
Use CCleaner tool regularly to wipe away the OS chores including the stale rust_mozprofile directories.
What does this message mean?
DBus is a message bus system for interprocess commutation. There is an open geckodriver issue on a similar if not the same subject:
request to geckodriver fails with no meaningful log entry when there is no access to $HOME/.mozilla or $HOME/.cache
Could that be an indication of the reason why sometimes the tests are failing?
The warning should not really affect the tests but it's difficult to speculate about your intermittent test failures without seeing what is actually happening in your tests.
If so, how to fix it?
Here are some things to try:
upgrade geckodriver to the latest stable version (currently 0.19.1)
update Firefox to the latest nightly version (currently 58)
try this answer
try this answer
For me the solution was to install dbus-x11
apt install dbus-x11

Selenium works when started locally, but not remotely

I'm hoping this is a simple issue to solve:
I have a dedicated machine that runs selenium with chromedriver. I can physically walk to the machine and type the following in a local terminal:
java -Dwebdriver.chrome.driver=chromedriver238 -jar selenium-server-3.11.jar
I can then go to any other machine on the network and kick off testing (in my case, codeception on jenkins) and it will sucessfully run my tests in chrome without a hitch.
However, if I try to run the above command without physically being at the selenium machine (ex, trying to ssh into the machine to run the command or making this command run as part of a supervisor process) then selenium has trouble starting the instance of chrome.
Has anyone run into this scenario before? Is there a way I can give 'interactive' access to the background script to allow it to open stuff on my screen?
Because when you physically walk to the machine and run the command. the selenium can get the desktop/window interface.
When use SSH, selenium lost the desktop/window interface, selenium have to start chrome under headless model, but your code not config to run as headless model. So the conflict come out.
you need to config your code to run with headless model.
I'm to getting the same scenario, when i try to start the selenium code on the machine A it works yet when i try to start selenium and run the scripts from machine B
(remotely connecting to machine A using ssh [ssh test#machine-a]) chrome instance doesn't start/launch and driver is getting null.
logs :
2020-02-27 12:04:27,319 INFO [LogWritter] Exception in beforeclass chrome driver instantiation , driver is null
2020-02-27 12:04:27,493 INFO [LogWritter] Exception in getting screenshot---java.awt.AWTException: headless environment
Any help/suggestion would be great !

chromedrive.exe has stopped working

Am running the automation suite on the below configuration
Selenium: 3.11.0
Chrome: 65.0.3325.181
Chromedriver: 2.37
JDK: 1.8
OS: Windows 7 Enterprise(64 -bit)
On mid of the execution am getting an error as Chromedriver.exe has stopped working and the execution got stopped.
To resolve this, have tried with different version of selenium and chromedriver. Couldn't able to resolve the issue.
Issue Image
ChromeDriver Log: Log
Update:
Am getting this error whenever my code triggers the driver.get(URL) or driver.navigate().to(URL) command. FYI, am not sure this gonna help or not. Just to give more insight, my code will access two sites, in that one is https and another one is http. Am getting the exception whenever it access the http site.

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.