-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathpen_spec.rb
92 lines (79 loc) · 3.51 KB
/
pen_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
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Pen' do
let(:driver) { start_session }
it 'uses a pen' do
driver.get 'https://www.selenium.dev/selenium/web/pointerActionsPage.html'
pointer_area = driver.find_element(id: 'pointerArea')
driver.action(devices: :pen)
.move_to(pointer_area)
.pointer_down
.move_by(2, 2)
.pointer_up
.perform
moves = driver.find_elements(class: 'pointermove')
move_to = properties(moves[0])
down = properties(driver.find_element(class: 'pointerdown'))
move_by = properties(moves[1])
up = properties(driver.find_element(class: 'pointerup'))
rect = pointer_area.rect
center_x = rect.x + (rect.width / 2)
center_y = rect.y + (rect.height / 2)
expect(move_to).to include('button' => '-1',
'pointerType' => 'pen',
'pageX' => center_x.to_s,
'pageY' => center_y.floor.to_s)
expect(down).to include('button' => '0',
'pointerType' => 'pen',
'pageX' => center_x.to_s,
'pageY' => center_y.floor.to_s)
expect(move_by).to include('button' => '-1',
'pointerType' => 'pen',
'pageX' => (center_x + 2).to_s,
'pageY' => (center_y + 2).floor.to_s)
expect(up).to include('button' => '0',
'pointerType' => 'pen',
'pageX' => (center_x + 2).to_s,
'pageY' => (center_y + 2).floor.to_s)
end
it 'sets pointer event attributes' do
driver.get 'https://www.selenium.dev/selenium/web/pointerActionsPage.html'
pointer_area = driver.find_element(id: 'pointerArea')
driver.action(devices: :pen)
.move_to(pointer_area)
.pointer_down
.move_by(2, 2, tilt_x: -72, tilt_y: 9, twist: 86)
.pointer_up
.perform
moves = driver.find_elements(class: 'pointermove')
move_to = properties(moves[0])
down = properties(driver.find_element(class: 'pointerdown'))
move_by = properties(moves[1])
up = properties(driver.find_element(class: 'pointerup'))
rect = pointer_area.rect
center_x = rect.x + (rect.width / 2)
center_y = rect.y + (rect.height / 2)
expect(move_to).to include('button' => '-1',
'pointerType' => 'pen',
'pageX' => center_x.to_s,
'pageY' => center_y.floor.to_s)
expect(down).to include('button' => '0',
'pointerType' => 'pen',
'pageX' => center_x.to_s,
'pageY' => center_y.floor.to_s)
expect(move_by).to include('button' => '-1',
'pointerType' => 'pen',
'pageX' => (center_x + 2).to_s,
'pageY' => (center_y + 2).floor.to_s,
'tiltX' => -72.to_s,
'tiltY' => 9.to_s,
'twist' => 86.to_s)
expect(up).to include('button' => '0',
'pointerType' => 'pen',
'pageX' => (center_x + 2).to_s,
'pageY' => (center_y + 2).floor.to_s)
end
def properties(element)
element.text.sub(/.*?\s/, '').split(',').to_h { |item| item.lstrip.split(/\s*:\s*/) }
end
end