Can't connect to Selenium::WebDriver

rails
ruby

#1

Hello,

I am in the process of upgrading our Rails app to Circle CI 2.0

This is my V1 file

dependencies:
  pre:
    - pip install mozdownload mozinstall
    - mozdownload --version 57.0.4 --destination firefox.tar.bz2
    - mozinstall firefox.tar.bz2
    - wget -O geckodriver.tar.gz https://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-linux64.tar.gz
    - gunzip -c geckodriver.tar.gz | tar xopf -
    - chmod +x geckodriver && mv geckodriver /home/ubuntu/bin/
machine:
  environment:
    PATH: "${HOME}/${CIRCLE_PROJECT_REPONAME}/firefox:${PATH}"
  services:
    - redis
test:
  override:
    - bundle exec rspec -r rspec_junit_formatter --format RspecJunitFormatter -o $CIRCLE_TEST_REPORTS/rspec/junit.xml
  post:
    - bundle exec brakeman -q -z
    - bundle exec rubocop
- bundle exec license_finder

and this is my V2 file

version: 2
jobs:
  build:
    working_directory: ~/creditspring
    parallelism: 1
    environment:
      CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
      CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
    docker:
    - image: circleci/ruby:2.4.2-node-browsers
      environment:
        RAILS_ENV: test
        RACK_ENV: test
        PGHOST: 127.0.0.1
        PGUSER: pguser
    - image: redis
    - image: postgres:10.4
      environment:
        POSTGRES_USER: pguser
        POSTGRES_PASSWORD: ""
        POSTGRES_DB: creditspring
    steps:
    - checkout
    - run:
        name: Install dependencies
        command: sudo apt-get update && sudo apt-get install -y redis-tools
    - run:
        name: Start the redis server
        command: sudo redis-cli ping >/dev/null 2>&1 || sudo service redis-server start
    - run:
        name: Create artifacts folders to store build results
        command: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS

    # Install gems with cache support
    - type: cache-restore
      name: Restore bundle cache
      key: frontoffice-{{ checksum "Gemfile.lock" }}
    - run:
        name: Install gems
        command: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
    - type: cache-save
      name: Store bundle cache
      key: frontoffice-{{ checksum "Gemfile.lock" }}
      paths:
        - vendor/bundle

    # Setup database
    - run:
        name: Create database config
        command: |-
          mkdir -p config && echo 'test:
            database: creditspring
            pool: 5
            encoding: unicode
            adapter: postgresql
            username: pguser
            host: localhost
          ' > config/database.yml
    - run:
        name: Create test database
        command: bundle exec rake db:create db:schema:load --trace

    - run:
        name: Run tests
        command: bundle exec rspec --no-color -r rspec_junit_formatter --format RspecJunitFormatter -o $CIRCLE_TEST_REPORTS/rspec/junit.xml

    # Post test checks
    - run:
        name: Run Rubocop for checking code conventions
        command: bundle exec rubocop
        when: always
    - run:
        name: Run license_finder to check if open source licenses have been approved
        command: bundle exec license_finder
        when: always
    - run:
        name: Run Brakeman to look for security vulnerabilities
        command: bundle exec brakeman -q -z
        when: always
    - store_test_results:
        path: /tmp/circleci-test-results
    - store_artifacts:
        path: /tmp/circleci-artifacts
    - store_artifacts:
        path: /tmp/circleci-test-results

The problem I am having is that it seems like the selenium-webdriver gem is not able to spin up a firefox instance. I tried to SSH to the machine and do the following:

require "selenium-webdriver"
driver = Selenium::WebDriver.for :firefox

but it is stuck and I get this after some time waiting and manually cancelling.

Net::ReadTimeout: Net::ReadTimeout
	from /usr/local/lib/ruby/2.4.0/net/protocol.rb:176:in `rbuf_fill'
	from /usr/local/lib/ruby/2.4.0/net/protocol.rb:154:in `readuntil'
	from /usr/local/lib/ruby/2.4.0/net/protocol.rb:164:in `readline'
	from /usr/local/lib/ruby/2.4.0/net/http/response.rb:40:in `read_status_line'
	from /usr/local/lib/ruby/2.4.0/net/http/response.rb:29:in `read_new'
	from /usr/local/lib/ruby/2.4.0/net/http.rb:1446:in `block in transport_request'
	from /usr/local/lib/ruby/2.4.0/net/http.rb:1443:in `catch'
	from /usr/local/lib/ruby/2.4.0/net/http.rb:1443:in `transport_request'
	from /usr/local/lib/ruby/2.4.0/net/http.rb:1416:in `request'
	from /usr/local/lib/ruby/2.4.0/net/http.rb:1409:in `block in request'
	from /usr/local/lib/ruby/2.4.0/net/http.rb:877:in `start'
	from /usr/local/lib/ruby/2.4.0/net/http.rb:1407:in `request'
	from /home/circleci/creditspring/vendor/bundle/ruby/2.4.0/gems/selenium-webdriver-3.12.0/lib/selenium/webdriver/remote/http/default.rb:121:in `response_for'
	from /home/circleci/creditspring/vendor/bundle/ruby/2.4.0/gems/selenium-webdriver-3.12.0/lib/selenium/webdriver/remote/http/default.rb:76:in `request'
	from /home/circleci/creditspring/vendor/bundle/ruby/2.4.0/gems/selenium-webdriver-3.12.0/lib/selenium/webdriver/remote/http/common.rb:62:in `call'
	from /home/circleci/creditspring/vendor/bundle/ruby/2.4.0/gems/selenium-webdriver-3.12.0/lib/selenium/webdriver/remote/bridge.rb:164:in `execute'

Any suggestion on how to proceed?
Thank you for your help


#2

Any ideas? thank you for your help


#3

I am not sure if this is related to your problem, but this section here looks odd to me:

# Install gems with cache support
- type: cache-restore
  name: Restore bundle cache
  key: frontoffice-{{ checksum "Gemfile.lock" }}
- run:
    name: Install gems
    command: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
- type: cache-save
  name: Store bundle cache
  key: frontoffice-{{ checksum "Gemfile.lock" }}
  paths:
    - vendor/bundle

Shouldn’t those type keys be run keys?


#4

that configuration piece I found it here https://robots.thoughtbot.com/circleci-2-rails


#5

just to be sure I did run

circleci config validate -c circle.yml

and seems to be ok with it


#6

You might need run with Xvfb for selenium test something like this

  • run:
    name: Run tests
    command: xvfb-run bundle exec rspec --no-color -r rspec_junit_formatter --format RspecJunitFormatter -o $CIRCLE_TEST_REPORTS/rspec/junit.xml

Dont forget to install xvfb before this step


#7

My bad, not run for everything - type: cache-save should use a save_cache: key, and ditto for type: cache-restore. Maybe your way also works, but it does not match the docs.


#8

thank you, will try


#9

thank you, will amend to stay closer to the docs


#10

It was a very long journey, but I managed to have it working


#11

thank you to all the people who helped here


#12

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.