ferrum-har 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -12
- data/lib/ferrum/har/options_extension.rb +20 -0
- data/lib/ferrum/har/page_extension.rb +2 -1
- data/lib/ferrum/har/version.rb +1 -1
- data/lib/ferrum/har.rb +5 -9
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d8d40ce71b743bf429c007041d4e1df81c0cf82b9765d8cf886249abf882543
|
4
|
+
data.tar.gz: 33c293040e516c1e28fc1ad31c95a8c6e43ed9509b2b773644efcfe0eca74d2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fa0a91fefc4e7a6c14b176257521e9c02941d420e6ad64e0e5681e1efd3b6121b97c33d685338176a0c8c2381213f994f6989fb92ae55f8e44ad68d99bffe4d
|
7
|
+
data.tar.gz: 2e93582b28d0c0ceb59638f3e92c0e3ef74178a27ba6d20d1a08b5578d55e091fefc709d14557abe07824cd778c05d8a97b278d79fd4ab9e62ac763842477f05
|
data/README.md
CHANGED
@@ -4,9 +4,10 @@ ferrum-har
|
|
4
4
|
[![Gem Version](https://img.shields.io/gem/v/ferrum-har?color=green)](https://img.shields.io/gem/v/ferrum-har?color=green)
|
5
5
|
|
6
6
|
[ferrum-har](https://github.com/hlascelles/ferrum-har) is a gem that adds the ability to capture
|
7
|
-
HAR files while running tests
|
7
|
+
[HAR](https://en.wikipedia.org/wiki/HAR_(file_format)) files while running tests
|
8
|
+
using [ferrum](https://github.com/rubycdp/ferrum).
|
8
9
|
|
9
|
-
|
10
|
+
## Installation
|
10
11
|
|
11
12
|
Add ferrum-har to your Gemfile and `bundle install`:
|
12
13
|
|
@@ -14,18 +15,16 @@ Add ferrum-har to your Gemfile and `bundle install`:
|
|
14
15
|
gem "ferrum-har"
|
15
16
|
```
|
16
17
|
|
17
|
-
|
18
|
+
## Usage
|
18
19
|
|
19
20
|
Use [ferrum](https://github.com/rubycdp/ferrum) as normal and call the `har` method on
|
20
|
-
the `page` (or `browser`) object.
|
21
|
-
by using the `Ferrum::Har::REQUIRED_BROWSER_OPTIONS` constant.
|
21
|
+
the `page` (or `browser`) object. Chrome must be used as the browser engine.
|
22
22
|
|
23
|
-
Note, the devtools window in Chrome will be opened
|
23
|
+
Note, the devtools window in Chrome will be opened by ferrum-har for the duration of the ferrum
|
24
|
+
test run. This is mandatory to obtain the HAR from Chrome.
|
24
25
|
|
25
26
|
```ruby
|
26
|
-
browser = Ferrum::Browser.new
|
27
|
-
browser_options: Ferrum::Har::REQUIRED_BROWSER_OPTIONS,
|
28
|
-
)
|
27
|
+
browser = Ferrum::Browser.new
|
29
28
|
page = browser.create_page
|
30
29
|
page.go_to("https://www.bbc.co.uk")
|
31
30
|
|
@@ -33,7 +32,7 @@ page.go_to("https://www.bbc.co.uk")
|
|
33
32
|
puts page.har
|
34
33
|
```
|
35
34
|
|
36
|
-
|
35
|
+
## How it works
|
37
36
|
|
38
37
|
Creating a HAR file from [ferrum](https://github.com/rubycdp/ferrum) network objects is complex and
|
39
38
|
potentially incompatible with the HAR generated
|
@@ -51,12 +50,21 @@ One ramification of this is that the Chrome devtools must be open for the extens
|
|
51
50
|
|
52
51
|
To get the extension to be loaded we must pass some switches to the Chrome process via ferrum,
|
53
52
|
specifically the `--auto-open-devtools-for-tabs` and `--load-extension` switches. This is done
|
54
|
-
by
|
53
|
+
by ferrum-har automatically.
|
55
54
|
|
56
55
|
For further reading, a full list of Chrome switches can be found
|
57
56
|
[here](https://peter.sh/experiments/chromium-command-line-switches/).
|
58
57
|
|
59
|
-
|
58
|
+
## Upgrading
|
59
|
+
|
60
|
+
`ferrum-har` uses [semantic versioning](https://semver.org/), so major version changes will usually
|
61
|
+
require additional actions to be taken upgrading from one major version to another.
|
62
|
+
|
63
|
+
## Changelog
|
64
|
+
|
65
|
+
A full changelog can be found here: [CHANGELOG.md](https://github.com/hlascelles/ferrum-har/blob/master/CHANGELOG.md)
|
66
|
+
|
67
|
+
## Further work
|
60
68
|
|
61
69
|
Some ideas for improvements.
|
62
70
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This module is prepended to Ferrum::Browser::Options::Chrome to alter the default options so they
|
4
|
+
# work with the ferrum-har gem.
|
5
|
+
module Ferrum
|
6
|
+
module Har
|
7
|
+
module OptionsExtension
|
8
|
+
def merge_default(flags, options)
|
9
|
+
super
|
10
|
+
# We have to remove the "disable-extensions" option from the default browser extension
|
11
|
+
# list because the ferrum-har gem requires an (internal) extension to work.
|
12
|
+
.except("disable-extensions")
|
13
|
+
.merge(
|
14
|
+
"auto-open-devtools-for-tabs" => nil, # Chrome devtools must be open to invoke getHAR
|
15
|
+
"load-extension" => "#{Ferrum::Har::GEM_DIR}/extension", # Extension that gets the HAR
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -14,7 +14,8 @@ module Ferrum
|
|
14
14
|
execute("document.ferrumHarRequested = true;")
|
15
15
|
base64_encoded_har = Ferrum::Utils::Attempt.with_retry(
|
16
16
|
errors: [HarNotReadyError],
|
17
|
-
|
17
|
+
# 10 seconds
|
18
|
+
max: 20,
|
18
19
|
wait: 0.5
|
19
20
|
) do
|
20
21
|
found = evaluate("document.ferrumHar;")
|
data/lib/ferrum/har/version.rb
CHANGED
data/lib/ferrum/har.rb
CHANGED
@@ -1,23 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "ferrum"
|
4
|
+
require "ferrum/browser/options/chrome"
|
4
5
|
require "ferrum/har/version"
|
5
6
|
require "ferrum/har/page_extension"
|
7
|
+
require "ferrum/har/options_extension"
|
6
8
|
|
7
9
|
module Ferrum
|
8
10
|
module Har
|
9
11
|
GEM_DIR = File.expand_path("../..", __dir__)
|
10
|
-
REQUIRED_BROWSER_OPTIONS = {
|
11
|
-
"auto-open-devtools-for-tabs" => nil, # The chrome devtools must be open to invoke getHAR
|
12
|
-
"load-extension" => "#{Ferrum::Har::GEM_DIR}/extension", # The extension that gets the HAR
|
13
|
-
}.freeze
|
14
12
|
end
|
15
13
|
end
|
16
14
|
|
17
|
-
# We have to remove the "disable-extensions" option from the default browser extension list because
|
18
|
-
# the ferrum-har gem requires an (internal) extension to work.
|
19
|
-
Ferrum::Browser::Options::Chrome::DEFAULT_OPTIONS =
|
20
|
-
Ferrum::Browser::Options::Chrome::DEFAULT_OPTIONS.except("disable-extensions")
|
21
|
-
|
22
15
|
# Add the #har method to Ferrum::Page
|
23
16
|
Ferrum::Page.prepend(Ferrum::Har::PageExtension)
|
17
|
+
|
18
|
+
# Add the #merge_default method to Ferrum::Browser::Options::Chrome
|
19
|
+
Ferrum::Browser::Options::Chrome.prepend(Ferrum::Har::OptionsExtension)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ferrum-har
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harry Lascelles
|
@@ -11,7 +11,7 @@ cert_chain: []
|
|
11
11
|
date: 2024-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: base64
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: ferrum
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -47,6 +47,7 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- README.md
|
49
49
|
- lib/ferrum/har.rb
|
50
|
+
- lib/ferrum/har/options_extension.rb
|
50
51
|
- lib/ferrum/har/page_extension.rb
|
51
52
|
- lib/ferrum/har/version.rb
|
52
53
|
homepage: https://github.com/hlascelles/ferrum-har
|