2

我正在尝试配置一个 Rails 应用程序以在 CircleCI 2.0 上进行测试(它在 v1.0 上运行良好)。

我已经使用以下 Docker 映像设置了一个配置文件(我第一次使用 Docker,所以不确定这是否正确):

build:
  docker:
    - image: circleci/ruby:2.4-node
      environment:
        SELENIUM_DRIVER_URL: http://localhost:4444/wd/hub
    - image: circleci/postgres:10.2
        environment:
          POSTGRES_USER: user
          POSTGRES_DB: datatbase
          POSTGRES_PASSWORD: ""
    - image: selenium/standalone-chrome:3.5.3

一切正常,所有测试都通过了,除了一个!

Failure/Error: attach_file 'file', File.join(Rails.root, 'spec', 'support', 'images', 'test_image.jpg'), visible: false
     Selenium::WebDriver::Error::ExpectedError:
       invalid argument: File not found : /home/circleci/project/spec/support/images/test_image.jpg

test_image.jpg确实存在。它被其他所有成功通过的非 JS 规范使用。

这个失败的规范是唯一一个测试 javascript 的规范,因此是通过 selenium/chrome 运行的。

从测试输出来看,selenium 似乎在寻找home/circleci/project,而不是 Rails 根文件夹。

如何配置以确保该规范在该文件的正确根目录中查找?

4

2 回答 2

1

我花了很长时间才弄清楚这一点。我对 Docker 还很陌生,在很多地方,CircleCI 文档让我感觉一头雾水。

如果这对遇到此问题的任何人有用,我image: selenium/standalone-chrome:3.5.3从我的配置文件中删除,而是使用包含所有内容的 Ruby 图像circleci/ruby:2.4-node-bowsers

build:
  docker:
    - image: circleci/ruby:2.4-node-bowsers
      environment:
        RAILS_ENV: test
    - image: circleci/postgres:10.2
        environment:
          POSTGRES_USER: user
          POSTGRES_DB: datatbase
          POSTGRES_PASSWORD: ""

问题解决了!

于 2018-03-06T06:51:58.460 回答
1

我正在详细说明 OP 提出的解决方案,因为我需要将此配置添加到我的 circleci config.yml 文件中,以使 Capybara 与 Selenium 一起正常工作:

  - run:
      name: Download Selenium
      command: |
        curl -O http://selenium-release.storage.googleapis.com/3.5/selenium-server-standalone-3.5.3.jar
  - run:
      name: Start Selenium
      command: |
        java -jar selenium-server-standalone-3.5.3.jar -log selenium.log
      background: true

我不会向 OP 解决方案添加评论,因为代码不会正确显示。

于 2018-11-19T16:05:31.483 回答