-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathmouse_spec.rb
162 lines (122 loc) · 4.81 KB
/
mouse_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Mouse' do
let(:driver) { start_session }
it 'click and hold' do
driver.get 'https://www.selenium.dev/selenium/web/mouse_interaction.html'
clickable = driver.find_element(id: 'clickable')
driver.action
.click_and_hold(clickable)
.perform
expect(driver.find_element(id: 'click-status').text).to eq 'focused'
end
it 'click and release' do
driver.get 'https://www.selenium.dev/selenium/web/mouse_interaction.html'
clickable = driver.find_element(id: 'click')
driver.action
.click(clickable)
.perform
expect(driver.current_url).to include 'resultPage.html'
end
describe 'alternate button clicks' do
it 'right click' do
driver.get 'https://www.selenium.dev/selenium/web/mouse_interaction.html'
clickable = driver.find_element(id: 'clickable')
driver.action
.context_click(clickable)
.perform
expect(driver.find_element(id: 'click-status').text).to eq 'context-clicked'
end
it 'back click' do
driver.get 'https://www.selenium.dev/selenium/web/mouse_interaction.html'
driver.find_element(id: 'click').click
expect(driver.title).to eq('We Arrive Here')
driver.action
.pointer_down(:back)
.pointer_up(:back)
.perform
expect(driver.title).to eq('BasicMouseInterfaceTest')
end
it 'forward click' do
driver.get 'https://www.selenium.dev/selenium/web/mouse_interaction.html'
driver.find_element(id: 'click').click
driver.navigate.back
expect(driver.title).to eq('BasicMouseInterfaceTest')
driver.action
.pointer_down(:forward)
.pointer_up(:forward)
.perform
expect(driver.title).to eq('We Arrive Here')
end
end
it 'double click' do
driver.get 'https://www.selenium.dev/selenium/web/mouse_interaction.html'
clickable = driver.find_element(id: 'clickable')
driver.action
.double_click(clickable)
.perform
expect(driver.find_element(id: 'click-status').text).to eq 'double-clicked'
end
it 'hovers' do
driver.get 'https://www.selenium.dev/selenium/web/mouse_interaction.html'
hoverable = driver.find_element(id: 'hover')
driver.action
.move_to(hoverable)
.perform
expect(driver.find_element(id: 'move-status').text).to eq 'hovered'
end
describe 'move by offset' do
it 'offset from element' do
driver.get 'https://www.selenium.dev/selenium/web/mouse_interaction.html'
driver.action.scroll_to(driver.find_element(id: 'bottom')).perform
mouse_tracker = driver.find_element(id: 'mouse-tracker')
driver.action
.move_to(mouse_tracker, 8, 11)
.perform
rect = mouse_tracker.rect
center_x = rect.width / 2
center_y = rect.height / 2
x_coord, y_coord = driver.find_element(id: 'relative-location').text.split(',').map(&:to_i)
expect(x_coord).to be_within(1).of(center_x + 8)
expect(y_coord).to be_within(1).of(center_y + 11)
end
it 'offset from viewport', {platforn: :linux, reason: 'it only fails on the linux pipeline'} do
driver.get 'https://www.selenium.dev/selenium/web/mouse_interaction.html'
driver.action
.move_to_location(8, 12)
.perform
x_coord, y_coord = driver.find_element(id: 'absolute-location').text.split(',').map(&:to_i)
expect(x_coord).to be_within(1).of(8)
expect(y_coord).to be_within(1).of(12)
end
it 'offset from current pointer location' do
driver.get 'https://www.selenium.dev/selenium/web/mouse_interaction.html'
driver.action.move_to_location(8, 11).perform
driver.action
.move_by(13, 15)
.perform
x_coord, y_coord = driver.find_element(id: 'absolute-location').text.split(',').map(&:to_i)
expect(x_coord).to be_within(1).of(8 + 13)
expect(y_coord).to be_within(1).of(11 + 15)
end
end
it 'drags to another element' do
driver.get 'https://www.selenium.dev/selenium/web/mouse_interaction.html'
draggable = driver.find_element(id: 'draggable')
droppable = driver.find_element(id: 'droppable')
driver.action
.drag_and_drop(draggable, droppable)
.perform
expect(driver.find_element(id: 'drop-status').text).to include('dropped')
end
it 'drags by an offset' do
driver.get 'https://www.selenium.dev/selenium/web/mouse_interaction.html'
draggable = driver.find_element(id: 'draggable')
start = draggable.rect
finish = driver.find_element(id: 'droppable').rect
driver.action
.drag_and_drop_by(draggable, finish.x - start.x, finish.y - start.y)
.perform
expect(driver.find_element(id: 'drop-status').text).to include('dropped')
end
end