Skip to content

Commit 4b02516

Browse files
committed
create default chrome options
1 parent 1e69dc7 commit 4b02516

File tree

5 files changed

+35
-26
lines changed

5 files changed

+35
-26
lines changed

examples/ruby/spec/browsers/chrome_spec.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@
77
let(:chrome_location) { driver_finder && ENV.fetch('CHROME_BIN', nil) }
88

99
it 'basic options' do
10-
options = Selenium::WebDriver::Options.chrome
10+
options = default_chrome_options
1111
@driver = Selenium::WebDriver.for :chrome, options: options
1212
end
1313

1414
it 'add arguments' do
15-
options = Selenium::WebDriver::Options.chrome
15+
options = default_chrome_options
1616

1717
options.args << '--start-maximized'
1818

1919
@driver = Selenium::WebDriver.for :chrome, options: options
2020
end
2121

2222
it 'sets location of binary' do
23-
options = Selenium::WebDriver::Options.chrome
23+
options = default_chrome_options
2424

2525
options.binary = chrome_location
2626

2727
@driver = Selenium::WebDriver.for :chrome, options: options
2828
end
2929

3030
it 'add extensions' do
31-
extension_file_path = File.expand_path('../spec_support/extensions/webextensions-selenium-example.crx', __dir__)
32-
options = Selenium::WebDriver::Options.chrome
31+
options = default_chrome_options
3332

33+
extension_file_path = File.expand_path('../spec_support/extensions/webextensions-selenium-example.crx', __dir__)
3434
options.add_extension(extension_file_path)
3535

3636
@driver = Selenium::WebDriver.for :chrome, options: options
@@ -40,15 +40,15 @@
4040
end
4141

4242
it 'keeps browser open' do
43-
options = Selenium::WebDriver::Options.chrome
43+
options = default_chrome_options
4444

4545
options.detach = true
4646

4747
@driver = Selenium::WebDriver.for :chrome, options: options
4848
end
4949

5050
it 'excludes switches' do
51-
options = Selenium::WebDriver::Options.chrome
51+
options = default_chrome_options
5252

5353
options.exclude_switches << 'disable-popup-blocking'
5454

@@ -131,7 +131,8 @@
131131
'offline' => false,
132132
'latency' => 100,
133133
'download_throughput' => 200,
134-
'upload_throughput' => 200)
134+
'upload_throughput' => 200
135+
)
135136
end
136137

137138
it 'gets the browser logs' do
@@ -155,7 +156,8 @@
155156
end
156157

157158
def driver_finder
158-
options = Selenium::WebDriver::Options.chrome(browser_version: 'stable')
159+
options = default_chrome_options
160+
options.browser_version = 'stable'
159161
service = Selenium::WebDriver::Service.chrome
160162
finder = Selenium::WebDriver::DriverFinder.new(options, service)
161163
ENV['CHROMEDRIVER_BIN'] = finder.driver_path

examples/ruby/spec/drivers/options_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
let(:url) { 'https://www.selenium.dev/selenium/web/' }
99

1010
it 'page load strategy normal' do
11-
options = Selenium::WebDriver::Options.chrome
11+
options = default_chrome_options
1212
options.page_load_strategy = :normal
1313

1414
driver = Selenium::WebDriver.for :chrome, options: options
@@ -17,7 +17,7 @@
1717
end
1818

1919
it 'page load strategy eager' do
20-
options = Selenium::WebDriver::Options.chrome
20+
options = default_chrome_options
2121
options.page_load_strategy = :eager
2222

2323
driver = Selenium::WebDriver.for :chrome, options: options
@@ -26,7 +26,7 @@
2626
end
2727

2828
it 'page load strategy none' do
29-
options = Selenium::WebDriver::Options.chrome
29+
options = default_chrome_options
3030
options.page_load_strategy = :none
3131

3232
driver = Selenium::WebDriver.for :chrome, options: options
@@ -48,7 +48,7 @@
4848
end
4949

5050
it 'accepts untrusted certificates' do
51-
options = Selenium::WebDriver::Options.chrome
51+
options = default_chrome_options
5252
options.accept_insecure_certs = true
5353

5454
driver = Selenium::WebDriver.for :chrome, options: options
@@ -57,7 +57,7 @@
5757
end
5858

5959
it 'sets unhandled prompt behavior' do
60-
options = Selenium::WebDriver::Options.chrome
60+
options = default_chrome_options
6161
options.unhandled_prompt_behavior = :accept
6262

6363
driver = Selenium::WebDriver.for :chrome, options: options
@@ -75,7 +75,7 @@
7575
end
7676

7777
it 'sets strict file interactability' do
78-
options = Selenium::WebDriver::Options.chrome
78+
options = default_chrome_options
7979
options.strict_file_interactability = true
8080

8181
driver = Selenium::WebDriver.for :chrome, options: options
@@ -84,7 +84,7 @@
8484
end
8585

8686
it 'sets the proxy' do
87-
options = Selenium::WebDriver::Options.chrome
87+
options = default_chrome_options
8888
options.proxy = Selenium::WebDriver::Proxy.new(http: 'myproxy.com:8080')
8989

9090
driver = Selenium::WebDriver.for :chrome, options: options
@@ -93,7 +93,7 @@
9393
end
9494

9595
it 'sets the implicit timeout' do
96-
options = Selenium::WebDriver::Options.chrome
96+
options = default_chrome_options
9797
options.timeouts = {implicit: 1}
9898

9999
driver = Selenium::WebDriver.for :chrome, options: options
@@ -102,7 +102,7 @@
102102
end
103103

104104
it 'sets the page load timeout' do
105-
options = Selenium::WebDriver::Options.chrome
105+
options = default_chrome_options
106106
options.timeouts = {page_load: 400_000}
107107

108108
driver = Selenium::WebDriver.for :chrome, options: options
@@ -111,7 +111,7 @@
111111
end
112112

113113
it 'sets the script timeout' do
114-
options = Selenium::WebDriver::Options.chrome
114+
options = default_chrome_options
115115
options.timeouts = {script: 40_000}
116116

117117
driver = Selenium::WebDriver.for :chrome, options: options

examples/ruby/spec/drivers/remote_webdriver_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
after { server.stop }
1919

2020
it 'starts remotely' do
21-
options = Selenium::WebDriver::Options.chrome
21+
options = default_chrome_options
2222
driver = Selenium::WebDriver.for :remote, url: grid_url, options: options
2323

2424
expect { driver.session_id }.not_to raise_exception
2525
end
2626

2727
it 'uploads' do
28-
options = Selenium::WebDriver::Options.chrome
28+
options = default_chrome_options
2929
driver = Selenium::WebDriver.for :remote, url: server.webdriver_url, options: options
3030

3131
driver.get('https://the-internet.herokuapp.com/upload')
@@ -41,7 +41,8 @@
4141
end
4242

4343
it 'downloads' do
44-
options = Selenium::WebDriver::Options.chrome(enable_downloads: true)
44+
options = default_chrome_options
45+
default_chrome_options.enable_downloads = true
4546
driver = Selenium::WebDriver.for :remote, url: grid_url, options: options
4647

4748
file_names = %w[file_1.txt file_2.jpg]

examples/ruby/spec/drivers/service_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
end
1717

1818
it 'specifies driver location' do
19-
options = Selenium::WebDriver::Options.chrome(binary: browser_path)
19+
options = default_chrome_options
20+
options.binary = browser_path
2021
service = Selenium::WebDriver::Service.chrome
2122

2223
service.executable_path = driver_path
@@ -32,7 +33,8 @@
3233
end
3334

3435
def driver_finder
35-
options = Selenium::WebDriver::Options.chrome(browser_version: 'stable')
36+
options = default_chrome_options
37+
options.browser_version = 'stable'
3638
service = Selenium::WebDriver::Service.chrome
3739
finder = Selenium::WebDriver::DriverFinder.new(options, service)
3840
ENV['CHROMEDRIVER_BIN'] = finder.driver_path

examples/ruby/spec/spec_helper.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@
3131
config.after { @driver&.quit }
3232

3333
def start_session
34+
@service = Selenium::WebDriver::Service.chrome
35+
@driver = Selenium::WebDriver.for(:chrome, options: deault_chrome_options)
36+
end
37+
38+
def deault_chrome_options
3439
options = Selenium::WebDriver::Chrome::Options.new
3540
options.add_argument('disable-search-engine-choice-screen')
3641
options.add_argument('--no-sandbox')
3742
options.browser_version = 'stable'
38-
@service = Selenium::WebDriver::Service.chrome
39-
@driver = Selenium::WebDriver.for(:chrome, options: options)
43+
options
4044
end
4145

4246
def start_bidi_session

0 commit comments

Comments
 (0)