Skip to content

Commit 7c78f9e

Browse files
committed
[rb] move input device encode method to superclass
1 parent fc5326f commit 7c78f9e

5 files changed

Lines changed: 7 additions & 21 deletions

File tree

rb/lib/selenium/webdriver/common/interactions/input_device.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ def no_actions? # Determine if only pauses are present
5555
actions = @actions.reject { |action| action.type == :pause }
5656
actions.empty?
5757
end
58+
59+
def encode
60+
{type: type, id: name, actions: @actions.map(&:encode)} unless no_actions?
61+
end
5862
end # InputDevice
5963
end # Interactions
6064
end # WebDriver

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ def type
3333
Interactions::KEY
3434
end
3535

36-
def encode
37-
return nil if no_actions?
38-
39-
{type: type, id: name, actions: @actions.map(&:encode)}
40-
end
41-
4236
def create_key_down(key)
4337
add_action(TypingInteraction.new(self, :down, key))
4438
end

rb/lib/selenium/webdriver/common/interactions/none_input.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ class NoneInput < InputDevice
3131
def type
3232
Interactions::NONE
3333
end
34-
35-
def encode
36-
return nil if no_actions?
37-
38-
{type: type, id: name, actions: @actions.map(&:encode)}
39-
end
4034
end # NoneInput
4135
end # Interactions
4236
end # WebDriver

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ def type
4141
end
4242

4343
def encode
44-
return nil if no_actions?
45-
46-
output = {type: type, id: name, actions: @actions.map(&:encode)}
47-
output[:parameters] = {pointerType: kind}
44+
output = super
45+
output[:parameters] = {pointerType: kind} if output
4846
output
4947
end
5048

rb/spec/unit/selenium/webdriver/common/interactions/interaction_spec.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ def type
2727
:special
2828
end
2929

30-
def encode
31-
{type: type, name: name, actions: @actions.map(&:encode)}
32-
end
33-
3430
def create_special(val)
3531
add_action(NewInteraction.new(self, val))
3632
end
@@ -77,7 +73,7 @@ def special_input(device = nil)
7773
sub_action_builder.special_action('special').perform
7874

7975
expect(bridge).to have_received(:send_actions).with([{type: :special,
80-
name: 'new',
76+
id: 'new',
8177
actions: [{type: :newType,
8278
special: 'special'}]}])
8379
end

0 commit comments

Comments
 (0)