Skip to content

Commit 4e2a2d7

Browse files
committed
Switch to CircleCI
1 parent 59cdcc1 commit 4e2a2d7

File tree

5 files changed

+107
-38
lines changed

5 files changed

+107
-38
lines changed

.circleci/config.yml

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,50 @@
11
version: 2.1
2+
23
orbs:
34
ruby: circleci/[email protected]
45

5-
jobs:
6-
build:
6+
executors:
7+
ruby:
78
docker:
8-
- image: circleci/ruby:2.7.1-stretch-node
9-
executor: ruby/default
9+
- image: circleci/ruby:buster-node-browsers
10+
11+
commands:
12+
create_artifact_folders:
1013
steps:
11-
- checkout
1214
- run:
13-
name: Which bundler?
14-
command: bundle -v
15-
- ruby/bundle-install
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/websocket-driver-0.6.x.gemfile", "gemfiles/websocket-driver-0.7.x.gemfile"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Ferrum - high-level API to control Chrome in Ruby
22

3-
[![CircleCI](https://circleci.com/gh/rubycdp/ferrum.svg?style=svg)](https://circleci.com/gh/rubycdp/ferrum)
3+
[![CircleCI](https://circleci.com/gh/rubycdp/ferrum.svg?style=shield)](https://circleci.com/gh/rubycdp/ferrum)
44

55
<img align="right"
66
width="320" height="241"

spec/frame_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ module Ferrum
283283
browser.execute <<-JS
284284
document.body.innerHTML += "<iframe src='/ferrum/buttons' id='buttons_frame'>"
285285
JS
286+
browser.network.wait_for_idle
286287

287288
frame = browser.at_xpath("//iframe[@id='buttons_frame']").frame
288289
expect(frame.xpath("//button").size).to eq(3)
@@ -320,6 +321,7 @@ module Ferrum
320321
browser.execute <<-JS
321322
document.body.innerHTML += "<iframe src='/ferrum/buttons' id='buttons_frame'>"
322323
JS
324+
browser.network.wait_for_idle
323325

324326
frame = browser.at_xpath("//iframe[@id='buttons_frame']").frame
325327
expect(frame.at_xpath("//button[@id='click_me_123']")).not_to be_nil
@@ -357,6 +359,7 @@ module Ferrum
357359
browser.execute <<-JS
358360
document.body.innerHTML += "<iframe src='/ferrum/buttons' id='buttons_frame'>"
359361
JS
362+
browser.network.wait_for_idle
360363

361364
frame = browser.at_css("iframe#buttons_frame").frame
362365
expect(frame.css("button").size).to eq(3)
@@ -394,6 +397,7 @@ module Ferrum
394397
browser.execute <<-JS
395398
document.body.innerHTML += "<iframe src='/ferrum/buttons' id='buttons_frame'>"
396399
JS
400+
browser.network.wait_for_idle
397401

398402
frame = browser.at_css("iframe#buttons_frame").frame
399403
expect(frame.at_css("button#click_me_123")).not_to be_nil

spec/spec_helper.rb

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,7 @@
88

99
require "ferrum"
1010
require "support/server"
11-
12-
RSpec.shared_context "Global helpers" do
13-
def server
14-
Ferrum::Server.server
15-
end
16-
17-
def base_url(*args)
18-
server.base_url(*args)
19-
end
20-
21-
def browser
22-
@browser
23-
end
24-
25-
def with_external_browser(host: "127.0.0.1", port: 32001)
26-
options = { host: host, port: port, window_size: [1400, 1400], headless: true }
27-
process = Ferrum::Browser::Process.new(options)
28-
29-
begin
30-
process.start
31-
yield "http://#{host}:#{port}"
32-
ensure
33-
process.stop
34-
end
35-
end
36-
end
11+
require "support/global_helpers"
3712

3813
RSpec.configure do |config|
3914
config.include_context "Global helpers"
@@ -54,8 +29,14 @@ def with_external_browser(host: "127.0.0.1", port: 32001)
5429

5530
config.before(:all) do
5631
base_url = Ferrum::Server.server.base_url
57-
@browser = Ferrum::Browser.new(base_url: base_url,
58-
process_timeout: 5)
32+
options = { base_url: base_url, process_timeout: 5 }
33+
34+
if ENV['CI']
35+
FERRUM_LOGGER = StringIO.new
36+
options.merge!(logger: FERRUM_LOGGER)
37+
end
38+
39+
@browser = Ferrum::Browser.new(**options)
5940
end
6041

6142
config.after(:all) do
@@ -64,9 +45,33 @@ def with_external_browser(host: "127.0.0.1", port: 32001)
6445

6546
config.before(:each) do
6647
server&.wait_for_pending_requests
48+
49+
if ENV['CI']
50+
FERRUM_LOGGER.truncate(0)
51+
FERRUM_LOGGER.rewind
52+
end
6753
end
6854

69-
config.after(:each) do
55+
config.after(:each) do |example|
56+
if ENV['CI'] && example.exception
57+
save_exception_aftifacts(browser, example.metadata)
58+
end
59+
7060
@browser.reset
7161
end
62+
63+
def save_exception_aftifacts(browser, meta)
64+
time_now = Time.now
65+
filename = File.basename(meta[:file_path])
66+
line_number = meta[:line_number]
67+
timestamp = "#{time_now.strftime('%Y-%m-%d-%H-%M-%S.')}#{'%03d' % (time_now.usec/1000).to_i}"
68+
69+
screenshot_name = "screenshot-#{filename}-#{line_number}-#{timestamp}.png"
70+
screenshot_path = "#{ENV["CIRCLE_ARTIFACTS"]}/screenshots/#{screenshot_name}"
71+
browser.screenshot(path: screenshot_path, full: true)
72+
73+
log_name = "ferrum-#{filename}-#{line_number}-#{timestamp}.txt"
74+
log_path = "#{ENV["CIRCLE_ARTIFACTS"]}/logs/#{log_name}"
75+
File.open(log_path, 'wb') { |file| file.write(FERRUM_LOGGER.string) }
76+
end
7277
end

spec/support/global_helpers.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
RSpec.shared_context "Global helpers" do
2+
def server
3+
Ferrum::Server.server
4+
end
5+
6+
def base_url(*args)
7+
server.base_url(*args)
8+
end
9+
10+
def browser
11+
@browser
12+
end
13+
14+
def with_external_browser(host: "127.0.0.1", port: 32001)
15+
options = { host: host, port: port, window_size: [1400, 1400], headless: true }
16+
process = Ferrum::Browser::Process.new(options)
17+
18+
begin
19+
process.start
20+
yield "http://#{host}:#{port}"
21+
ensure
22+
process.stop
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)