我正在为Rails应用程序建立一个Bitbucket管道。我可以运行所有标准RSpec测试,但是集成测试收到的响应为空。使用在管道设置中安装的firefox和geckodriver。
在管道中手动安装了firefox和geckodriver并使用Xvfb设置了显示器,这解决了大多数错误,但是集成测试在运行时仍会收到空响应。我将selenium webdriver设置为调试模式,以便更好地记录日志。
管道代码:
image:
name: atlassian/pipelines-awscli
definitions:
services:
postgres:
image: postgres
environment:
POSTGRES_DB: pipelines
POSTGRES_USER: test_user
POSTGRES_PASSWORD: test_user_password
runTests: &runTests
image: ruby:2.5.3
name: Run rspec tests in the ruby app
services:
- postgres
script:
- export DATABASE_URL=postgresql://test_user:test_user_password@localhost/pipelines
- apt-get update
- apt-get --assume-yes install nodejs
- apt-get install -y wget xvfb libgtk-3-0 libdbus-glib-1-2
- mkdir /usr/bin/firefox
- wget -q --continue --output-document /usr/bin/firefox/firefox.tar.bz2 "https://ftp.mozilla.org/pub/firefox/releases/69.0/linux-x86_64/en-US/firefox-69.0.tar.bz2"
- tar -xaf "/usr/bin/firefox/firefox.tar.bz2" --strip-components=1 --directory "/usr/bin/firefox"
# Prepend firefox dir to PATH
- export PATH=~/usr/bin/firefox:$PATH
- wget -q --continue --output-document /tmp/geckodriver.tar.gz "https://github.com/mozilla/geckodriver/releases/download/v0.25.0/geckodriver-v0.25.0-linux64.tar.gz"
- tar -C /opt -zxf /tmp/geckodriver.tar.gz
- rm /tmp/geckodriver.tar.gz
- mv /opt/geckodriver /opt/geckodriver-v0.25.0
- ln -fs /opt/geckodriver-v0.25.0 /usr/bin/geckodriver
- ln -fs /opt/geckodriver-v0.25.0 /usr/bin/wires
- chmod 755 /opt/geckodriver-v0.25.0
- export PATH=~/opt/geckodriver-v0.25.0:$PATH
- Xvfb :99 -ac &
- export DISPLAY=:99
- bundle install
- bundle exec rspec
buildImage: &buildImage
name: Build and push docker image to ECR
services:
- docker
script:
- export DOCKER_URI=$DEV_AWS_REGISTERY_URL:$DEV_VERSION
- eval $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
- docker build -t $DOCKER_URI .
- docker push $DOCKER_URI
pipelines:
branches:
develop:
- step: *runTests
- step: *buildImage
硒管道设置spec_helper.rb:
if ENV['PIPELINE'] == 'true'
Selenium::WebDriver::Firefox::Binary.path = "/usr/bin/firefox/firefox"
options = Selenium::WebDriver::Firefox::Options.new(args: ['-headless'])
Selenium::WebDriver.for(:firefox, options: options)
Selenium::WebDriver.logger.level = :debug
end
预期的管道可以运行测试,但会收到以下错误消息。看起来端口值不同:
Progress: |==============================================Capybara starting Puma...
* Version 3.12.0 , codename: Llamas in Pajamas
* Min threads: 0, max threads: 4
* Listening on tcp://127.0.0.1:45187
2019-09-24 17:50:00 DEBUG Selenium Executing Process ["/usr/bin/geckodriver", "--binary=/usr/bin/firefox/firefox", "--port=4445"]
2019-09-24 17:50:00 DEBUG Selenium polling for socket on ["127.0.0.1", 4445]
2019-09-24 17:50:00 INFO Selenium Skipping handshake as we know it is W3C.
2019-09-24 17:50:00 INFO Selenium -> POST session
2019-09-24 17:50:00 INFO Selenium >>> http://127.0.0.1:4445/session | {"desiredCapabilities":{"browserName":"firefox","marionette":true,"timeouts":{},"moz:firefoxOptions":{}},"capabilities":{"firstMatch":[{"browserName":"firefox","timeouts":{},"moz:firefoxOptions":{}}]}}
2019-09-24 17:50:00 DEBUG Selenium > {"Accept"=>"application/json", "Content-Type"=>"application/json; charset=UTF-8", "User-Agent"=>"selenium/3.141.0 (ruby linux)", "Content-Length"=>"201"}
1569347400897 mozrunner::runner INFO Running command: "/usr/bin/firefox/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofileOHlkJt"
1569347401430 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1569347401430 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry
1569347401430 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1569347401430 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader*
1569347403039 Marionette INFO Listening on port 39251
2019-09-24 17:50:03 INFO Selenium <- {"value":{"sessionId":"c2aa808a-eb01-4cae-982c-994f55f0ef53","capabilities":{"acceptInsecureCerts":false,"browserName":"firefox","browserVersion":"69.0","moz:accessibilityChecks":false,"moz:buildID":"20190827005903","moz:geckodriverVersion":"0.25.0","moz:headless":false,"moz:processID":12664,"moz:profile":"/tmp/rust_mozprofileOHlkJt","moz:shutdownTimeout":60000,"moz:useNonSpecCompliantPointerOrigin":false,"moz:webdriverClick":true,"pageLoadStrategy":"normal","platformName":"linux","platformVersion":"4.19.50-coreos-r1","rotatable":false,"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify"}}}
2019-09-24 17:50:03 INFO Selenium Detected W3C dialect.
2019-09-24 17:50:03 INFO Selenium -> POST session/c2aa808a-eb01-4cae-982c-994f55f0ef53/url
2019-09-24 17:50:03 INFO Selenium >>> http://127.0.0.1:4445/session/c2aa808a-eb01-4cae-982c-994f55f0ef53/url | {"url":"http://127.0.0.1:45187/"}
2019-09-24 17:50:03 DEBUG Selenium > {"Accept"=>"application/json", "Content-Type"=>"application/json; charset=UTF-8", "User-Agent"=>"selenium/3.141.0 (ruby linux)", "Content-Length"=>"33"}
2019-09-24 17:50:03 INFO Selenium <- {"value":null}
...
Failure/Error: first(:link, 'Login').click
Capybara::ExpectationNotMet:
expected to find link "Login" at least 1 time but there were no matches
有人知道如何为集成测试配置位桶管道吗?