Running selenium-chromedriver using Protractor on linux - selenium

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

Related

Chromedriver can’t be opened because Apple cannot check it for malicious software

Environment:
OS : Big Sur 11.1
Homebrew 3.2.13
Python 3.9.7
Command:
chromedriver —version
Error GUI Alert:

Error via output of .py file attempt to run chromedriver:
raise WebDriverException(selenium.common.exceptions.WebDriverException: Message: Service /opt/homebrew/bin/chromedriver unexpectedly exited. Status code was: -9
Fix Method (1)
As stated in the alert, try updating chromedriver:
Uninstall the current version:
brew uninstall chromedriver
Verify that chromedriver is uninstalled:
brew info chromedriver
Install the newest version of chromedriver:
brew install chromedriver
You can also try:
brew reinstall chromedriver
Fix Method (2) : Still Stuck
If you are still experiencing the issue, this fix helped me.
Determine which chromedriver is being used, run:
which chromedriver
Result :
/opt/homebrew/bin/chromedriver
Use the path to chromedriver in the following command to unblock it.
xattr -d com.apple.quarantine /opt/homebrew/bin/chromedriver
Now run the following:
chromedriver —version
Result :
ChromeDriver 93.0.4577.63
Chromedriver should successfully execute.
Reference
coorasse's answer.
For downloading from the chrome drive website
this one worked for me for MAC m1 chip
Use the path to chromedriver in the following command to unblock it.
xattr -d com.apple.quarantine path/to/chromedrive
I had the same issue this morning, this is what fixed it for me.
Go to the system and preferences -> security and privacy.
Then under general tab you will see a notification that about the
exec you are trying to open.
Just click "open anyway" there.
Go back to the chromedriver exe and open it it will then give you the same error but along with that you will get an option to open it.
Click Open and it should resolve.
Worked for me.

Issues while implementing jenkins docker image+chrome+ruby unknown error: Chrome failed to start: crashed (Selenium::WebDriver::Error::UnknownError)

I am trying to setup jenkins using the official jenkins docker image.
Dockerfile
FROM jenkins/jenkins:lts
USER root
RUN apt-get update && apt install -y ruby-full
RUN apt-get install -y curl
RUN apt -y autoremove
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs
RUN apt-get install -y build-essential
RUN apt install -y wget
RUN gem install --no-ri --no-rdoc --format-executable rake
RUN gem install selenium-webdriver
RUN gem install bundler
RUN npm install -g node-mongo-seeds
#Permissions granted to jenkins user to do a gem install
RUN chown -R jenkins:jenkins /var/lib/gems
RUN apt-get install -y patch ruby-dev zlib1g-dev liblzma-dev
RUN chown -R jenkins:jenkins /usr/local/bin
# We need wget to set up the PPA and xvfb to have a virtual screen and unzip to install the Chromedriver
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.35
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
USER jenkins
While running the job the browser won't open and hit the localhost.
I tried hitting 'google.com' as well
google-chrome --headless --no-sandbox 'https://www.google.com'
still no success
Fontconfig warning: "/etc/fonts/fonts.conf", line 100: unknown element "blank"
[0531/130727.949511:ERROR:browser_process_sub_thread.cc(217)] Waited 17 ms for network service
I am not able understand why jenkins user not able to open the browser.
Google Chrome 74.0.3729.169
ChromeDriver 2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881)
ruby 2.3.3p222 (2016-11-21) [x86_64-linux-gnu]
Jenkins 2.164.3
This error message...
unknown error: Chrome failed to start: crashed (Selenium::WebDriver::Error::UnknownError)
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You are using chromedriver=2.35
Release Notes of chromedriver=2.35 clearly mentions the following :
Supports Chrome v62-64
You are using chrome=74.0
Release Notes of ChromeDriver v74.0 clearly mentions the following :
Supports Chrome v74
So there is a clear mismatch between ChromeDriver v2.35 and the Chrome Browser v74.0
Solution
Upgrade ChromeDriver to current ChromeDriver v74.0 level.
Keep Chrome version at Chrome v74 level. (as per ChromeDriver v2.46 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
Execute your #Test.
So as per #DebanjanB comment it resolved the driver issues but as per the new issue of chrome crashing I resolved it by just adding
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
d = Selenium::WebDriver.for :chrome, options: options

running selenium chrome browser in docker container

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

Error running headless Chromium on Ubuntu

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.

Appium does not start with non sudo installation

Platform: Ubuntu 14.10
Appium - 1.3.7
One similar question I had come across -
How to setup Appium in Ubuntu for android
and following suggestion, I install npm via HomeBrew
And eventually, appium execution fails with error -
error: Appium will not work if used or installed with sudo. Please rerun/install as a non-root user. If you had to install Appium using `sudo npm install -g appium`, the solution is to reinstall Node using a method (Homebrew, for example) that doesn't require sudo to install global npm packages.
Is there anything I missed?
Appium allows to run under sudo since 1.2.3: source
apparently I was on wrong directory when invoking invoking appium. I should be in /node-v0.12.2-linux-x64/bin$ and invoke appium.
even though I was in wrong directory, the error message I received was so descriptive (and misleading) that it made me believe that I installed appium in wrong way.