Skip to content

Commit

Permalink
Merge pull request #47 from rueyjye/feature/fix_switch_window
Browse files Browse the repository at this point in the history
fix switch add rspec
  • Loading branch information
hikimochi authored Nov 14, 2019
2 parents d48f7f8 + 07aaa01 commit fe4a9aa
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 9 deletions.
21 changes: 18 additions & 3 deletions lib/bucky/test_equipment/user_operation/user_operation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,24 @@ def refresh(_)
@driver.navigate.refresh
end

def switch_next_window(_)
def switch_to_next_window(_)
window_index = @driver.window_handles.index(@driver.window_handle)
windows_number = @driver.window_handles.size
unless window_index+1 == windows_number
@driver.switch_to.window(@driver.window_handles[window_index+1])
end
end

def switch_to_previous_window(_)
window_index = @driver.window_handles.index(@driver.window_handle)
@driver.switch_to.window(@driver.window_handles[window_index-1])
end

def switch_to_newest_window(_)
@driver.switch_to.window(@driver.window_handles.last)
end

def back_to_window(_)
def switch_to_oldest_window(_)
@driver.switch_to.window(@driver.window_handles.first)
end

Expand All @@ -61,11 +74,13 @@ def switch_to_the_window(args)

# Close window
def close(_)
window_index = @driver.window_handles.index(@driver.window_handle)
@driver.close
@driver.switch_to.window(@driver.window_handles[window_index-1])
end

def stop(_)
puts 'stop. please enter to continue'
puts 'stop. press enter to continue'
gets
end

Expand Down
68 changes: 62 additions & 6 deletions spec/test_equipment/user_operation/user_operation_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,62 @@
end
end

describe '#switch_next_window' do
let(:operation) { :switch_next_window }
describe '#switch_to_next_window' do
let(:operation) { :switch_to_next_window }
let(:window_handles_double) { double('window_handles double') }
let(:window_index) { 2 }
let(:windows_number) { 4 }
before do
allow(driver_double).to receive(:window_handle)
allow(driver_double).to receive_message_chain(:window_handles, :index).and_return(window_index)
allow(driver_double).to receive_message_chain(:window_handles, :size).and_return(windows_number)
end
it 'call driver.switch_to.window' do
allow(driver_double).to receive_message_chain(:window_handles, :[])
expect(driver_double).to receive_message_chain(:switch_to, :window)
subject.send(operation, nil)
end

it 'switch to next window index' do
allow(driver_double).to receive_message_chain(:switch_to, :window)
expect(driver_double).to receive_message_chain(:window_handles, :[]).with(window_index + 1)
subject.send(operation, nil)
end
end

describe '#switch_to_previous_window' do
let(:operation) { :switch_to_previous_window }
let(:window_index) { 2 }
before do
allow(driver_double).to receive(:window_handle)
allow(driver_double).to receive_message_chain(:window_handles, :index).and_return(window_index)
end
it 'call driver.switch_to.window' do
allow(driver_double).to receive_message_chain(:window_handles, :[])
expect(driver_double).to receive_message_chain(:switch_to, :window)
subject.send(operation, nil)
end

it 'switch to previous window index' do
allow(driver_double).to receive_message_chain(:switch_to, :window)
expect(driver_double).to receive_message_chain(:window_handles, :[]).with(window_index - 1)
subject.send(operation, nil)
end
end

describe '#switch_to_newest_window' do
let(:operation) { :switch_to_newest_window }
before do
allow(driver_double).to receive_message_chain(:window_handles, :last)
end
it 'call driver.switch_to.window' do
allow(driver_double).to receive_message_chain(:switch_to, :frame)
expect(driver_double).to receive_message_chain(:switch_to, :window)
subject.send(operation, nil)
end
end

describe '#back_to_window' do
let(:operation) { :back_to_window }
describe '#switch_to_oldest_window' do
let(:operation) { :switch_to_oldest_window }
before do
allow(driver_double).to receive_message_chain(:window_handles, :first)
end
Expand All @@ -73,8 +115,22 @@

describe '#close' do
let(:operation) { :close }
let(:window_index) { 2 }
before do
allow(driver_double).to receive(:window_handle)
allow(driver_double).to receive_message_chain(:window_handles, :index).and_return(window_index)
end
it 'call driver.close' do
expect(driver_double).to receive_message_chain(:close)
allow(driver_double).to receive_message_chain(:window_handles, :[])
allow(driver_double).to receive_message_chain(:switch_to, :window)
expect(driver_double).to receive(:close)
subject.send(operation, nil)
end

it 'switch to last window index' do
allow(driver_double).to receive(:close)
allow(driver_double).to receive_message_chain(:switch_to, :window)
expect(driver_double).to receive_message_chain(:window_handles, :[]).with(window_index - 1)
subject.send(operation, nil)
end
end
Expand Down

0 comments on commit fe4a9aa

Please sign in to comment.