Skip to content

Commit bcf48d1

Browse files
committed
[rb] Support remote debugging via debug gem
1 parent 0dbec9d commit bcf48d1

File tree

6 files changed

+44
-8
lines changed

6 files changed

+44
-8
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,16 @@ To run with a specific version of Ruby you can change the version in `rb/ruby_ve
268268
echo 'RUBY_VERSION = "<X.Y.Z>"' > rb/ruby_version.bzl
269269
```
270270

271+
If you want to debug code in tests, you can do it via [`debug`](https://github.com/ruby/debug) gem:
272+
273+
1. Add `binding.break` to the code where you want the debugger to start.
274+
2. Run `bazel test --test_output streamed <test>`. Streaming output is not required, but will clearly say when debugger starts.
275+
3. When debugger starts, run the following in a separate terminal to connect to debugger:
276+
277+
```sh
278+
bazel-selenium/external/bundle/bin/rdbg -A
279+
```
280+
271281
If you want to use RubyMine for development, a bit of extra configuration is necessary to let the IDE know about Bazel toolchain and artifacts:
272282

273283
1. Run `bazel build @bundle//:bundle //rb:selenium-devtools //rb:selenium-webdriver` before configuring IDE.

rb/Gemfile.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@ GEM
1717
coderay (1.1.3)
1818
crack (0.4.5)
1919
rexml
20+
debug (1.7.2)
21+
irb (>= 1.5.0)
22+
reline (>= 0.3.1)
2023
diff-lcs (1.5.0)
2124
ffi (1.15.5-java)
2225
hashdiff (1.0.1)
26+
io-console (0.6.0)
27+
io-console (0.6.0-java)
28+
irb (1.6.4)
29+
reline (>= 0.3.0)
2330
json (2.6.3)
2431
json (2.6.3-java)
2532
method_source (1.0.0)
@@ -37,6 +44,8 @@ GEM
3744
rack (2.2.5)
3845
rainbow (3.1.1)
3946
regexp_parser (2.6.1)
47+
reline (0.3.3)
48+
io-console (~> 0.5)
4049
rexml (3.2.5)
4150
rspec (3.12.0)
4251
rspec-core (~> 3.12.0)
@@ -89,6 +98,7 @@ PLATFORMS
8998
x64-mingw32
9099

91100
DEPENDENCIES
101+
debug (~> 1.7)
92102
pry (~> 0.14)
93103
rack (~> 2.0)
94104
rspec (~> 3.0)

rb/selenium-webdriver.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Gem::Specification.new do |s|
5353
s.add_runtime_dependency 'rubyzip', ['>= 1.2.2', '< 3.0']
5454
s.add_runtime_dependency 'websocket', ['~> 1.0']
5555

56+
s.add_development_dependency 'debug', ['~> 1.7']
5657
s.add_development_dependency 'pry', ['~> 0.14']
5758
s.add_development_dependency 'rack', ['~> 2.0']
5859
s.add_development_dependency 'rspec', ['~> 3.0']

rb/spec/integration/selenium/webdriver/spec_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
# specific language governing permissions and limitations
1818
# under the License.
1919

20+
require 'debug/session'
21+
DEBUGGER__::CONFIG[:fork_mode] = :parent
22+
DEBUGGER__.open(nonstop: true)
23+
2024
require 'rubygems'
2125
require 'time'
2226
require 'rspec'

rb/spec/unit/selenium/webdriver/common/selenium_manager_spec.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,33 @@
2222
module Selenium
2323
module WebDriver
2424
describe SeleniumManager do
25-
describe 'self.binary' do
25+
describe '.binary' do
26+
def stub_binary(binary)
27+
allow(File).to receive(:exist?).with(a_string_ending_with(binary)).and_return(true)
28+
allow(File).to receive(:executable?).with(a_string_ending_with(binary)).and_return(true)
29+
end
30+
2631
before do
2732
described_class.instance_variable_set(:@binary, nil)
2833
end
2934

3035
it 'detects Windows' do
31-
allow(File).to receive(:exist?).and_return(true)
32-
allow(File).to receive(:executable?).and_return(true)
36+
stub_binary('/windows/selenium-manager.exe')
3337
allow(Platform).to receive(:windows?).and_return(true)
3438

3539
expect(described_class.send(:binary)).to match(%r{/windows/selenium-manager\.exe$})
3640
end
3741

3842
it 'detects Mac' do
39-
allow(File).to receive(:exist?).and_return(true)
40-
allow(File).to receive(:executable?).and_return(true)
43+
stub_binary('/macos/selenium-manager')
4144
allow(Platform).to receive(:windows?).and_return(false)
4245
allow(Platform).to receive(:mac?).and_return(true)
4346

4447
expect(described_class.send(:binary)).to match(%r{/macos/selenium-manager$})
4548
end
4649

4750
it 'detects Linux' do
48-
allow(File).to receive(:exist?).and_return(true)
49-
allow(File).to receive(:executable?).and_return(true)
51+
stub_binary('/linux/selenium-manager')
5052
allow(Platform).to receive(:windows?).and_return(false)
5153
allow(Platform).to receive(:mac?).and_return(false)
5254
allow(Platform).to receive(:linux?).and_return(true)
@@ -55,7 +57,7 @@ module WebDriver
5557
end
5658

5759
it 'errors if cannot find' do
58-
allow(File).to receive(:exist?).and_return(false)
60+
allow(File).to receive(:exist?).with(a_string_including('selenium-manager')).and_return(false)
5961

6062
expect {
6163
described_class.send(:binary)

rb/spec/unit/selenium/webdriver/spec_helper.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
# specific language governing permissions and limitations
1818
# under the License.
1919

20+
require 'debug/session'
21+
DEBUGGER__::CONFIG[:fork_mode] = :parent
22+
DEBUGGER__.open(nonstop: true)
23+
2024
require 'rubygems'
2125
require 'time'
2226
require 'rspec'
@@ -48,4 +52,9 @@ def with_env(hash)
4852
c.include Selenium::WebDriver::UnitSpecHelper
4953

5054
c.filter_run focus: true if ENV['focus']
55+
56+
c.before do
57+
# https://github.com/ruby/debug/issues/797
58+
allow(File).to receive(:exist?).and_call_original
59+
end
5160
end

0 commit comments

Comments
 (0)