Skip to content

Commit

Permalink
Use GitHub Actions for CI (teamcapybara#2612)
Browse files Browse the repository at this point in the history
* Use GitHub Actions for CI

This aims to replace the existing Travis CI jobs with GitHub Actions.
Because the Travis CI jobs are a bit outdated, there is no one-to-one
correspondence.
  • Loading branch information
mvz committed Jan 5, 2023
1 parent 631f3ea commit 172daf5
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 14 deletions.
153 changes: 153 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# This workflow will download a prebuilt Ruby version, install dependencies and
# run tests with Rake
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby

name: Build

"on": push

env:
CUCUMBER_PUBLISH_QUIET: true
RUBYOPTS: "--disable-did-you-mean"
NOKOGIRI_USE_SYSTEM_LIBRARIES: true
JAVA_OPTS: "-Djava.security.egd=file:/dev/urandom"
WD_CACHE_TIME: 0

jobs:
rack_smoke:
runs-on: ubuntu-latest

env:
HTML5_PARSING: true
steps:
- uses: actions/checkout@v3

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.0"
bundler-cache: true
- name: Run rack_smoke
run: bundle exec rake rack_smoke

headless:
runs-on: ubuntu-latest

env:
HEADLESS: true

strategy:
# Ensure all jobs are run to completion
fail-fast: false
matrix:
ruby: ["3.0"]
task: ["spec_chrome", "spec_firefox", "cucumber"]

steps:
- uses: actions/checkout@v3

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run tests
run: bundle exec rake ${{ matrix.task }}

headless_base_versions:
runs-on: ubuntu-latest

env:
HEADLESS: true
BUNDLE_GEMFILE: gemfiles/Gemfile.base-versions

strategy:
# Ensure all jobs are run to completion
fail-fast: false
matrix:
ruby: ["2.7.0"]
task: ["spec_chrome", "spec_firefox", "cucumber"]

steps:
- uses: actions/checkout@v3
- name: Install non-ruby dependencies
run: |
sudo apt-get update
sudo apt-get install libxslt-dev
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run tests
run: bundle exec rake ${{ matrix.task }}

remote_chrome:
runs-on: ubuntu-latest

strategy:
matrix:
ruby: ["2.7"]

steps:
- uses: actions/checkout@v3

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run remote Chrome
run: docker-compose up -d selenium_chrome
- name: Run specs
run: bundle exec rake spec_chrome_remote
- name: Run cukes
run: bundle exec rake cucumber

remote_firefox:
runs-on: ubuntu-latest

strategy:
matrix:
ruby: ["3.0"]

steps:
- uses: actions/checkout@v3

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run remote Firefox
run: docker-compose up -d selenium_firefox
- name: Run specs
run: bundle exec rake spec_firefox_remote
- name: Run cukes
run: bundle exec rake cucumber

non_headless:
runs-on: ubuntu-latest

strategy:
# Ensure all jobs are run to completion
fail-fast: false
matrix:
ruby: ["3.0"]
task: ["spec_chrome", "spec_firefox", "cucumber"]

steps:
- uses: actions/checkout@v3
- name: Install non-ruby dependencies
run: |
sudo apt-get update
sudo apt-get install xvfb fluxbox
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run tests inside a window manager
run: xvfb-run sh -c "fluxbox & bundle exec rake ${{ matrix.task }}; killall fluxbox"
2 changes: 1 addition & 1 deletion spec/sauce_spec_chrome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

Capybara::Selenium::Driver.new(app,
browser: :remote, url: url,
desired_capabilities: capabilities,
capabilities: capabilities,
options: Selenium::WebDriver::Chrome::Options.new(args: ['']))
end

Expand Down
5 changes: 1 addition & 4 deletions spec/selenium_spec_chrome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ module TestSessions
pending "Selenium doesn't currently support getting visible text for shadow root elements"
when /Capybara::Session selenium_chrome node #shadow_root/
skip 'Not supported with this Selenium version' if selenium_lt?('4.1', @session)
skip 'Not supported with this chromedriver version' if chromedriver_lt?('96.0', @session)
end
end

Expand Down Expand Up @@ -203,8 +204,4 @@ module TestSessions
end.not_to raise_error
end
end

def chromedriver_version
Gem::Version.new(session.driver.browser.capabilities['chrome']['chromedriverVersion'].split[0])
end
end
11 changes: 5 additions & 6 deletions spec/selenium_spec_chrome_remote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def selenium_gte?(version)

Capybara::Selenium::Driver.new app,
browser: :remote,
desired_capabilities: :chrome,
capabilities: :chrome,
options: browser_options,
url: url
end
Expand All @@ -62,8 +62,11 @@ module TestSessions
'Capybara::Session selenium_chrome_remote #attach_file with multipart form should fire change once for each set of files uploaded',
'Capybara::Session selenium_chrome_remote #attach_file with multipart form should fire change once when uploading multiple files from empty'
pending "Selenium with Remote Chrome doesn't support multiple file upload" unless selenium_gte?(3.14)
when /Capybara::Session selenium_chrome node #shadow_root should get visible text/
when /Capybara::Session selenium_chrome_remote node #shadow_root should get visible text/
pending "Selenium doesn't currently support getting visible text for shadow root elements"
when /Capybara::Session selenium_chrome_remote node #shadow_root/
skip 'Not supported with this Selenium version' if selenium_lt?('4.1', @session)
skip 'Not supported with this chromedriver version' if chromedriver_lt?('96.0', @session)
end
end

Expand Down Expand Up @@ -96,8 +99,4 @@ module TestSessions
end.not_to raise_error
end
end

def chromedriver_version
Gem::Version.new(session.driver.browser.capabilities['chrome']['chromedriverVersion'].split[0])
end
end
4 changes: 3 additions & 1 deletion spec/selenium_spec_firefox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,16 @@ module TestSessions
'Capybara::Session selenium node #shadow_root should find nested shadow roots',
'Capybara::Session selenium node #shadow_root should click on elements',
'Capybara::Session selenium node #shadow_root should use convenience methods once moved to a descendant of the shadow root',
'Capybara::Session selenium node #shadow_root should produce error messages when failing',
'Capybara::Session with firefox with selenium driver #evaluate_script returns a shadow root'
pending "Firefox doesn't yet have full W3C shadow root support"
when 'Capybara::Session selenium #fill_in should handle carriage returns with line feeds in a textarea correctly'
pending 'Not sure what firefox is doing here'
when /Capybara::Session selenium_chrome node #shadow_root should get visible text/
when /Capybara::Session selenium node #shadow_root should get visible text/
pending "Selenium doesn't currently support getting visible text for shadow root elements"
when /Capybara::Session selenium node #shadow_root/
skip 'Not supported with this Selenium version' if selenium_lt?('4.1', @session)
skip 'Not supported with this geckodriver version' if geckodriver_lt?('0.31.0', @session)
end
end

Expand Down
16 changes: 14 additions & 2 deletions spec/selenium_spec_firefox_remote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def ensure_selenium_running!

Capybara::Selenium::Driver.new app,
browser: :remote,
desired_capabilities: :firefox,
capabilities: :firefox,
options: browser_options,
url: url
end
Expand All @@ -65,8 +65,20 @@ module TestSessions
when /#accept_confirm should work with nested modals$/
# skip because this is timing based and hence flaky when set to pending
skip 'Broken in FF 63 - https://bugzilla.mozilla.org/show_bug.cgi?id=1487358' if firefox_gte?(63, @session)
when /Capybara::Session selenium_chrome node #shadow_root should get visible text/
when 'Capybara::Session selenium_firefox_remote #fill_in should handle carriage returns with line feeds in a textarea correctly'
pending 'Not sure what firefox is doing here'
when 'Capybara::Session selenium_firefox_remote node #shadow_root should find elements inside the shadow dom using CSS',
'Capybara::Session selenium_firefox_remote node #shadow_root should find nested shadow roots',
'Capybara::Session selenium_firefox_remote node #shadow_root should click on elements',
'Capybara::Session selenium_firefox_remote node #shadow_root should use convenience methods once moved to a descendant of the shadow root',
'Capybara::Session selenium_firefox_remote node #shadow_root should produce error messages when failing',
'Capybara::Session with firefox with selenium driver #evaluate_script returns a shadow root'
pending "Firefox doesn't yet have full W3C shadow root support"
when /Capybara::Session selenium_firefox_remote node #shadow_root should get visible text/
pending "Selenium doesn't currently support getting visible text for shadow root elements"
when /Capybara::Session selenium_firefox_remote node #shadow_root/
skip 'Not supported with this Selenium version' if selenium_lt?('4.1', @session)
skip 'Not supported with this geckodriver version' if geckodriver_lt?('0.31.0', @session)
end
end

Expand Down
24 changes: 24 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ def firefox_gte?(version, session)
firefox?(session) && (session.driver.browser.capabilities[:browser_version].to_f >= version)
end

def geckodriver_version(session)
Gem::Version.new(session.driver.browser.capabilities['moz:geckodriverVersion'])
end

def geckodriver_gte?(version, session)
firefox?(session) && geckodriver_version(session) >= Gem::Version.new(version)
end

def geckodriver_lt?(version, session)
firefox?(session) && geckodriver_version(session) < Gem::Version.new(version)
end

def chrome?(session)
browser_name(session) == :chrome
end
Expand All @@ -45,6 +57,18 @@ def chrome_gte?(version, session)
chrome?(session) && (chrome_version(session) >= version)
end

def chromedriver_version(session)
Gem::Version.new(session.driver.browser.capabilities['chrome']['chromedriverVersion'].split[0])
end

def chromedriver_gte?(version, session)
chrome?(session) && chromedriver_version(session) >= Gem::Version.new(version)
end

def chromedriver_lt?(version, session)
chrome?(session) && chromedriver_version(session) < Gem::Version.new(version)
end

def selenium?(session)
session.driver.is_a? Capybara::Selenium::Driver
end
Expand Down

0 comments on commit 172daf5

Please sign in to comment.