Skip to content

Commit b26e56d

Browse files
authored
Merge pull request #129 from rubycdp/circleci
Switch to CircleCI
2 parents 4d3a07f + 8034bd4 commit b26e56d

File tree

5 files changed

+74
-27
lines changed

5 files changed

+74
-27
lines changed

.circleci/config.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
version: 2.1
2+
3+
orbs:
4+
ruby: circleci/ruby@1.0.7
5+
6+
executors:
7+
ruby:
8+
docker:
9+
- image: circleci/ruby:buster-node-browsers
10+
11+
commands:
12+
create_artifact_folders:
13+
steps:
14+
- run:
15+
name: Create artifacts folders
16+
command: mkdir -p /home/circleci/project/tmp/{screenshots,logs}
17+
store_screenshots_and_logs:
18+
steps:
19+
- store_artifacts:
20+
path: /home/circleci/project/tmp/screenshots
21+
destination: screenshots
22+
- store_artifacts:
23+
path: /home/circleci/project/tmp/logs
24+
destination: logs
25+
26+
jobs:
27+
test:
28+
parameters:
29+
ruby-version:
30+
type: string
31+
gemfile:
32+
type: string
33+
executor: ruby
34+
steps:
35+
- checkout
36+
- create_artifact_folders
37+
- ruby/install:
38+
version: << parameters.ruby-version >>
39+
- run: bundle install
40+
- run: bundle exec rake
41+
- store_screenshots_and_logs
42+
43+
workflows:
44+
build:
45+
jobs:
46+
- test:
47+
matrix:
48+
parameters:
49+
ruby-version: ["2.5", "2.6", "2.7"]
50+
gemfile: ["gemfiles/capybara-2.x.gemfile", "gemfiles/capybara-3.x.gemfile", "gemfiles/websocket-driver-6.x.gemfile", "gemfiles/ferrum-master.gemfile"]

.rspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
--color
2-
--format=doc
32
--fail-fast
3+
--format=doc
4+
--require spec_helper

.travis.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Cuprite - Headless Chrome driver for Capybara
22

3-
[![Build Status](https://travis-ci.org/rubycdp/cuprite.svg?branch=master)](https://travis-ci.org/rubycdp/cuprite)
3+
[![Build Status](https://circleci.com/gh/rubycdp/cuprite.svg?style=shield)](https://circleci.com/gh/rubycdp/cuprite)
44

55
Cuprite is a pure Ruby driver (read as _no_ Selenium/WebDriver/ChromeDriver
66
dependency) for [Capybara](https://github.com/teamcapybara/capybara). It allows

spec/spec_helper.rb

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
$:.unshift(CUPRITE_ROOT + "/lib")
55

66
require "bundler/setup"
7-
87
require "rspec"
8+
99
require "capybara/spec/spec_helper"
1010
require "capybara/cuprite"
1111

@@ -15,10 +15,11 @@
1515
Capybara.register_driver(:cuprite) do |app|
1616
options = {}
1717
options.merge!(inspector: true) if ENV["INSPECTOR"]
18-
options.merge!(logger: StringIO.new) if ENV["TRAVIS"]
18+
options.merge!(logger: StringIO.new) if ENV["CI"]
1919
driver = Capybara::Cuprite::Driver.new(app, options)
2020
process = driver.browser.process
2121

22+
puts ""
2223
puts "Browser: #{process.browser_version}"
2324
puts "Protocol: #{process.protocol_version}"
2425
puts "V8: #{process.v8_version}"
@@ -80,17 +81,18 @@ module TestSessions
8081
end
8182

8283
config.around do |example|
83-
if ENV["TRAVIS"]
84+
if ENV["CI"]
8485
session = @session || TestSessions::Cuprite
8586
session.driver.browser.logger.truncate(0)
8687
session.driver.browser.logger.rewind
8788
end
8889

8990
example.run
9091

91-
if ENV["TRAVIS"] && example.exception
92+
if ENV["CI"] && example.exception
9293
session = @session || TestSessions::Cuprite
9394
raise session.driver.browser.logger.string
95+
save_exception_aftifacts(session.driver.browser, example.metadata)
9496
end
9597
end
9698

@@ -100,4 +102,19 @@ module TestSessions
100102
end
101103

102104
Capybara::SpecHelper.configure(config)
105+
106+
def save_exception_aftifacts(browser, meta)
107+
time_now = Time.now
108+
filename = File.basename(meta[:file_path])
109+
line_number = meta[:line_number]
110+
timestamp = "#{time_now.strftime('%Y-%m-%d-%H-%M-%S.')}#{'%03d' % (time_now.usec/1000).to_i}"
111+
112+
screenshot_name = "screenshot-#{filename}-#{line_number}-#{timestamp}.png"
113+
screenshot_path = "#{ENV["CIRCLE_ARTIFACTS"]}/screenshots/#{screenshot_name}"
114+
browser.screenshot(path: screenshot_path, full: true)
115+
116+
log_name = "ferrum-#{filename}-#{line_number}-#{timestamp}.txt"
117+
log_path = "#{ENV["CIRCLE_ARTIFACTS"]}/logs/#{log_name}"
118+
File.open(log_path, 'wb') { |file| file.write(FERRUM_LOGGER.string) }
119+
end
103120
end

0 commit comments

Comments
 (0)