Chromedriver on Travis-CI - google-chrome

I am having trouble getting chromedriver on Travis-CI working for my project knockout-secure-binding. I am trying to use WebdriverJS to automate testing with Chrome, at the least.
I noted that there seems to be some issues with chromedriver on Travis-CI, including:
http://github.com/travis-ci/travis-ci/issues/938
http://github.com/travis-ci/travis-ci/issues/272
https://code.google.com/p/chromedriver/issues/detail?id=308
The issue seems to be a variant of "chrome not reachable", and from what I can gather it requires an upstream engagement by Google to fix it.
The details of the error are available through the Travis build log.
No workaround is apparent, though one comment mentioned using --no-sandbox, but it is not clear where or how one would employ this in WebdriverJS.
Any thoughts on this would be sincerely appreciated.
—— Edit ——
As a matter of interest I am using Sauce Labs in lieu of Chromedriver.

There's an easier way to launch Chrome on Travis CI, simply specify google-chrome in addons/apt/sources and google-chrome-package in addons/apt/packages.
Here's my sample config for a better understanding:
sudo: required
dist: trusty
addons:
apt:
sources:
- google-chrome
packages:
- google-chrome-stable
language: node_js
node_js:
- "6"
cache:
directories: node_modules
branches:
only: master
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- npm i -g npm#^3
- sleep 3

I think Travis does support chrome driver, if you add these in your travis.yml, extract the right chromedriver and unzip it to a known location, so that you can trace it later.
before_script:
- wget http://chromedriver.storage.googleapis.com/2.10/chromedriver_linux64.zip
- unzip chromedriver_linux64.zip -d /home/travis/virtualenv/python2.7.9/
- export CHROME_BIN=chromium-browser
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3
Plus when you call selenium or any testing automation library, you would need to add this the code here is in Python but this can be done in Java and Ruby as well.
options = webdriver.ChromeOptions()
options.binary_location = '/usr/bin/chromium-browser'
#All the arguments added for chromium to work on selenium
options.add_argument("--no-sandbox") #This make Chromium reachable
options.add_argument("--no-default-browser-check") #Overrides default choices
options.add_argument("--no-first-run")
options.add_argument("--disable-default-apps")
driver = webdriver.Chrome('/home/travis/virtualenv/python2.7.9 /chromedriver',chrome_options=options)

EDIT: As of October 2018, Travis CI is slowly moving away from containers (see official announcement). Therefore, one can omit sudo: false, but the given ChromeDriver setup still works.
If you want to use a container-based environment (fast boot time but no sudo), you can also do it as follows (include language and so forth accordingly):
dist: trusty
sudo: false
addons:
chrome: stable
apt:
packages:
- chromium-chromedriver
before_script:
# include ChromeDriver in PATH
- ln --symbolic /usr/lib/chromium-browser/chromedriver "${HOME}/bin/chromedriver"
# start Chrome and listen on localhost
- google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &
Afterwards, as you already mentioned, add --no-sandbox to your Chrome options (taken from this gist):
var webdriver = require('selenium-webdriver');
var chromeOptions = {
'args': ['--no-sandbox']
};
var chromeCapabilities = webdriver.Capabilities.chrome();
chromeCapabilities.set('chromeOptions', chromeOptions);
var driver = new webdriver.Builder().withCapabilities(chromeCapabilities).build();
This is due to an issue in Travis CI. However, if you need sudo anyway or have a long-running build where a container-based environment makes only limited sense, you can also set sudo: true and omit adding --no-sandbox.
Additional resources:
Google Chrome addon on Travis CI
GUI and headless browser testing on Travis CI
How to make travis execute Angular tests on Chrome ("Please set env variable CHROME_BIN")

Related

CircleCI is unable to read the JUnit xml generated by Behave while splitting the test by timings

Ok, so I am trying to split my Appium tests by their timing in CircleCI for running the test in parallel. My tests are written in behave(Python) and I am generating the JUnit XML file. Here is my config.yml file
version: 2.1
orbs:
macos: circleci/macos#2.2.0
jobs:
example-job:
macos:
xcode: 13.4.1
parallelism: 4
resource_class: large
steps:
- checkout
- run:
name: Install appium server
command: |
sudo npm update -g
sudo npm install -g appium
sudo npm install -g wd
- run:
name: Start appium server
command: appium --address localhost --port 4723
background: true
- run:
name: Installing Dependencies
command: pip3 install -r requirements.txt
- run:
name: Test application
command: |
TEST=$(circleci tests glob "features/featurefiles/*.feature" | circleci tests split --split-by=timings --timings-type=classname)
echo $TEST
behave $TEST --junit
- store_test_results:
path: reports
- store_artifacts:
path: ./Logs
destination: logs-file
- store_artifacts:
path: ./screenshots
workflows:
example-workflow:
jobs:
- example-job
When I am running the test, I am getting the error "No timing found for "features/featurefiles/XXX.feature" and it is splitting the test by the filename. It runs well but the split is not happening by the timing.
When the execution is done, I can see the data in the TESTS tab, also in the Timing Tab
I believe CircleCI is not able to read the JUnit file generated by Behave, it is searching for the different JUnit XML file. How can we make CircleCI read the JUnit file generated by Behave?
If anyone face such issue, please take a look at the classname in the JUnit report. There is a format in which CircleCI read the classname. In my case, the classname in the JUnit report was mentioned as
features.featurefiles.Login.feature
But the CircleCI was looking for the classname in below format
features/featurefiles/Login.feature
I had to write a utility to change the classname in the report once the execution was completed.Once it was done, CircleCI was able to read the timings.
Hope it help someone :)

Chromedriver does not respond on Centos 7

Hi in a headless centos 7 I am trying to getting work headless selenium tests.
To do that I Installed google-chrome, chromedriver and selenium pip package but I have no success here is what I have done.
google-chrome version:
yum list installed |grep google-chrome
google-chrome-stable.x86_64 83.0.4103.106-1 #google-chrome
I downloaded chrome driver version 83.0.4103.39 from this link, unzip it and move it to the /usr/bin/local
-rwxr-xr-x 1 root root 10774816 May 5 23:53 chromedriver
and that path is in env as well.
PATH=...:/usr/local/bin/chromedriver:/usr/local/bin/
When I type chromdriver in the terminal nothing happens. It just stucks. I am behind corporate proxy so I can't really try to change firewall or etc. What am i doing wrong ?
Don't put binary executables on $PATH, but only directory /usr/local/bin.
You'll have to source the profile after editing it: . ~/.bashrc.
And you might have to configure it for headless mode:
options = webdriver.ChromeOptions()
options.add_argument('window-size=1920x1080');
options.add_argument('--headless')
options.add_argument('--incognito');
Also check for possible alerts there: sealert -a /var/log/audit/audit.log.

NaCl helper process running without a sandbox! error when running npm tests

I'n having a problem when running some npm test. The error I'm receiving is: "NaCl helper process running without a sandbox!", which is true, as I'm running the browser with the "--no-sandbox" option. I have to run this option due to the fact that the browser runs as root, and I don't have an option to run it a different user at all(it's a docker image).
Can anyone please help me to sort it out?
P.S I'm installing the browser in the following way:
RUN apt-get update
RUN apt-get install -y nodejs npm
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb https://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
RUN apt-get install -y apt-transport-https
RUN apt-get update
RUN apt-get install -y google-chrome-stable
Thanks in advance!
This error message...
NaCl helper process running without a sandbox!
...implies that you have no setuid sandbox in your system, hence the program was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.
Solution
A quick solution will be, if you want to run Chrome and only use the namespace sandbox, you can set the flag:
--disable-setuid-sandbox
This flag will disable the setuid sandbox (Linux only). But if you do so on a host without appropriate kernel support for the namespace sandbox, Chrome will not spin up. As an alternative you can also use the flag:
--no-sandbox
This flag will disable the sandbox for all process types that are normally sandboxed.
Example:
chromeOptions: {
args: ['--disable-setuid-sandbox', '--no-sandbox']
},
You can find a detailed discussion in Security Considerations - ChromeDriver - Webdriver for Chrome
Deep dive
As per the documentation in Linux SUID Sandbox Development google-chrome needs a SUID helper binary to turn on the sandbox on Linux. In majority of the cases you can install the proper sandbox for you using the command:
build/update-linux-sandbox.sh
This program will install the proper sandbox for you in /usr/local/sbin and tell you to update your .bashrc if required.
However, there can be some exceptions as an example, if your setuid binary is out of date, you will get messages such as:
Running without the SUID sandbox!
Or
The setuid sandbox provides API version X, but you need Y
You are using a wrong version of the setuid binary!
In these cases, you need to:
Build chrome_sandbox whenever you build chrome (ninja -C xxx chrome chrome_sandbox instead of ninja -C xxx chrome)
After building, execute update-linux-sandbox.sh.
# needed if you build on NFS!
sudo cp out/Debug/chrome_sandbox /usr/local/sbin/chrome-devel-sandbox
sudo chown root:root /usr/local/sbin/chrome-devel-sandbox
sudo chmod 4755 /usr/local/sbin/chrome-devel-sandbox
Finally, you have to include the following line in your ~/.bashrc (or .zshenv):
export CHROME_DEVEL_SANDBOX=/usr/local/sbin/chrome-devel-sandbox
If you are using karma to run your tests, make sure you are using ChromeHeadless as the browser on karma.conf.js

xcrun: error: unable to find utility "xcode-select", not a developer tool or in PATH

when I execute the command “pod update”,I found some problems in this process.The detail information is as follows.
$ pod update
Update all pods
Updating local specs repositories
CocoaPods 1.1.0.beta.1 is available.
To update use: gem install cocoapods --pre
[!] This is a test version we'd love you to try.
For more information see http://blog.cocoapods.org
and the CHANGELOG for this version http://git.io/BaH8pQ.
Analyzing dependencies
sh: line 1: 4173 Segmentation fault: 11 /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk / -find xcode-select 2> /dev/null
xcrun: error: unable to find utility "xcode-select", not a developer tool or in PATH
Downloading dependencies
Using AFNetworking (3.1.0)
Using MJExtension (3.0.12)
Using ReactiveCocoa (2.1.8)
Using SDWebImage (3.8.1)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There are 4 dependencies from the Podfile and 4 total pods installed.
$
I was struck by the problem very long .I hope for your help!Thank you in advance!
opened Xcode.
Preferences
Locations
Selected the Command Lin Tools
credit : http://www.jianshu.com/p/6b56aba2ee05

Install specific chromedriver for protractor

I am having an issue with chrome driver that runs on the CircleCi.
The problem is that when running:
./node_modules/.bin/webdriver-manager update
and then checking the version of chromedriver and selenium with the command:
ls -lt node_modules/protractor/selenium
it shows the latest versions are:
selenium-server-standalone-2.45.0.jar
chromedriver
chromedriver_2.15.zip
According to the npm.taobao.org note ChromeDriver version 2.15 supports Chrome v40-43. But CicleCi documentation says that it uses Chrome version 38.0.
Consequently, I need to use ChromeDriver v2.13 which is compatible with Chrome v38.0.
My question is that how can I force webdriver-manager to use ChromeDriver v2.13 instead of the latest one.
This should probably be a feature request for the protractor team. But this is what I recommend you to do:
Change the webdriverVersions property on protractor's config.json file. webdriver-manager uses this property to download the files.
#Andres suggested a good solution, but the easiest can be adding a circle.yml file that contains the following command to upgrade chrome version:
test:
pre:
- sudo apt-get update && sudo apt-get install --only-upgrade google-chrome-stable