Configure GitLab CI to run features tests with rspec / selenium / Firefox - selenium-webdriver

I am new to gitlab CI and I need help to configure gitlab-ci to run feature tests with Firefox (Ruby 2.7 / Rails 6 / Rspec / Capybara).
All is ok except feature tests.
I think I have to configure something with Firefox, or maybe install something.
Thanks for your help !
Error message when running tests :
Failure/Error: visit "/meth/methodologies/#{#meth.id}/edit"
Selenium::WebDriver::Error::WebDriverError:
Could not find Firefox binary (os=linux). Make sure Firefox is installed or set the path manually with Selenium::WebDriver::Firefox::Binary.path=
File .gitlab-ci.yml
stages:
- build
- test
- deploy
image: ruby:2.7.1
cache: &global_cache
key: ${CI_COMMIT_REF_SLUG}
paths:
- apt-cache/
- vendor/ruby
- node_modules
- .yarn-cache
policy: pull-push
.base:
cache:
# inherit all global cache settings
<<: *global_cache
before_script:
- gem install bundler --no-document
- bundle install --jobs $(nproc) "${FLAGS[#]}" --path=vendor
.base_db:
# extends: .base
services:
- name: mysql:8.0.21
command: ['--default-authentication-plugin=mysql_native_password']
- name: selenium/standalone-firefox
alias: selenium
variables:
MYSQL_ROOT_PASSWORD: xxxx
DB_USERNAME: xxxx
DB_PASSWORD: xxxx
DB_HOST: mysql
RAILS_ENV: test
DISABLE_SPRING: 1
BUNDLE_PATH: vendor/bundle
cache:
# inherit all global cache settings
<<: *global_cache
before_script:
# install yarn & dependencies
- export APT_CACHE_DIR=`pwd`/apt-cache && mkdir -pv $APT_CACHE_DIR
- wget -q -O - https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
- echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list
- apt-get update -qq && apt-get -o dir::cache::archives="$APT_CACHE_DIR" install -y yarn
- yarn config set cache-folder .yarn-cache
- yarn install
- gem install bundler --no-document
- bundle install --jobs $(nproc) "${FLAGS[#]}" --path=vendor/ruby
# Setup test database
- cp config/database.ci.yml config/database.yml
- RAILS_ENV=test bundle exec rails db:create db:migrate
rubocop:
extends: .base
stage: build
# cache:
# policy: pull-push
script:
- bundle exec rubocop app --fail-level W
rspec:
extends: .base_db
stage: test
script:
- bundle exec rspec -t ~type:feature
artifacts:
paths:
- coverage/
features:
extends: .base_db
stage: test
script:
- bundle exec rspec
# services:
# - name: selenium/standalone-firefox
# alias: selenium
# artifacts:
# paths:
# - coverage/
pages:
stage: deploy
dependencies:
- rspec
script:
- mv coverage/ public/
artifacts:
paths:
- public
expire_in: 30 days
# only:
# - master
EDIT :
I added the installation of firefox.
Tests that use js still don't work. The error is now as follows :
Failure/Error: visit "/meth/methodologies/#{#meth.id}/edit"
Selenium::WebDriver::Error::UnknownError:
Process unexpectedly closed with status 1

You have to use your browser with headless option
rails_helper.rb
Capybara.register_driver :headless_firefox do |app|
browser_options = Selenium::WebDriver::Firefox::Options.new()
browser_options.args << '--headless'
Capybara::Selenium::Driver.new(
app,
browser: :firefox,
options: browser_options
)
end
Capybara.javascript_driver = :headless_firefox
Capybara.configure do |config|
config.default_max_wait_time = 10 # seconds
config.default_driver = :headless_firefox
end

Related

React app successfully deployed on cloudrun using cloudbuild but still the cloudrun url gives error

I have been trying to deploy the React app on cloud run using dockers & cloudbuild.yaml & even though the deployment & everything is successful, cloudrun url is showing weird error as:-
I tried redeploying tthrough cloudbuild again & most of the times the cloudbuild errors out with timeout error as this:-
The dockerfile looks like this:-
# build environment
FROM node:14-alpine as react-build
WORKDIR /app
COPY . ./
RUN yarn
RUN yarn build
# server environment
FROM nginx:alpine
COPY nginx.conf /etc/nginx/conf.d/configfile.template
COPY --from=react-build /app/build /usr/share/nginx/html
ENV PORT 8080
ENV HOST 0.0.0.0
EXPOSE 8080
CMD sh -c "envsubst '\$PORT' < /etc/nginx/conf.d/configfile.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
The cloudbuild file looks like this:-
# cloudbuild.yaml
steps:
# Build the container image
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/premi0103982-sustaina/cee-portal:latest', '.']
# dir: 'app' # Working directory for build context
# Push the container image to Container Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/premi0103982-sustaina/cee-portal:latest']
# Deploy container image to Cloud Run
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: gcloud
args: ['beta', 'run', 'deploy', 'cee-portal', '--image', 'gcr.io/$PROJECT_ID/cee-portal:latest', '--region',
'europe-west3', '--platform', 'managed', '--allow-unauthenticated']
Can you please tell me what wrong I'm doing...?

Gitlab CI: why do I get an error when I try to define the pages stage?

I'm trying to publish a create-react-app on Gitlab, using its CI.
This is my .gitlab-ci.yml file:
stages:
- build
- pages
build:
image: node:16
stage: build
script:
- npm install
- npm build
artifacts:
paths:
- build/
pages:
image: alpine:latest
stage: deploy
variables:
GIT_STRATEGY: none # Do not clone git repo
script:
- mv build public
artifacts:
paths:
- public
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
But unfortunately I get this error:
This GitLab CI configuration is invalid: pages job: chosen stage does not exist; available stages are .pre, build, pages, .post.
What's wrong with my configuration?
You need to change your stages.
You have:
stages:
- build
- pages
but define:
pages:
image: alpine:latest
stage: deploy
The stage needs to match:
stages:
- build
- deploy <-------

Permission error on Gitlab CI deployment with google app engine

I try to make a full process of integrated deployment with Gitlab and Google AppEngine.
But the deployment fail because it seems I miss rights. I really don't know which right is needed here.
I activated the App Engine API and the Cloud Build API.
The rights my service has:
my gitlab-ci.yml file:
Staging Deployment:
stage: Deploy
environment:
name: Staging
before_script:
- echo "deb http://packages.cloud.google.com/apt cloud-sdk-jessie main" | tee /etc/apt/sources.list.d/google-cloud-sdk.list
- curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
- apt-get update
- apt-get -qq -y install google-cloud-sdk
script:
- echo $DEPLOY_KEY_FILE_PRODUCTION > /tmp/$CI_PIPELINE_ID.json
- gcloud auth activate-service-account --key-file /tmp/$CI_PIPELINE_ID.json
- gcloud config list
- gcloud config set project $PROJECT_ID_PRODUCTION
- gcloud --quiet --project $PROJECT_ID_PRODUCTION app deploy gae/test.yml
only:
refs:
- master
And finally my test.yml:
# [START django_app]
runtime: python37
service: testing
entrypoint: gunicorn -b :$PORT manta.wsgi --timeout 120
default_expiration: "5m"
env_variables:
DJANGO_SETTINGS_MODULE: manta.settings.dev
handlers:
# This configures Google App Engine to serve the files in the app's
# static directory.
- url: /static
static_dir: static/
# This handler routes all requests not caught above to the main app.
# It is required when static routes are defined, but can be omitted
# (along with the entire handlers section) when there are no static
# files defined.
- url: /.*
script: auto
# [END django_app]
And the error I have during deployment:
ERROR: (gcloud.app.deploy) Permissions error fetching application [apps/testing]. Please make sure you are using the correct project ID and that you have permission to view applications on the project.

dockerized react - how to auto enable hot reloading

I'm dockerizing MERN apps at the moment.
The apps is divided into 2, react app at frontend and express app at backend.
The goals is to enable hot reloading at the react app.
Here's my docker-compose.yml file :
version: '3'
services:
mango:
container_name: mango
image: nginx:alpine
ports:
- 3000:80
volumes:
- ./docker/app/nginx.conf:/etc/nginx/conf.d/default.conf
- ./build:/usr/share/nginx/html
depends_on:
- mango-builder
command: "/bin/sh -c 'nginx -g \"daemon off;\"'"
logging:
options:
max-size: "10m"
max-file: "3"
networks:
- local_network
mango-builder:
container_name: mango-builder
image: node:12.13.0
working_dir: /app
volumes:
- .:/app
command: bash -c "rm -rf /app/package-lock.json && rm -rf /app/yarn.lock && yarn && if [ `$NODE_ENV` = `development` ]; then yarn run start; else yarn run build; fi"
logging:
options:
max-size: "10m"
max-file: "3"
networks:
- local_network
networks:
local_network:
Note that:
When the NODE_ENV is set to development, it will run the yarn run start command.
yarn will try to recompile dependencies whenever there's a react component change
mango-builder will be built first before the mango
The build folder was generated by mango-builder, then it's attached into mango (check the volumes section)
The react app is running well at browser
When I try to change the react modules, somehow the hot reloading is not working.
I have a feeling I need to make the yarn run start keep running in the background, but I don't know how to do it.
Any thoughts?

Google cloud build unexpected char : in cloudbuild.yaml

I am getting the following error in my google cloud build
Failed to trigger build: failed unmarshalling build config cloudbuild.yaml: yaml: line 12: could not find expected ':'
I can not pinpoint where exactly I am missing : in my cloudbuild.yaml file
steps:
# Install
- name: "gcr.io/cloud-builders/npm"
args: ["install"]
# Update submodules
- name: "gcr.io/cloud-builders/git"
entrypoint: "bash"
args:
- "-c"
- |
git config -f .gitmodules submodule.myprojectsubmodule.url https://source.developers.google.com/p/myproject/r/github_myprojectsubmodule
git submodule init
git submodule update
# Lint
- name: "gcr.io/cloud-builders/npm"
args: ["run", "lint"]
# Test
- name: "gcr.io/cloud-builders/npm"
args: ["run", "test"]
# Build
- name: "gcr.io/cloud-builders/gcloud"
args:
- kms
- decrypt
- --ciphertext-file=.env.enc
- --plaintext-file=.env
- --location=global
- --keyring=myproject
- --key=cloudbuild-env
- name: "gcr.io/cloud-builders/npm"
args: ["run", "build"]
# Deploy
- name: "gcr.io/cloud-builders/npm"
args: ["run", "deploy"]
I have added # Update submodules step using the following comment https://github.com/GoogleCloudPlatform/cloud-builders/issues/26#issuecomment-463465138
To be a valid yaml format, the git commands should be correctly aligned under the | symbol in Update submodules section.
# Update submodules
- name: "gcr.io/cloud-builders/git"
entrypoint: "bash"
args:
- "-c"
- |
git config -f .gitmodules submodule.myprojectsubmodule.url https://source.developers.google.com/p/myproject/r/github_myprojectsubmodule
git submodule init
git submodule update
A YAML validator could be useful in this case, for example https://codebeautify.org/yaml-validator.

Resources