Skip to content

Commit 231acf6

Browse files
committed
[rb] add integration tests for ActionBuilder
1 parent fe30005 commit 231acf6

1 file changed

Lines changed: 143 additions & 59 deletions

File tree

rb/spec/integration/selenium/webdriver/action_builder_spec.rb

Lines changed: 143 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module WebDriver
2424
describe ActionBuilder do
2525
after { driver.action.clear_all_actions }
2626

27-
describe 'Key actions' do
27+
describe '#send_keys' do
2828
it 'sends keys to the active element', except: {browser: %i[safari safari_preview]} do
2929
driver.navigate.to url_for('bodyTypingTest.html')
3030
keylogger = driver.find_element(id: 'body_result')
@@ -38,7 +38,41 @@ module WebDriver
3838
expect(driver.find_element(id: 'result').text.strip).to be_empty
3939
end
4040

41-
it 'can send keys with shift pressed', except: {browser: %i[safari safari_preview]} do
41+
it 'sends keys to element' do
42+
driver.navigate.to url_for('formPage.html')
43+
44+
input = driver.find_element(css: '#working')
45+
46+
driver.action.send_keys(input, 'abcd').perform
47+
wait.until { input.attribute(:value).length == 4 }
48+
expect(input.attribute(:value)).to eq('abcd')
49+
end
50+
51+
it 'sends keys with multiple arguments' do
52+
driver.navigate.to url_for('formPage.html')
53+
54+
input = driver.find_element(css: '#working')
55+
input.click
56+
57+
driver.action.send_keys('abcd', 'dcba').perform
58+
wait.until { input.attribute(:value).length == 8 }
59+
expect(input.attribute(:value)).to eq('abcddcba')
60+
end
61+
62+
it 'sends non-ASCII keys' do
63+
driver.navigate.to url_for('formPage.html')
64+
65+
input = driver.find_element(css: '#working')
66+
input.click
67+
68+
driver.action.send_keys('abcd', :left, 'a').perform
69+
wait.until { input.attribute(:value).length == 5 }
70+
expect(input.attribute(:value)).to eq('abcad')
71+
end
72+
end
73+
74+
describe 'multiple key presses' do
75+
it 'sends keys with shift pressed', except: {browser: %i[safari safari_preview]} do
4276
driver.navigate.to url_for('javascriptPage.html')
4377

4478
event_input = driver.find_element(id: 'theworks')
@@ -54,7 +88,7 @@ module WebDriver
5488
expect(expected).to match(/^(focus )?keydown keydown keypress keyup keydown keypress keyup keyup$/)
5589
end
5690

57-
it 'can press and release modifier keys' do
91+
it 'press and release modifier keys' do
5892
driver.navigate.to url_for('javascriptPage.html')
5993

6094
event_input = driver.find_element(id: 'theworks')
@@ -70,66 +104,118 @@ module WebDriver
70104
wait.until { keylogger.text.include? 'up' }
71105
expect(keylogger.text).to match(/keyup *$/)
72106
end
107+
end
73108

74-
it 'can send multiple send_keys commands' do
75-
driver.navigate.to url_for('formPage.html')
109+
describe '#release_actions' do
110+
it 'releases pressed keys' do
111+
driver.navigate.to url_for('javascriptPage.html')
76112

77-
input = driver.find_element(css: '#working')
78-
input.click
113+
event_input = driver.find_element(id: 'theworks')
114+
keylogger = driver.find_element(id: 'result')
79115

80-
driver.action.send_keys('abcd', 'dcba').perform
81-
wait.until { input.attribute(:value).length == 8 }
82-
expect(input.attribute(:value)).to eq('abcddcba')
116+
event_input.click
117+
118+
driver.action.key_down(:shift).perform
119+
wait.until { keylogger.text.include? 'down' }
120+
expect(keylogger.text).to match(/keydown *$/)
121+
122+
driver.action.release_actions
123+
wait.until { keylogger.text.include? 'up' }
124+
expect(keylogger.text).to match(/keyup *$/)
83125
end
84126

85-
it 'can send non-ASCII keys' do
86-
driver.navigate.to url_for('formPage.html')
127+
it 'releases pressed buttons', except: [{browser: %i[safari safari_preview]},
128+
{driver: :remote, browser: :ie}] do
129+
driver.navigate.to url_for('javascriptPage.html')
87130

88-
input = driver.find_element(css: '#working')
89-
input.click
131+
event_input = driver.find_element(id: 'clickField')
90132

91-
driver.action.send_keys('abcd', :left, 'a').perform
92-
wait.until { input.attribute(:value).length == 5 }
93-
expect(input.attribute(:value)).to eq('abcad')
133+
driver.action.click_and_hold(event_input).perform
134+
expect(event_input.attribute(:value)).to eq('Hello')
135+
136+
driver.action.release_actions
137+
expect(event_input.attribute(:value)).to eq('Clicked')
94138
end
139+
end
95140

96-
it 'can send keys to element' do
97-
driver.navigate.to url_for('formPage.html')
141+
describe '#release' do
142+
it 'releases pressed buttons', except: [{browser: %i[safari safari_preview]},
143+
{driver: :remote, browser: :ie}] do
144+
driver.navigate.to url_for('javascriptPage.html')
98145

99-
input = driver.find_element(css: '#working')
146+
event_input = driver.find_element(id: 'clickField')
100147

101-
driver.action.send_keys(input, 'abcd').perform
102-
wait.until { input.attribute(:value).length == 4 }
103-
expect(input.attribute(:value)).to eq('abcd')
148+
driver.action.click_and_hold(event_input).perform
149+
expect(event_input.attribute(:value)).to eq('Hello')
150+
151+
driver.action.release.perform
152+
expect(event_input.attribute(:value)).to eq('Clicked')
104153
end
154+
end
105155

106-
it 'can release pressed keys via release action' do
156+
describe '#click' do
157+
it 'clicks provided element' do
107158
driver.navigate.to url_for('javascriptPage.html')
159+
element = driver.find_element(id: 'clickField')
160+
driver.action.click(element).perform
161+
expect(element.attribute(:value)).to eq('Clicked')
162+
end
163+
end
108164

109-
event_input = driver.find_element(id: 'theworks')
110-
keylogger = driver.find_element(id: 'result')
165+
describe 'pointer presses' do
166+
it 'holds pointer down and releases' do
167+
driver.navigate.to url_for('javascriptPage.html')
168+
element = driver.find_element(id: 'clickField')
169+
driver.action.move_to(element).pointer_down(:left).click.pointer_up(:left).perform
170+
expect(element.attribute(:value)).to eq('Clicked')
171+
end
172+
end
111173

112-
event_input.click
174+
describe '#double_click' do
175+
it 'presses pointer twice', except: {browser: %i[safari safari_preview]} do
176+
driver.navigate.to url_for('javascriptPage.html')
177+
element = driver.find_element(id: 'doubleClickField')
113178

114-
driver.action.key_down(:shift).perform
115-
wait.until { keylogger.text.include? 'down' }
116-
expect(keylogger.text).to match(/keydown *$/)
179+
driver.action.double_click(element).perform
180+
expect(element.attribute(:value)).to eq('DoubleClicked')
181+
end
182+
end
117183

118-
driver.action.release_actions
119-
wait.until { keylogger.text.include? 'up' }
120-
expect(keylogger.text).to match(/keyup *$/)
184+
describe '#context_click' do
185+
it 'right clicks an element' do
186+
driver.navigate.to url_for('javascriptPage.html')
187+
element = driver.find_element(id: 'doubleClickField')
188+
189+
driver.action.context_click(element).perform
190+
expect(element.attribute(:value)).to eq('ContextClicked')
121191
end
122-
end # Key actions
192+
end
123193

124-
describe 'Pointer actions' do
125-
it 'clicks an element' do
194+
describe '#move_to' do
195+
it 'moves to element' do
126196
driver.navigate.to url_for('javascriptPage.html')
127197
element = driver.find_element(id: 'clickField')
128-
driver.action.click(element).perform
198+
driver.action.move_to(element).click.perform
199+
129200
expect(element.attribute(:value)).to eq('Clicked')
130201
end
131202

132-
it 'can drag and drop' do
203+
it 'moves to element with offset' do
204+
driver.navigate.to url_for('javascriptPage.html')
205+
origin = driver.find_element(id: 'keyUpArea')
206+
destination = driver.find_element(id: 'clickField')
207+
origin_rect = origin.rect
208+
destination_rect = destination.rect
209+
x_offset = (destination_rect.x - origin_rect.x).ceil
210+
y_offset = (destination_rect.y - origin_rect.y).ceil
211+
212+
driver.action.move_to(origin, x_offset, y_offset).click.perform
213+
expect(destination.attribute(:value)).to eq('Clicked')
214+
end
215+
end
216+
217+
describe '#drag_and_drop' do
218+
it 'moves one element to another' do
133219
driver.navigate.to url_for('droppableItems.html')
134220

135221
draggable = long_wait.until do
@@ -143,36 +229,34 @@ module WebDriver
143229
text = droppable.find_element(tag_name: 'p').text
144230
expect(text).to eq('Dropped!')
145231
end
232+
end
146233

147-
it 'double clicks an element', except: {browser: %i[safari safari_preview]} do
148-
driver.navigate.to url_for('javascriptPage.html')
149-
element = driver.find_element(id: 'doubleClickField')
234+
describe '#drag_and_drop_by' do
235+
it 'moves one element a provided distance' do
236+
driver.navigate.to url_for('droppableItems.html')
150237

151-
driver.action.double_click(element).perform
152-
expect(element.attribute(:value)).to eq('DoubleClicked')
153-
end
238+
draggable = long_wait.until do
239+
driver.find_element(id: 'draggable')
240+
end
154241

155-
it 'context clicks an element' do
156-
driver.navigate.to url_for('javascriptPage.html')
157-
element = driver.find_element(id: 'doubleClickField')
242+
driver.action.drag_and_drop_by(draggable, 138, 50).perform
158243

159-
driver.action.context_click(element).perform
160-
expect(element.attribute(:value)).to eq('ContextClicked')
244+
droppable = driver.find_element(id: 'droppable')
245+
text = droppable.find_element(tag_name: 'p').text
246+
expect(text).to eq('Dropped!')
161247
end
248+
end
162249

163-
it 'can release pressed buttons via release action', except: [{browser: %i[safari safari_preview]},
164-
{driver: :remote, browser: :ie}] do
250+
describe '#move_to_location' do
251+
it 'moves pointer to specified coordinates' do
165252
driver.navigate.to url_for('javascriptPage.html')
253+
element = driver.find_element(id: 'clickField')
254+
rect = element.rect
255+
driver.action.move_to_location(rect.x, rect.y).click.perform
166256

167-
event_input = driver.find_element(id: 'clickField')
168-
169-
driver.action.click_and_hold(event_input).perform
170-
expect(event_input.attribute(:value)).to eq('Hello')
171-
172-
driver.action.release_actions
173-
expect(event_input.attribute(:value)).to eq('Clicked')
257+
expect(element.attribute(:value)).to eq('Clicked')
174258
end
175-
end # Pointer actions
259+
end
176260
end # ActionBuilder
177261
end # WebDriver
178262
end # Selenium

0 commit comments

Comments
 (0)