Skip to content

Commit a3da5e8

Browse files
committed
[rb] allow device names to use default random id
1 parent 8bf63e7 commit a3da5e8

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ module Interactions
2929
#
3030

3131
class << self
32-
def key(name)
32+
def key(name = nil)
3333
KeyInput.new(name)
3434
end
3535

36-
def pointer(kind, **kwargs)
37-
PointerInput.new(kind, **kwargs)
36+
def pointer(kind = :mouse, name: nil)
37+
PointerInput.new(kind, name: name)
3838
end
3939

4040
def none(name = nil)

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

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,58 @@
2222
module Selenium
2323
module WebDriver
2424
describe Interactions do
25-
it 'creates a new key input' do
26-
expect(Interactions.key(:name)).to be_a(Interactions::KeyInput)
25+
describe '#key' do
26+
it 'creates a new key input with provided name' do
27+
device = Interactions.key(:name)
28+
29+
expect(device).to be_a(Interactions::KeyInput)
30+
expect(device.name).to eq(:name)
31+
end
32+
33+
it 'sets name to a random UUID if no name is provided' do
34+
allow(SecureRandom).to receive(:uuid).and_return(:id)
35+
36+
device = Interactions.key
37+
38+
expect(device).to be_a(Interactions::KeyInput)
39+
expect(device.name).to eq(:id)
40+
end
2741
end
2842

29-
it 'creates a new pointer input' do
30-
expect(Interactions.pointer(:mouse)).to be_a(Interactions::PointerInput)
43+
describe '#pointer' do
44+
it 'creates a new pointer input with a provided name' do
45+
device = Interactions.pointer(:mouse, name: :name)
46+
47+
expect(device).to be_a(Interactions::PointerInput)
48+
expect(device.name).to eq(:name)
49+
end
50+
51+
it 'sets name to a random UUID if no name is provided' do
52+
allow(SecureRandom).to receive(:uuid).and_return(:id)
53+
54+
device = Interactions.pointer(:mouse)
55+
56+
expect(device).to be_a(Interactions::PointerInput)
57+
expect(device.name).to eq(:id)
58+
end
3159
end
3260

33-
it 'creates a new none input' do
34-
expect(Interactions.none).to be_a(Interactions::NoneInput)
61+
describe '#none' do
62+
it 'creates a new pointer input with a provided name' do
63+
device = Interactions.none(:name)
64+
65+
expect(device).to be_a(Interactions::NoneInput)
66+
expect(device.name).to eq(:name)
67+
end
68+
69+
it 'sets name to a random UUID if no name is provided' do
70+
allow(SecureRandom).to receive(:uuid).and_return(:id)
71+
72+
device = Interactions.none
73+
74+
expect(device).to be_a(Interactions::NoneInput)
75+
expect(device.name).to eq(:id)
76+
end
3577
end
3678
end
3779
end # WebDriver

0 commit comments

Comments
 (0)