I am trying to use chrome standalone driver on Travis CI server. I am getting this error:
selenium.common.exceptions.WebDriverException: Message: u'chrome not reachable\
The script runs fine locally.
in .travis.yml I have
before_script:
# google chrome standalone driver
- wget http://chromedriver.storage.googleapis.com/2.10/chromedriver_linux64.zip
- unzip chromedriver_linux64.zip
- sudo mv chromedriver /usr/local/bin
- sudo chmod a+x /usr/local/bin/chromedriver
and in my tests I have
from selenium.webdriver import Chrome
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
Chrome()
and after a delay I get the error message stated above.
I have tried changing the location of the chrome driver, and explicitly pass the executable_path to Chrome, but no joy.
I've successfully run tests in Travis using headless Chrome.
I've used the following arguments to start chrome:
no-sandbox
no-default-browser-check
no-first-run
disable-default-apps
The no-sandbox argument was the one that bypassed the 'chrome not reachable' error.
Related
I have a Selenium automation that I wrote in python to test the workflow of my website.
In my script I set a PATH and a webdriver as follow:
PATH = "<path-to->/ChromeWebDriver/chromedriver"
driver = webdriver.Chrome(PATH)
Goes without saying that this works just fine and without any issue. and I am able to run my script.
Now I wanted to try to integrate this script in a azure DevOps pipeline to automate this script every tot hours.
but I am getting and error (reasonable error) during the pipeline trigger.
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH
I understand that the PATH I have declared in my code, it won't work as not different, but how can I configure my pipeline to add the chrome driver to a windows vm during the process?
because I have a yaml file that is configured as follow
trigger:
- master
variables:
vmImageName: 'ubuntu-latest'
steps:
- task: UsePythonVersion#0
inputs:
versionSpec: '3.x'
addToPath: true
- script: |
python -m pip install --upgrade pip
pip install selenium
- task: Pythonscript#0
inputs:
scriptSource: 'filePath'
scriptPath: './test.py'
Is there a way how I can set the path? thank you so so much in advance
EDIT:
I did something different. In my repo I added ubuntu chrome driver and pointed my PATH to that folder. When I run the pipeline in azure, I get this error.
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(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.)
Problem solved, I have to download chrome driver for ubuntu, change my configuration pipeline to run on a ubuntu vm, and create a folder with the chromedriver where my pipeline was. and deploy everything.
So far I have written the code in Google Colab like this but It just doesn't load the chrome web driver and open a chrome browser.
!apt-get update
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
!pip install selenium
from selenium import webdriver
driver = webdriver.Chrome('chromedriver')
But it throws an exception stating
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
"If I set the options to --headless it works fine, But I need to load a chrome browser to observe the automation flow."
I am trying to use selenium chrome driver with docker. Unfortunately I can't get it working. When I do docker-compose up to launch the container it crashes with a
"container_name exited with code 1" error.
Using docker logs -t -f I was able to get the below error.
selenium.common.exceptions.WebDriverException:
Message: unknown error: Chrome failed to start: exited abnormally
I know that there have been other stack overflow posts about this issue, but all the solutions involve adding chrome options. I have already tried adding various chrome driver options without any luck. See code below.
options = webdriver.ChromeOptions()
options.add_argument('--proxy-server=socks5://localhost:9050')
options.add_argument('disable-infobars')
options.add_argument('--disable-extensions')
options.add_argument('--no-sandbox')
options.add_argument('--disable-setuid-sandbox')
options.add_argument('--headless')
options.add_argument('--start-maximized')
options.add_argument('window-size=1200x800')
options.add_argument('--disable-gpu')
driver = webdriver.Chrome(options=options, desired_capabilities=caps)
I have tried various combinations of the above code with no luck. I also tried commenting out the 'proxy=server' option and running the container, but I get the same error. When I run the normal python code it works without any errors.
Below is the relevant portion of my Dockerfile.
# Extra suff chrome driver needs
RUN apt-get install -y libglib2.0-0=2.50.3-2 \
libnss3=2:3.26.2-1.1+deb9u1 \
libgconf-2-4=3.2.6-4+b1 \
libfontconfig1=2.11.0-6.7+b1
# need this for chrome driver, not just ui
RUN apt-get install -y wget xvfb unzip
# Set up the Chrome PPA
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
# Update the package list and install chrome
RUN apt-get update -y
RUN apt-get install -y google-chrome-stable
# Set up Chromedriver Environment variables
ENV CHROMEDRIVER_VERSION 2.19
ENV CHROMEDRIVER_DIR /chromedriver
RUN mkdir $CHROMEDRIVER_DIR
# Download and install Chromedriver
RUN wget -q --continue -P $CHROMEDRIVER_DIR "http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip"
RUN unzip $CHROMEDRIVER_DIR/chromedriver* -d $CHROMEDRIVER_DIR
# Put Chromedriver into the PATH
ENV PATH $CHROMEDRIVER_DIR:$PATH
You're facing an incompatibility between the chromedriver and chrome browser versions being used.
Here are the two lines in question:
RUN apt-get install -y google-chrome-stable
The above means that you'll download the latest chrome browser.
ENV CHROMEDRIVER_VERSION 2.19
However, over here you're specifically using ChromeDriver v2.19, which is a really old version.
You'll need to use compatible versions, which can generally be found in the release notes:
http://chromedriver.chromium.org/downloads
I installed Chromium 59.0, and I'm trying to run it in headless mode using the following command:
sudo /opt/google/chrome/chrome --headless --disable-gpu --no-sandbox
but I'm getting the following errors:
[0512/174717.638937:WARNING:audio_manager.cc(295)] Multiple instances of AudioManager detected
[0512/174717.639027:WARNING:audio_manager.cc(254)] Multiple instances of AudioManager detected
Has anyone encountered this and found a way to get past it?
I encountered the exact same thing under dockerized ubuntu running karma.js tests.
You will need to have pulseaudio or similar running.
Try:
apt-get install pulseaudio
And before you run chrome
pulseaudio --daemonize
You can see it in my docker-entrypoint.sh:
https://github.com/codeclou/docker-nodejs-chrome-xvfb
When running with docker you will need to run docker with:
--shm-size=128M
Since chrome will complain about small /dev/shm which is 64MB by default.
I am using protractor to run tests against an Angular application. They work on my OSX environment but not on Linux where TeamCity is trying to run it.
When I run this command on my local OSX environment, it works (tested on my co-workers machine, too):
./node_modules/protractor/bin/protractor protractor.conf.js
Using ChromeDriver directly...
..
Finished in 5.55 seconds
2 tests, 2 assertions, 0 failures
When I run this on a linux machine, or a TeamCity job tries to run it, it fails:
./node_modules/protractor/bin/protractor protractor.conf.js
Using ChromeDriver directly...
/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/http/util.js:87
Error('Timed out waiting for the WebDriver server at ' + url));
^
Error: Timed out waiting for the WebDriver server at http://127.0.0.1:52959/
at Error (<anonymous>)
at onResponse (/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/http/util.js:87:11)
at /usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/http/util.js:42:21
at /usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/http/http.js:96:5
at ClientRequest.<anonymous> (/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/http/index.js:136:7)
at ClientRequest.EventEmitter.emit (events.js:95:17)
at Socket.socketErrorListener (http.js:1547:9)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:440:14
at process._tickCallback (node.js:415:13)
==== async task ====
WebDriver.createSession()
at Function.webdriver.WebDriver.acquireSession_ (/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:131:49)
at Function.webdriver.WebDriver.createSession (/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:111:30)
Attempts to resolve:
I have looked at this issue, but a standalone webdriver server is no solution.
I looked at this issue but my version of selenium-wedriver is 2.42.1, so, not the same bug.
Versions:
$ node --version
v0.10.26
$ ./node_modules/protractor/bin/protractor --version
Version 1.0.0
$ uname -mrs
Linux 3.11.0-15-generic x86_64
Progress Update:
Trying to get the version of chrome-webdriver exposed a problem:
$ ./node_modules/protractor/selenium/chromedriver --version
./node_modules/protractor/selenium/chromedriver: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory
From this I concluded there was a dependency issue and found that Selenium requires Chrome. (more).
I installed Chrome on the Linux box using steps like this:
sudo apt-get install libxss1 libappindicator1 libindicator7
sudo wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb
This didn't work exactly like that, but after a few back and forths with dependencies and sudo apt-get install I think I got Chrome installed:
$ google-chrome --version
Google Chrome 36.0.1985.143
This made the chromedriver version work:
$ ./node_modules/protractor/selenium/chromedriver --version
ChromeDriver 2.10.267518
However, running Protractor still does not work:
$ ./node_modules/protractor/bin/protractor protractor.conf.js
Using ChromeDriver directly...
/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:109
var template = new Error(this.message);
^
UnknownError: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.10.267518,platform=Linux 3.11.0-15-generic x86_64)
at new bot.Error (/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:109:18)
at Object.bot.response.checkResponse (/usr/share/TeamCity/buildAgent/work/57bd89f9c9abb5d5/webapp/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/response.js:106:9)
You need to be able to run Chrome or Firefox headless and for that you'll need to configure Xvfb among other things, otherwise Chrome will fail to launch without a proper $DISPLAY.
You could also use PhantomJS but, IMHO, what good does that to e2e testing since is not a real browser.
This is what I'm successfully using for continuous testing: https://github.com/elgalu/docker-selenium
I had the same problem and it resolved just after installing unity-gtk3-module !!
yum install unity-gtk3-module
Installing:
PackageKit-gtk3-module
Updating:
Installing for dependencies:
PackageKit-glib
adwaita-cursor-theme
adwaita-icon-theme
at-spi2-atk
at-spi2-core
cairo-gobject
colord-libs
gtk3
json-glib
libXevie
libgusb
rest
Updating for dependencies:
glib2
i hope this helps