Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/common/interactions/interaction_spec.rb
1865 views
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
require File.expand_path('../../spec_helper', __dir__)
21
22
module Selenium
23
module WebDriver
24
module Interactions
25
class NewDevice < InputDevice
26
def initialize(name = nil)
27
super
28
@type = :special
29
end
30
31
def create_special(val)
32
add_action(NewInteraction.new(self, val))
33
end
34
end
35
36
class NewInteraction < Interaction
37
def initialize(source, special)
38
super(source)
39
@special = special
40
@type = :newType
41
end
42
43
def assert_source(source)
44
raise TypeError, "#{source.type} is not a valid input type" unless source.is_a? NewDevice
45
end
46
47
def encode
48
{type: type, special: @special}
49
end
50
end
51
52
class SubActionBuilder < ActionBuilder
53
def special_action(special, device: nil)
54
special_input(device).create_special(special)
55
self
56
end
57
58
private
59
60
def special_input(name = nil)
61
device(name: name, type: :newType) || add_input(NewDevice.new('new'))
62
end
63
end
64
65
describe Interaction do
66
it 'can create subclass' do
67
bridge = instance_double(Remote::Bridge)
68
allow(bridge).to receive(:send_actions)
69
sub_action_builder = SubActionBuilder.new(bridge)
70
sub_action_builder.special_action('special').perform
71
72
expect(bridge).to have_received(:send_actions).with([{type: :special,
73
id: 'new',
74
actions: [{type: :newType,
75
special: 'special'}]}])
76
end
77
78
it 'raises a NotImplementedError if not a subclass' do
79
expect { described_class.new(NoneInput.new) }.to raise_error(NotImplementedError)
80
end
81
end
82
end # Interactions
83
end # WebDriver
84
end # Selenium
85
86