Skip to content

Commit 5e5d5e2

Browse files
authored
Merge pull request #115 from kaidotdev/accept-timeout-args
Accept timeout argument to avoid Selenium::WebDriver::Error::TimeoutError
2 parents 2d0c1da + 2ff74f1 commit 5e5d5e2

File tree

5 files changed

+51
-9
lines changed

5 files changed

+51
-9
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
- run:
7676
name: Run RuboCop on changed files
7777
command: |
78-
git diff --name-only origin/master...HEAD -- '*.rb' | xargs bundle exec rubocop -f html --out report.html
78+
git diff --name-only origin/master...HEAD -- '*.rb' | xargs -r bundle exec rubocop -f html --out report.html
7979
- store_artifacts:
8080
path: report.html
8181
publish_to_rubygems:

bucky-core.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Gem::Specification.new do |spec|
4343
spec.add_runtime_dependency 'addressable', '~> 2.5'
4444
spec.add_runtime_dependency 'color_echo', '~> 3.1'
4545
spec.add_runtime_dependency 'json', '~> 2.3.0'
46-
spec.add_runtime_dependency 'nokogiri', '~> 1.11.1'
46+
spec.add_runtime_dependency 'nokogiri', '1.18.2'
4747
spec.add_runtime_dependency 'parallel', '~> 1.11'
4848
spec.add_runtime_dependency 'ruby-mysql', '~> 2.9'
4949
spec.add_runtime_dependency 'selenium-webdriver', '4.24'

lib/bucky/test_equipment/user_operation/user_operation_helper.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def back(_)
2727

2828
def input(args)
2929
# when input successfully, return of click is nil.
30-
wait_until_helper(5, 0.1, Selenium::WebDriver::Error::StaleElementReferenceError) { @pages.get_part(args).send_keys(args[:word]).nil? }
30+
wait_until_helper((args || {}).fetch(:timeout, 5), 0.1, Selenium::WebDriver::Error::StaleElementReferenceError) { @pages.get_part(args).send_keys(args[:word]).nil? }
3131
end
3232

3333
# Clear textbox
@@ -38,7 +38,7 @@ def clear(args)
3838
def click(args)
3939
elem = @pages.get_part(args)
4040
# when click successfully, return of click is nil.
41-
wait_until_helper(5, 0.1, Selenium::WebDriver::Error::WebDriverError) { elem.click.nil? }
41+
wait_until_helper((args || {}).fetch(:timeout, 5), 0.1, Selenium::WebDriver::Error::WebDriverError) { elem.click.nil? }
4242
end
4343

4444
def refresh(_)
@@ -68,7 +68,7 @@ def switch_to_oldest_window(_)
6868

6969
def switch_to_the_window(args)
7070
# when the window successfully switched, return of switch_to.window is nil.
71-
wait_until_helper(5, 0.1, Selenium::WebDriver::Error::NoSuchWindowError) { @driver.switch_to.window(args[:window_name]).nil? }
71+
wait_until_helper((args || {}).fetch(:timeout, 5), 0.1, Selenium::WebDriver::Error::NoSuchWindowError) { @driver.switch_to.window(args[:window_name]).nil? }
7272
end
7373

7474
# Close window
@@ -84,7 +84,7 @@ def stop(_)
8484
end
8585

8686
def choose(args)
87-
option = wait_until_helper(5, 0.1, Selenium::WebDriver::Error::StaleElementReferenceError) { Selenium::WebDriver::Support::Select.new(@pages.get_part(args)) }
87+
option = wait_until_helper((args || {}).fetch(:timeout, 5), 0.1, Selenium::WebDriver::Error::StaleElementReferenceError) { Selenium::WebDriver::Support::Select.new(@pages.get_part(args)) }
8888
if args.key?(:text)
8989
type = :text
9090
selected = args[type].to_s
@@ -101,8 +101,8 @@ def choose(args)
101101
end
102102

103103
# Alert accept
104-
def accept_alert(_)
105-
alert = wait_until_helper(5, 0.1, Selenium::WebDriver::Error::NoSuchAlertError) { @driver.switch_to.alert }
104+
def accept_alert(args)
105+
alert = wait_until_helper((args || {}).fetch(:timeout, 5), 0.1, Selenium::WebDriver::Error::NoSuchAlertError) { @driver.switch_to.alert }
106106
alert.accept
107107
end
108108

spec/test_equipment/user_operation/user_operation_helper_spec.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@
103103
describe '#switch_to_the_window' do
104104
let(:operation) { :switch_to_the_window }
105105
let(:args) { { window_name: 'new' } }
106+
let(:timeout_sec) { 2 }
107+
let(:args_with_timeout) { { window_name: 'new', timeout: timeout_sec } }
106108
it 'call driver.swich_to_window_by_name' do
107109
expect(driver_double).to receive_message_chain(:switch_to, :window)
108110
subject.send(operation, args)
@@ -111,6 +113,10 @@
111113
expect(subject).to receive(:wait_until_helper)
112114
subject.send(operation, args)
113115
end
116+
it 'call wait_until_helper with timeout argument' do
117+
expect(subject).to receive(:wait_until_helper) { |timeout, *| expect(timeout).to eq(timeout_sec) }
118+
subject.send(operation, args_with_timeout)
119+
end
114120
end
115121

116122
describe '#close' do
@@ -146,6 +152,8 @@
146152
describe '#input' do
147153
let(:operation) { :input }
148154
let(:args) { { page: 'top', part: 'form', word: 'hogehoge' } }
155+
let(:timeout_sec) { 2 }
156+
let(:args_with_timeout) { args.merge(timeout: timeout_sec) }
149157
let(:elem_double) { double('elem double') }
150158
it 'call part#send_keys' do
151159
expect(pages_double).to receive_message_chain(:get_part, :send_keys)
@@ -156,6 +164,12 @@
156164
expect(subject).to receive(:wait_until_helper)
157165
subject.send(operation, args)
158166
end
167+
it 'call wait_until_helper with timeout argument' do
168+
allow(pages_double).to receive_message_chain(:get_part, :send_keys).and_return(elem_double)
169+
# Verify that some of the arguments match.
170+
expect(subject).to receive(:wait_until_helper) { |timeout, *| expect(timeout).to eq(timeout_sec) }
171+
subject.send(operation, args_with_timeout)
172+
end
159173
end
160174

161175
describe '#clear' do
@@ -170,6 +184,8 @@
170184
describe '#click' do
171185
let(:operation) { :click }
172186
let(:args) { { page: 'top', part: 'form' } }
187+
let(:timeout_sec) { 2 }
188+
let(:args_with_timeout) { args.merge(timeout: timeout_sec) }
173189
let(:elem_double) { double('elem double') }
174190
it 'call part#click' do
175191
allow(pages_double).to receive(:get_part).and_return(elem_double)
@@ -187,6 +203,14 @@
187203
expect(subject).to receive(:wait_until_helper)
188204
subject.send(operation, args)
189205
end
206+
207+
it 'call wait_until_helper with timeout argument' do
208+
allow(pages_double).to receive(:get_part).and_return(elem_double)
209+
allow(elem_double).to receive(:click)
210+
# Verify that some of the arguments match.
211+
expect(subject).to receive(:wait_until_helper) { |timeout, *| expect(timeout).to eq(timeout_sec) }
212+
subject.send(operation, args_with_timeout)
213+
end
190214
end
191215

192216
describe '#choose' do
@@ -195,6 +219,8 @@
195219
let(:args_value) { { page: 'top', part: 'form', value: 1 } }
196220
let(:args_index) { { page: 'top', part: 'form', index: 1 } }
197221
let(:args_error) { { page: 'top', part: 'form', error: 1 } }
222+
let(:timeout_sec) { 2 }
223+
let(:args_text_with_timeout) { args_text.merge(timeout: timeout_sec) }
198224
let(:option_double) { double('option double') }
199225
let(:elem_double) { double('elem double') }
200226
before do
@@ -221,11 +247,19 @@
221247
expect(subject).to receive(:wait_until_helper).and_return(option_double)
222248
subject.send(operation, args_text)
223249
end
250+
it 'call wait_until_helper with timeout argument' do
251+
allow(option_double).to receive(:select_by).with(:text, 'foo')
252+
# Verify that some of the arguments match.
253+
expect(subject).to receive(:wait_until_helper) { |timeout, *| expect(timeout).to eq(timeout_sec) }.and_return(option_double)
254+
subject.send(operation, args_text_with_timeout)
255+
end
224256
end
225257

226258
describe '#accept_alert' do
227259
let(:operation) { :accept_alert }
228260
let(:alert_double) { double('alert double') }
261+
let(:timeout_sec) { 2 }
262+
let(:args_timeout) { { timeout: timeout_sec } }
229263
it 'call driver.switch_to.alert.accept' do
230264
expect(driver_double).to receive_message_chain(:switch_to, :alert, :accept)
231265
subject.send(operation, nil)
@@ -236,6 +270,13 @@
236270
expect(subject).to receive(:wait_until_helper).and_return(alert_double)
237271
subject.send(operation, nil)
238272
end
273+
it 'call wait_until_helper with timeout argument' do
274+
allow(driver_double).to receive_message_chain(:switch_to, :alert).and_return(alert_double)
275+
allow(alert_double).to receive(:accept)
276+
# Verify that some of the arguments match.
277+
expect(subject).to receive(:wait_until_helper) { |timeout, *| expect(timeout).to eq(2) }.and_return(alert_double)
278+
subject.send(operation, args_timeout)
279+
end
239280
end
240281

241282
describe '#wait' do

system_testing/test_bucky_project/services/service_a/pc/scenarios/e2e/pc_e2e.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ cases:
1717
operate: click
1818
page: index
1919
part: link
20+
timeout: 1
2021
- proc: check title
2122
exec:
2223
verify: assert_title
@@ -128,4 +129,4 @@ cases:
128129
- proc: index
129130
exec:
130131
verify: click_multiple_element
131-
page: index
132+
page: index

0 commit comments

Comments
 (0)