tlopo-selenium-docker 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bae1f77fc2a5526c95012e587e06871f9d76e59dbd4792b77cee859ef08f0a61
4
- data.tar.gz: 241056f63628cbc490163bcce6e3b031ea8dfcbf511ae1934160580feac5f5ec
3
+ metadata.gz: 00fa1d9a00a203e23c1ef2ff7f7452be847e3875d45f1d18b37a450d8fcb0c0c
4
+ data.tar.gz: c4cfcc2654a5e94ff19615ff9ee8c6f412814b1f1008f81ff18a68e20f773d50
5
5
  SHA512:
6
- metadata.gz: 775e76d33ac46ff3bc95213659e6ee145dbd4fde85c13068d3eeaf35df135a26beeab206ae722a7ae578ff6ce065e406185291c351ce83733a243463aa39add8
7
- data.tar.gz: 9d66b8b01064c6edc76212eacd441f8bf24ce98ac67c0e50ea96d0cbf1d26ae835ca1802b8c3f77840e62a7341abf5a86cc75f208d6e01d50553b2a2f423fc65
6
+ metadata.gz: 88c8e8f0f5f2a4ba046a778f7601634ed035d36e2d4932d97fa9d3ad163ee497392f0ff260b72fdee62f7735f373fba5e2df715e66829a72a479e1b6538d7d56
7
+ data.tar.gz: b4e66eef3e024e86e5ab010da13fdc7c90ef2b23d76ae3631232108bc3dd24d2a835a47c679ac79f0237e2b5ff8f0eedaf89d7bfcd5145a0a006acb3fecf01bd
data/README.md CHANGED
@@ -1,39 +1,100 @@
1
- # Tlopo::Selenium::Docker
1
+ # Tlopo::SeleniumDocker
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ Manages the lifecycle of a Selenium Docker container and hands you a ready-to-use
4
+ `Selenium::WebDriver`. It pulls the images, allocates free host ports (guarded by file
5
+ locks so parallel runs don't collide), creates a dedicated Docker network, starts the
6
+ browser container, and optionally records a video of the session. Everything is torn
7
+ down when the block returns.
4
8
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tlopo/selenium/docker`. To experiment with that code, run `bin/console` for an interactive prompt.
9
+ ## Requirements
10
+
11
+ - A running Docker daemon reachable by [`docker-api`](https://github.com/swipely/docker-api)
12
+ - Ruby >= 2.6.0
6
13
 
7
14
  ## Installation
8
15
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
16
+ Add the gem to your Gemfile:
17
+
18
+ ```ruby
19
+ gem "tlopo-selenium-docker"
20
+ ```
10
21
 
11
- Install the gem and add to the application's Gemfile by executing:
22
+ Then run:
12
23
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
24
+ $ bundle install
14
25
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
26
+ Or install it directly:
16
27
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
28
+ $ gem install tlopo-selenium-docker
18
29
 
19
30
  ## Usage
20
31
 
21
- TODO: Write usage instructions here
32
+ ```ruby
33
+ require "tlopo/selenium_docker"
34
+
35
+ Tlopo::SeleniumDocker.new.run do |driver|
36
+ driver.navigate.to "https://example.com"
37
+ puts driver.title
38
+ end
39
+ ```
40
+
41
+ ### Options
42
+
43
+ | Option | Default | Description |
44
+ | ------------------ | ------------------------------------------ | ---------------------------------------------------- |
45
+ | `:selenium_image` | `selenium/standalone-chrome:4.8.3` | Image used for the browser container. |
46
+ | `:video_image` | `selenium/video:ffmpeg-4.3.1-20220726` | Image used for the video recorder. |
47
+ | `:chrome_data_dir` | `nil` | Host directory mounted as the Chrome user data dir. |
48
+ | `:video_path` | `nil` | When set, records the session and copies it here. |
49
+
50
+ ### Recording a video
51
+
52
+ ```ruby
53
+ Tlopo::SeleniumDocker.new(video_path: "session.mp4").run do |driver|
54
+ driver.navigate.to "https://example.com"
55
+ end
56
+ ```
57
+
58
+ The recording is written to `session.mp4` (the `.mp4` extension is appended if omitted)
59
+ once the block completes.
22
60
 
23
61
  ## Development
24
62
 
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
63
+ After checking out the repo, run `bin/setup` to install dependencies. Then run
64
+ `rake test` to run the tests, or `bin/console` for an interactive prompt.
26
65
 
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
66
+ To install this gem onto your local machine, run `bundle exec rake install`.
28
67
 
29
- ## Contributing
68
+ ### Tests
30
69
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tlopo-selenium-docker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/tlopo-selenium-docker/blob/main/CODE_OF_CONDUCT.md).
70
+ There are two suites:
32
71
 
33
- ## License
72
+ - `rake test` — fast unit tests that do not require Docker. This is the default
73
+ task (`rake`) and what CI runs.
74
+ - `rake integration` — an end-to-end test that starts a real Selenium container
75
+ against an in-process dummy HTTP server and records the session to video. It
76
+ requires a running Docker daemon and is skipped automatically when none is
77
+ reachable.
78
+
79
+ The integration test resolves the daemon from the active Docker context (the
80
+ same one the `docker` CLI uses), so it works with Docker Desktop, Colima, and
81
+ others without extra configuration. Set `DOCKER_HOST` to override.
82
+
83
+ It uses the multi-arch `selenium/standalone-chromium` and `selenium/video`
84
+ images, so it runs natively on both amd64 and arm64 (Apple Silicon) hosts. The
85
+ recording is written to `/tmp/tlopo-selenium-docker-session.mp4`:
34
86
 
35
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
87
+ ```
88
+ $ bundle exec rake integration
89
+ $ open /tmp/tlopo-selenium-docker-session.mp4
90
+ ```
36
91
 
37
- ## Code of Conduct
92
+ ## Contributing
93
+
94
+ Bug reports and pull requests are welcome on GitHub at
95
+ https://github.com/tlopo-ruby/tlopo-selenium-docker.
96
+
97
+ ## License
38
98
 
39
- Everyone interacting in the Tlopo::Selenium::Docker project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/tlopo-selenium-docker/blob/main/CODE_OF_CONDUCT.md).
99
+ The gem is available as open source under the terms of the
100
+ [MIT License](https://opensource.org/licenses/MIT).
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tlopo
4
4
  class SeleniumDocker
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.3"
6
6
  end
7
7
  end
@@ -12,6 +12,8 @@ require "selenium-webdriver"
12
12
 
13
13
  module Tlopo
14
14
  class SeleniumDocker
15
+ class NoFreePortError < StandardError; end
16
+
15
17
  LOGGER ||= Logger.new $stderr
16
18
 
17
19
  def initialize(opts = {})
@@ -34,10 +36,9 @@ module Tlopo
34
36
  end
35
37
 
36
38
  def best_effort
37
- begin
38
- yield
39
- rescue
40
- end
39
+ yield
40
+ rescue StandardError
41
+ nil
41
42
  end
42
43
 
43
44
  def gen_short_id
@@ -90,6 +91,7 @@ module Tlopo
90
91
  rescue Errno::ECONNREFUSED
91
92
  return port
92
93
  end
94
+ raise NoFreePortError, "no free port available in range #{from}..#{to}"
93
95
  end
94
96
 
95
97
  def pull_images
@@ -188,6 +190,8 @@ module Tlopo
188
190
 
189
191
  options = Selenium::WebDriver::Chrome::Options.new
190
192
  options.add_argument("--no-first-run")
193
+ options.add_argument("--no-sandbox")
194
+ options.add_argument("--disable-dev-shm-usage")
191
195
  options.add_argument("--user-data-dir=/tmp/chrome-data-dir")
192
196
 
193
197
  @driver = Selenium::WebDriver.for :remote, url: url, capabilities: options
metadata CHANGED
@@ -1,85 +1,84 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tlopo-selenium-docker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - tlopo
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-11-04 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: tlopo-futex
13
+ name: docker-api
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: 0.1.0
18
+ version: 2.3.0
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: 0.1.0
25
+ version: 2.3.0
27
26
  - !ruby/object:Gem::Dependency
28
- name: docker-api
27
+ name: selenium-webdriver
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: 2.3.0
32
+ version: 4.25.0
34
33
  type: :runtime
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
- version: 2.3.0
39
+ version: 4.25.0
41
40
  - !ruby/object:Gem::Dependency
42
- name: selenium-webdriver
41
+ name: timeout
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - "~>"
46
45
  - !ruby/object:Gem::Version
47
- version: 4.25.0
46
+ version: 0.4.1
48
47
  type: :runtime
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
51
  - - "~>"
53
52
  - !ruby/object:Gem::Version
54
- version: 4.25.0
53
+ version: 0.4.1
55
54
  - !ruby/object:Gem::Dependency
56
- name: zlib
55
+ name: tlopo-futex
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - "~>"
60
59
  - !ruby/object:Gem::Version
61
- version: 3.1.0
60
+ version: 0.1.0
62
61
  type: :runtime
63
62
  prerelease: false
64
63
  version_requirements: !ruby/object:Gem::Requirement
65
64
  requirements:
66
65
  - - "~>"
67
66
  - !ruby/object:Gem::Version
68
- version: 3.1.0
67
+ version: 0.1.0
69
68
  - !ruby/object:Gem::Dependency
70
- name: timeout
69
+ name: zlib
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
72
  - - "~>"
74
73
  - !ruby/object:Gem::Version
75
- version: 0.4.1
74
+ version: 3.1.0
76
75
  type: :runtime
77
76
  prerelease: false
78
77
  version_requirements: !ruby/object:Gem::Requirement
79
78
  requirements:
80
79
  - - "~>"
81
80
  - !ruby/object:Gem::Version
82
- version: 0.4.1
81
+ version: 3.1.0
83
82
  description: Manges Selenium Docker container lifecycle and provides a handle to Selenium
84
83
  driver
85
84
  email:
@@ -98,7 +97,6 @@ licenses:
98
97
  - MIT
99
98
  metadata:
100
99
  homepage_uri: https://github.com/tlopo-ruby/tlopo-selenium-docker
101
- post_install_message:
102
100
  rdoc_options: []
103
101
  require_paths:
104
102
  - lib
@@ -106,15 +104,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
104
  requirements:
107
105
  - - ">="
108
106
  - !ruby/object:Gem::Version
109
- version: 2.6.0
107
+ version: 3.3.0
110
108
  required_rubygems_version: !ruby/object:Gem::Requirement
111
109
  requirements:
112
110
  - - ">="
113
111
  - !ruby/object:Gem::Version
114
112
  version: '0'
115
113
  requirements: []
116
- rubygems_version: 3.5.3
117
- signing_key:
114
+ rubygems_version: 3.6.9
118
115
  specification_version: 4
119
116
  summary: Manges Selenium Docker container lifecycle and provides a handle to Selenium
120
117
  driver