" Failed to find Chrome binary." in system spec gitlab-ci - selenium-webdriver

Context:
Rails 6.0.3.4
Ruby 2.7.1
In my gitlab CI, I run a system spec using RSpec and Selenium. The test runs well locally but throw the following error in gitlab CI
Failure/Error: driven_by :selenium, using: :chrome
Webdrivers::BrowserNotFound:
Failed to find Chrome binary.
# ./spec/rails_helper.rb:35:in `block (2 levels) in '
Could anyone kindly advise me how to fix this error ?
Here is my .gitlab-ci.yml
image: "ruby:2.7.1-buster"
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- vendor/bundle
- .bundle
- node_modules/
- .yarn
stages:
- build
- test
variables:
POSTGRES_HOST: xxxx
POSTGRES_USER: xxxx
POSTGRES_DB: xxxx
POSTGRES_PASSWORD: xxxx
before_script:
- gem install bundler
- bundle install -j $(nproc) --deployment
job_0_build:
stage: build
script:
- ruby -v
job_3_tests:
stage: test
cache:
paths:
- node_modules/
- .yarn
services:
- postgres:12.1
before_script:
- apt-get update -qq && apt-get install -y -qq nodejs
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
- yarn install --cache-folder .yarn
- yarn --version
- gem install bundler
- bundle install -j $(nproc) --deployment
script:
- bundle exec rake assets:precompile RAILS_ENV=test
- bundle exec rspec
Here is an extraction of my Gemfile.lock on (I think) relevant gems, I can provide others if you find useful
selenium-webdriver (3.142.7)
childprocess (>= 0.5, < 4.0)
rubyzip (>= 1.2.2)
chromedriver-helper (2.1.1)
archive-zip (~> 0.10)
nokogiri (~> 1.8)
capybara (3.33.0)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (~> 1.5)
xpath (~> 3.2)
webdrivers (4.4.1)
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
selenium-webdriver (>= 3.0, < 4.0)

Related

Running react-snap on AWS codebuild

I have a react website that I host on AWS. I have created code pipeline in AWS that connects to my github, which automatically builds the projects using codeBuild and deploys it to S3.
I'm trying to add react-snap to the project. It works well locally but when I try to build it in codebuild I get this error
Error: Failed to launch chrome!
/codebuild/output/src159566889/src/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: error while loading shared libraries: libXss.so.1: cannot open shared object file: No such file or directory
TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
at onClose (/codebuild/output/src159566889/src/node_modules/puppeteer/lib/Launcher.js:348:14)
at Interface.<anonymous> (/codebuild/output/src159566889/src/node_modules/puppeteer/lib/Launcher.js:337:50)
at Interface.emit (events.js:326:22)
at Interface.close (readline.js:416:8)
at Socket.onend (readline.js:194:10)
at Socket.emit (events.js:326:22)
at endReadableNT (_stream_readable.js:1241:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
error Command failed with exit code 1.
I have tried to google it but I didn't find anything specific to codebuild and react-snap. I have found similar questions in regards to running chrome on codebuild but they related to different environments like angular and so I wasn't able to copy their solutions.
This is what my current buildspec.yaml file looks like
version: 0.2
env:
variables:
S3_BUCKET: "xyz"
STAGE: "beta"
phases:
install:
commands:
- yarn install
build:
commands:
- echo "Building for $STAGE"
- yarn build
- sam package --template-file cloudformation/Root.json --s3-bucket ${S3_BUCKET} --s3-prefix WebsiteCF/${CODEBUILD_RESOLVED_SOURCE_VERSION} --output-template-file build/packaged-template.yaml
artifacts:
files:
- '**/*'
base-directory: 'build'
Based on the instruction on the link provided by the error, I tried adding this but it didn't work
install:
commands:
- PYTHON=python2 amazon-linux-extras install epel -y
- yum install -y chromium
- yarn install
I managed to get it working using these steps:
Make sure your AWS code builder is using aws/codebuild/standard:5.0
Go t AWS code builder -> Edit -> Environment -> Override image
Create a addArgs.sh file to your project with this content
# modifies react-snap defaultOptions to add the --no-sandbox and --disable-setuid-sandbox flags so that puppeteer/chromium can run in the codebuild standard image
sed -i "s/puppeteerArgs: \[\],/puppeteerArgs: \[\"--no-sandbox\", \"--disable-setuid-sandbox\"\],/" ./node_modules/react-snap/index.js
echo changed arguments in react-snap
To your buildspec.yml file, add these lines to the install stage
# Install chrome headless
- apt-get -y update
- apt-get --assume-yes install chromium-browser
- sh ./addArgs.sh # run custom script to change options on react-snap to make it work
I found the answer from here - https://github.com/stereobooster/react-snap/issues/122

.flowconfig file in react-native project is missing

I do not have .flowconfig file in my react-native project.
Even then if I add flow locally as :
yarn add --dev flow-bin babel-preset-flow
and then do flow init, it creates an empty .flowconfig file with the latest flow version displayed at end of the file as 0.79.1 . Is it fine? and the rules I had to copy from https://github.com/facebook/react-native/blob/master/.flowconfig which is regularly updated with current flow version(now 0.79.1).
React Native Environment Info:
System:
OS: macOS High Sierra 10.13.4
CPU: x64 Intel(R) Core(TM) i7-4770HQ CPU # 2.20GHz
Memory: 4.56 GB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 8.11.3 - /usr/local/bin/node
Yarn: 1.1.0 - /usr/local/bin/yarn
npm: 5.6.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.0, macOS 10.14, tvOS 12.0, watchOS 5.0
IDEs:
Android Studio: 3.0 AI-171.4443003
Xcode: 10.0/10L232m - /usr/bin/xcodebuild
npmPackages:
react: 16.4.1 => 16.4.1
react-native: 0.56.0 => 0.56.0
npmGlobalPackages:
create-react-native-app: 1.0.0
react-native-cli: 2.0.1
react-native-git-upgrade: 0.2.7
Editor: VSCode
Or
should I not use flow at all in the project, cause may be new version of react-native takes care of it?

circleci (v2.0) using npm when yarn is the run command

There's documentation on setting up yarn for circleci v1 but not v2 because it appears as though they've got yarn baked into the v2 api, however, in my config.yml i explicitly run yarn to install my deps yet, when i review the build logs it shows that npm is used for all my yarn commands... I obviously need to override this / install yarn? Unfortunately it appears that the v2 docs don't touch on this and my google-foo isn't being fruitful...
what's more interesting is that another one of my projects IS using yarn with almost the exact same config... what gives?
heres my current config.yml
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:7.10
# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/mongo:3.4.4
working_directory: ~/repo
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: yarn
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}
# run tests!
- run: yarn test
- run: echo "ALL GOOD IN THE HOOD"
- deploy:
name: Deploy on deploy branch
command: |
if [ "${CIRCLE_BRANCH}" == "deploy" ]; then
./node_modules/.bin/firebase ...
fi
I figured out the problem. My circleci folder was misspelled. I omitted the . and it was using a default config... sigh...

How to make travis execute Angular tests on Chrome ("Please set env variable CHROME_BIN")

I'm working on a sample Angular project generated by yeoman.
I am able to run karma tests locally (I set system variable CHROME_BIN to point to chromium binary, but this could have been done in more elegant way. Just a quick work-around.)
However, when attempting to produce a successful build with travis, I get following error:
ERROR [launcher]: Cannot start Chrome
Can not find the binary google-chrome
Please set env variable CHROME_BIN
I've followed the steps described here (basically using generator-travis-ci)
Then tried to fix it with this - got another error:
/home/travis/build.sh: line 142: ./.travis/scripts/install_chrome.sh: Permission denied
It's a standard angular app created with Yeoman - things should work out of the box, whereas reality is different ...
Has anybody successfully configured it?
Software versions I've been using:
user#machine:~/somewhere $ yo -v; grunt --version; bower -v
1.0.4
grunt-cli v0.1.9
grunt v0.4.1
1.2.6
my Travis job: https://travis-ci.org/vucalur/editor-yeoman-test
Use this solution to get it running using the preinstalled Chromium Version in Travis-CI VM:
https://github.com/karma-runner/karma/issues/1144#issuecomment-53633076
.travis.yml
node_js:
- "0.10"
script: node_modules/karma/bin/karma start test/karma.conf.js --single-run
before_install:
- export CHROME_BIN=chromium-browser
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
karma.conf.js
module.exports = function(config) {
var configuration = {
/* ... */
// start these browsers
browsers: ['Chrome', 'ChromeCanary'],
customLaunchers: {
Chrome_travis_ci: {
base: 'Chrome',
flags: ['--no-sandbox']
}
},
/* ... */
};
if(process.env.TRAVIS){
configuration.browsers = ['Chrome_travis_ci'];
}
config.set(configuration);
};
I'm afraid to say that you can only run Firefox (because it's already installed in the VM) and PhantomJS (because it's portable and headless).
Add the following into your .travis.yml file to startup Firefox:
before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
Then you'll just have to enable Firefox as a Karma browser in your configs.
Documentation
Based in karma-runner project issue (https://github.com/karma-runner/karma/issues/1144#issuecomment-53633076) You should set CHROME_BIN environment variable in your .travis.yml and configure a customLauncher in your karma file configuration.
For example, your .travis.yml file content will be:
language: node_js
node_js:
- '0.10'
before_script:
- 'export CHROME_BIN=chromium-browser'
- 'export DISPLAY=:99.0'
- 'sh -e /etc/init.d/xvfb start'
- 'npm install -g bower karma grunt-cli jshint'
- 'npm install'
- 'bower install'
And your karma.conf.js content:
module.exports = function(config) {
config.set({
// ... your default content
// This is the new content for your travis-ci configuration test
// Custom launcher for Travis-CI
customLaunchers: {
Chrome_travis_ci: {
base: 'Chrome',
flags: ['--no-sandbox']
}
},
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: true
});
if(process.env.TRAVIS){
config.browsers = ['Chrome_travis_ci'];
}
};
Option 1: APT Addon
You can make Travis execute Angular tests in Chrome by using the APT Addon to install the google-chrome-stable package and run it headless using Xvfb.
# Set language
language: node_js
# Set version of node
node_js:
- node
# Set DISPLAY for Xvfb
env:
- DISPLAY=:99.0
# Use APT Addon to install Chrome
addons:
apt:
sources:
- google-chrome
packages:
- google-chrome-stable
# Start Xvfb so you can run headless Chrome
before_install:
- sh -e /etc/init.d/xvfb start
# Install packages
install:
- npm install
# Run tests in continuous integration mode
script:
- ng test --single-run
Option 2: Chrome Addon
Alternatively, if your virtualization environment is Linux Trusty or OS X you can use the Chrome addon in headless mode.
# Use a trusty version of linux
dist: trusty
# Set language
language: node_js
# Set version of node
node_js:
- node
# Install Chrome addon
addons:
- chrome: stable
# Install packages
install:
- npm install
# Run tests in continuous integration mode with headless chrome
script:
- karma start --single-run --browsers ChromeHeadless
To run e2e tests, update protractor.conf.js to specify headless chrome.
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: [ '--headless', '--disable-gpu' ]
}
}

rails install pg - Can't find the 'libpq-fe.h header

$ sudo bundle install
Result
Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/..
Using rake (0.9.2.2)
Using i18n (0.6.1)
Using multi_json (1.3.6)
Using activesupport (3.2.8)
Using builder (3.0.4)
Using activemodel (3.2.8)
Using erubis (2.7.0)
Using journey (1.0.4)
Using rack (1.4.1)
Using rack-cache (1.2)
Using rack-test (0.6.2)
Using hike (1.2.1)
Using tilt (1.3.3)
Using sprockets (2.1.3)
Using actionpack (3.2.8)
Using mime-types (1.19)
Using polyglot (0.3.3)
Using treetop (1.4.11)
Using mail (2.4.4)
Using actionmailer (3.2.8)
Using arel (3.0.2)
Using tzinfo (0.3.33)
Using activerecord (3.2.8)
Using activeresource (3.2.8)
Using bundler (1.2.1)
Using coffee-script-source (1.4.0)
Using execjs (1.4.0)
Using coffee-script (2.2.0)
Using rack-ssl (1.3.2)
Using json (1.7.5)
Using rdoc (3.12)
Using thor (0.16.0)
Using railties (3.2.8)
Using coffee-rails (3.2.2)
Using jquery-rails (2.1.3)
Installing pg (0.14.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/bin/ruby1.8 extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby1.8
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
Gem files will remain installed in /var/lib/gems/1.8/gems/pg-0.14.1 for inspection.
Results logged to /var/lib/gems/1.8/gems/pg-0.14.1/ext/gem_make.out
An error occurred while installing pg (0.14.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.14.1'` succeeds before bundling.
I am make $ gem install pg -v '0.14.1' But this is not help
My Gemfile
source 'https://rubygems.org'
#gem 'rails', '3.0.9'
#gem 'sqlite3', '1.3.6', :group => :development
gem 'rails', '3.2.8'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
gem 'pg'
gem 'taps'
gem 'json'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
#group :production do
#gem 'pg'
#end
#group :development do
#gem 'sqlite3'
#end
gem_make.out
/usr/bin/ruby1.8 extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby1.8
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
mkmf.log
find_executable: checking for pg_config... -------------------- yes
--------------------
find_header: checking for libpq-fe.h... -------------------- no
"gcc -E -I. -I/usr/lib/ruby/1.8/i686-linux -I. -D_FORTIFY_SOURCE=2 -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -I -fno-strict-aliasing -g -g -O2 -fPIC conftest.c -o conftest.i"
conftest.c:1:22: fatal error: libpq-fe.h: No such file or directory
compilation terminated.
checked program was:
/* begin */
1: #include <libpq-fe.h>
/* end */
--------------------
Help me please. Thank you.
Sorry for this text.
Your post does not have much context to explain the code sections; please explain your scenario more clearly.
Just make this
$ sudo apt-get install libpq-dev
This is answered in Can't find the 'libpq-fe.h header when trying to install pg gem
Depending on your environment:
Mac: brew install postgresql
Ubuntu: sudo apt-get install libpq-dev
RHEL: yum install postgresql-devel
Alpine: apk add postgresql-dev
Then run gem install pg again
SO: Ubuntu
Language Programming: C
$ sudo apt-get install libpq-dev
In my case I was putting the directory path wrong. So:
From: gcc -o lib_version lib_version.c -I/usr/include/postgresql -lpq -std=c99
To: gcc -o lib_version lib_version.c -I /usr/include/postgresql -lpq -std=c99
GL
Try this:
brew install postgresql
gem install pg
bundle install
On Fedora/RHEL systems this did the trick:
sudo yum install libpqxx-devel
For Alpine Linux, you can add libpq-fe.h with:
apk add postgresql-dev
For Amazon Linux (AWS):
sudo yum install postgresql-devel
then run your command again
On Mac OS X run like this:
gem install pg -- --with-pg-config=***/path/to/pg_config***
***/path/to/pg_config*** is path to pg_config
I had this issue with a Jenkins server on Amazon AMI.
$ pg_config | grep VERSION
VERSION = PostgreSQL 9.4.9
Then depending on which version you need you can install the required lib
$ sudo yum list postgresql* | grep devel
postgresql92-devel.x86_64 9.2.18-1.59.amzn1 #amzn-main
postgresql94-devel.x86_64 9.4.9-1.67.amzn1 #amzn-main
postgresql8-devel.x86_64 8.4.20-5.52.amzn1 amzn-main
postgresql93-devel.x86_64 9.3.14-1.62.amzn1 amzn-main
postgresql95-devel.x86_64 9.5.4-1.71.amzn1 amzn-main
Then you can just install the corresponding version, in my case for version 9.4:
sudo yum install postgresql94-devel
This was happening me using capistrano while deploying my app in a centos7 distro. Apparently gem is requiring some header files which can be resolved installing the right development package.
I fixed it by running sudo yum search postgres | grep devel and found the right package for my postgres installation which was 10.
Then simply run sudo yum install postgresql10-devel, and eureka!
try this:
sudo apt-get install libpq-dev
gem install pg
it would be works!
On mac make sure your postgres is linked.
You can do it by
brew link --overwrite postgresql
This fixed the issue for me.
I use Ubuntu-16. And I use the method showed here:https://www.postgresql.org/download/linux/ubuntu/ to install postgresql-9.6;
And I use "sudo apt-get install libpq-dev" to install the devlib.But It still can't work. So I use the method ln to establish soft link, here it is :
sudo ln -s /usr/include/postgresql/libpq-fe.h /usr/include/;
sudo ln -s /usr/include/postgresql/postgres_ext.h /usr/include/
And I solve the problem at last.
brew install postgresql worked for me.
Installation of postgresql was giving another error
Error: The following directories are not writable by your user:
/usr/local/lib/pkgconfig
/usr/local/share/info
/usr/local/share/man/man3
This error was fixed by giving access to the mentioned directories to the current user
sudo chown -R $(whoami) (path)
This worked for me:
sudo gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
If you've installed postgresql on MacOS via Homebrew
brew install postgresql#95 # 9.5 is the version needed in my project
you may need to find the pg_config depending on your version of libpq
my project needed older version of pg.
gem install pg -v '0.20.0' -- --with-pg config=/usr/local/Cellar/libpq/13.1/bin/pg_config

Resources