0

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
LiKaZ
  • 306
  • 3
  • 9
  • Try with [Firefox Headless for Selenium](https://stackoverflow.com/questions/46753393/how-to-make-firefox-headless-programmatically-in-selenium-with-python) – Sourav Nov 13 '20 at 17:33
  • Thanks @SouravAtta . I will try this when I find time, and post here if I need more help. – LiKaZ Nov 26 '20 at 07:29

1 Answers1

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
  • This is perfectly working. Thanks ! I added this in gitlab-ci to install firefox `apt-get update && apt-cache search firefox && apt-get install -y firefox-esr` Do you know if this is the good way ? – LiKaZ Jun 01 '21 at 09:02