Skip to content

Commit 77a0c71

Browse files
committed
[rb] move each interaction class to its own file
1 parent 70cb566 commit 77a0c71

22 files changed

+509
-255
lines changed

‎rb/lib/selenium/webdriver/common.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@
3838
require 'selenium/webdriver/common/logs'
3939
require 'selenium/webdriver/common/manager'
4040
require 'selenium/webdriver/common/search_context'
41+
require 'selenium/webdriver/common/interactions/interaction'
42+
require 'selenium/webdriver/common/interactions/interactions'
43+
require 'selenium/webdriver/common/interactions/pointer_cancel'
44+
require 'selenium/webdriver/common/interactions/pointer_move'
45+
require 'selenium/webdriver/common/interactions/pointer_press'
46+
require 'selenium/webdriver/common/interactions/typing_interaction'
47+
require 'selenium/webdriver/common/interactions/pause'
4148
require 'selenium/webdriver/common/interactions/key_actions'
4249
require 'selenium/webdriver/common/interactions/pointer_actions'
43-
require 'selenium/webdriver/common/interactions/interactions'
4450
require 'selenium/webdriver/common/interactions/input_device'
45-
require 'selenium/webdriver/common/interactions/interaction'
4651
require 'selenium/webdriver/common/interactions/none_input'
4752
require 'selenium/webdriver/common/interactions/key_input'
4853
require 'selenium/webdriver/common/interactions/pointer_input'

‎rb/lib/selenium/webdriver/common/interactions/interaction.rb

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,6 @@ def initialize(source)
3434
@source = source
3535
end
3636
end
37-
38-
class Pause < Interaction
39-
def initialize(source, duration = nil)
40-
super(source)
41-
@duration = duration
42-
end
43-
44-
def type
45-
PAUSE
46-
end
47-
48-
def encode
49-
output = {type: type}
50-
output[:duration] = (@duration * 1000).to_i if @duration
51-
output
52-
end
53-
end # Interaction
5437
end # Interactions
5538
end # WebDriver
5639
end # Selenium

‎rb/lib/selenium/webdriver/common/interactions/key_input.rb

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,6 @@
2020
module Selenium
2121
module WebDriver
2222
module Interactions
23-
class TypingInteraction < Interaction
24-
attr_reader :type
25-
26-
def initialize(source, type, key)
27-
super(source)
28-
@type = assert_type(type)
29-
@key = Keys.encode_key(key)
30-
end
31-
32-
def assert_type(type)
33-
raise TypeError, "#{type.inspect} is not a valid key subtype" unless KeyInput::SUBTYPES.key? type
34-
35-
KeyInput::SUBTYPES[type]
36-
end
37-
38-
def encode
39-
{type: @type, value: @key}
40-
end
41-
end # TypingInteraction
42-
4323
class KeyInput < InputDevice
4424
SUBTYPES = {down: :keyDown, up: :keyUp, pause: :pause}.freeze
4525

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# frozen_string_literal: true
2+
3+
# Licensed to the Software Freedom Conservancy (SFC) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The SFC licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
module Selenium
21+
module WebDriver
22+
module Interactions
23+
class Pause < Interaction
24+
def initialize(source, duration = nil)
25+
super(source)
26+
@duration = duration
27+
end
28+
29+
def type
30+
PAUSE
31+
end
32+
33+
def encode
34+
output = {type: type}
35+
output[:duration] = (@duration * 1000).to_i if @duration
36+
output
37+
end
38+
end # Pause
39+
end # Interactions
40+
end # WebDriver
41+
end # Selenium
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
3+
# Licensed to the Software Freedom Conservancy (SFC) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The SFC licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
module Selenium
21+
module WebDriver
22+
module Interactions
23+
class PointerCancel < Interaction
24+
def type
25+
:pointerCancel
26+
end
27+
28+
def encode
29+
{type: type}
30+
end
31+
end # PointerCancel
32+
end # Interactions
33+
end # WebDriver
34+
end # Selenium

‎rb/lib/selenium/webdriver/common/interactions/pointer_input.rb

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -64,78 +64,6 @@ def create_pointer_cancel
6464
add_action(PointerCancel.new(self))
6565
end
6666
end # PointerInput
67-
68-
class PointerPress < Interaction
69-
BUTTONS = {left: 0, middle: 1, right: 2}.freeze
70-
DIRECTIONS = {down: :pointerDown, up: :pointerUp}.freeze
71-
72-
def initialize(source, direction, button)
73-
super(source)
74-
@direction = assert_direction(direction)
75-
@button = assert_button(button)
76-
end
77-
78-
def type
79-
@direction
80-
end
81-
82-
def assert_button(button)
83-
case button
84-
when Symbol
85-
raise ArgumentError, "#{button} is not a valid button!" unless BUTTONS.key? button
86-
87-
BUTTONS[button]
88-
when Integer
89-
raise ArgumentError, 'Button number cannot be negative!' if button.negative?
90-
91-
button
92-
else
93-
raise TypeError, "button must be a positive integer or one of #{BUTTONS.keys}, not #{button.class}"
94-
end
95-
end
96-
97-
def assert_direction(direction)
98-
raise ArgumentError, "#{direction.inspect} is not a valid button direction" unless DIRECTIONS.key? direction
99-
100-
DIRECTIONS[direction]
101-
end
102-
103-
def encode
104-
{type: type, button: @button}
105-
end
106-
end # PointerPress
107-
108-
class PointerMove < Interaction
109-
VIEWPORT = :viewport
110-
POINTER = :pointer
111-
ORIGINS = [VIEWPORT, POINTER].freeze
112-
113-
def initialize(source, duration, x, y, element: nil, origin: nil)
114-
super(source)
115-
@duration = duration * 1000
116-
@x_offset = x
117-
@y_offset = y
118-
@origin = element || origin || :viewport
119-
end
120-
121-
def type
122-
:pointerMove
123-
end
124-
125-
def encode
126-
{type: type, duration: @duration.to_i, x: @x_offset, y: @y_offset, origin: @origin}
127-
end
128-
end # PointerMove
129-
130-
class PointerCancel < Interaction
131-
def type
132-
:pointerCancel
133-
end
134-
135-
def encode
136-
{type: type}
137-
end
138-
end # PointerCancel
13967
end # Interactions
14068
end # WebDriver
14169
end # Selenium
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# frozen_string_literal: true
2+
3+
# Licensed to the Software Freedom Conservancy (SFC) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The SFC licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
module Selenium
21+
module WebDriver
22+
module Interactions
23+
class PointerMove < Interaction
24+
VIEWPORT = :viewport
25+
POINTER = :pointer
26+
ORIGINS = [VIEWPORT, POINTER].freeze
27+
28+
def initialize(source, duration, x, y, element: nil, origin: nil)
29+
super(source)
30+
@duration = duration * 1000
31+
@x_offset = x
32+
@y_offset = y
33+
@origin = element || origin || :viewport
34+
end
35+
36+
def type
37+
:pointerMove
38+
end
39+
40+
def encode
41+
{type: type, duration: @duration.to_i, x: @x_offset, y: @y_offset, origin: @origin}
42+
end
43+
end # PointerMove
44+
end # Interactions
45+
end # WebDriver
46+
end # Selenium
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# frozen_string_literal: true
2+
3+
# Licensed to the Software Freedom Conservancy (SFC) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The SFC licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
module Selenium
21+
module WebDriver
22+
module Interactions
23+
class PointerPress < Interaction
24+
BUTTONS = {left: 0, middle: 1, right: 2}.freeze
25+
DIRECTIONS = {down: :pointerDown, up: :pointerUp}.freeze
26+
27+
def initialize(source, direction, button)
28+
super(source)
29+
@direction = assert_direction(direction)
30+
@button = assert_button(button)
31+
end
32+
33+
def type
34+
@direction
35+
end
36+
37+
def assert_button(button)
38+
case button
39+
when Symbol
40+
raise ArgumentError, "#{button} is not a valid button!" unless BUTTONS.key? button
41+
42+
BUTTONS[button]
43+
when Integer
44+
raise ArgumentError, 'Button number cannot be negative!' if button.negative?
45+
46+
button
47+
else
48+
raise TypeError, "button must be a positive integer or one of #{BUTTONS.keys}, not #{button.class}"
49+
end
50+
end
51+
52+
def assert_direction(direction)
53+
raise ArgumentError, "#{direction.inspect} is not a valid button direction" unless DIRECTIONS.key? direction
54+
55+
DIRECTIONS[direction]
56+
end
57+
58+
def encode
59+
{type: type, button: @button}
60+
end
61+
end # PointerPress
62+
end # Interactions
63+
end # WebDriver
64+
end # Selenium
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# frozen_string_literal: true
2+
3+
# Licensed to the Software Freedom Conservancy (SFC) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The SFC licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
module Selenium
21+
module WebDriver
22+
module Interactions
23+
class TypingInteraction < Interaction
24+
attr_reader :type
25+
26+
def initialize(source, type, key)
27+
super(source)
28+
@type = assert_type(type)
29+
@key = Keys.encode_key(key)
30+
end
31+
32+
def assert_type(type)
33+
raise TypeError, "#{type.inspect} is not a valid key subtype" unless KeyInput::SUBTYPES.key? type
34+
35+
KeyInput::SUBTYPES[type]
36+
end
37+
38+
def encode
39+
{type: @type, value: @key}
40+
end
41+
end # TypingInteraction
42+
end # Interactions
43+
end # WebDriver
44+
end # Selenium

‎rb/spec/unit/selenium/webdriver/common/interactions/input_device_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def type
9999
expect(device.no_actions?).to be false
100100
end
101101
end
102-
end # InputDevice
102+
end
103103
end # Interactions
104104
end # WebDriver
105105
end # Selenium

0 commit comments

Comments
 (0)