domkey 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/domkey/version.rb +1 -1
- data/lib/domkey/view.rb +7 -7
- data/lib/domkey/view/{cargo.rb → binder.rb} +12 -12
- data/lib/domkey/view/option_selectable.rb +13 -22
- data/lib/domkey/view/option_selectable_group.rb +10 -11
- data/lib/domkey/view/page_object.rb +17 -0
- data/lib/domkey/view/select_list.rb +16 -30
- data/spec/{view_cargo_spec.rb → binder_spec.rb} +18 -18
- data/spec/option_selectable_spec.rb +87 -29
- data/spec/page_object_delegates_spec.rb +30 -0
- data/spec/select_list_spec.rb +104 -95
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e93f5beddbdb0fad6ae8e499a06a46dc177c23b3
|
4
|
+
data.tar.gz: 4a77a3c0434d61e3ce656babba4abfdfe2eb9853
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cc26e517caf10802fc411947b2de31ea5dc2ca06d6b4467fd8a4a81bc5f21ce7443f5dc17baac0836a84a193f630f028fae9375b550837660d6c5fe490ca1ab
|
7
|
+
data.tar.gz: 88deffe102eb2fa60e364cf7a59bdbd07b81997a54dda072d56653702f757909622fe77c9e3ffe55f8194136f18d915899fac384988fb019fa62e392a2b3ac41
|
data/lib/domkey/version.rb
CHANGED
data/lib/domkey/view.rb
CHANGED
@@ -3,7 +3,7 @@ require 'domkey/view/page_object_collection'
|
|
3
3
|
require 'domkey/view/radio_group'
|
4
4
|
require 'domkey/view/checkbox_group'
|
5
5
|
require 'domkey/view/select_list'
|
6
|
-
require 'domkey/view/
|
6
|
+
require 'domkey/view/binder'
|
7
7
|
|
8
8
|
module Domkey
|
9
9
|
|
@@ -25,10 +25,10 @@ module Domkey
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
# build
|
29
|
-
# @return [Domkey::View::
|
30
|
-
def
|
31
|
-
|
28
|
+
# build Binder with model and view
|
29
|
+
# @return [Domkey::View::Binder]
|
30
|
+
def binder model, browser: nil
|
31
|
+
Binder.new model: model, view: self.new(browser)
|
32
32
|
end
|
33
33
|
|
34
34
|
end
|
@@ -52,7 +52,7 @@ module Domkey
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def set value
|
55
|
-
|
55
|
+
Binder.new(model: value, view: self).set
|
56
56
|
end
|
57
57
|
|
58
58
|
# @param [Hash{Symbol => Object}] view data where Symbol is semantic descriptor for a pageobject in the view
|
@@ -71,7 +71,7 @@ module Domkey
|
|
71
71
|
when Hash
|
72
72
|
value
|
73
73
|
end
|
74
|
-
|
74
|
+
Binder.new(model: value, view: self).value
|
75
75
|
end
|
76
76
|
|
77
77
|
end
|
@@ -2,11 +2,11 @@ module Domkey
|
|
2
2
|
|
3
3
|
module View
|
4
4
|
|
5
|
-
# Data
|
5
|
+
# Data transfer facilitator for the view
|
6
6
|
# Sends data to view. Grabs data from view
|
7
|
-
#
|
8
|
-
# For specialized transfer object a client would sublcass this
|
9
|
-
# by default View.
|
7
|
+
# Data is a model of the view
|
8
|
+
# For specialized transfer object a client would sublcass this Binder,
|
9
|
+
# by default View.binder factory method is provided for regular data transfer object
|
10
10
|
#
|
11
11
|
# @usage
|
12
12
|
#
|
@@ -20,21 +20,21 @@ module Domkey
|
|
20
20
|
# end
|
21
21
|
# end
|
22
22
|
#
|
23
|
-
# model
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
23
|
+
# model = {city: 'Austin', fruit: 'tomato'}
|
24
|
+
# binder = MyView.binder model
|
25
|
+
# binder.set #=> sets view.city with model[:city] and view.fruit with view_model[:fruit]
|
26
|
+
# binder.value #=> returns {city: 'Austing', fruit: 'tomato'}
|
27
27
|
#
|
28
|
-
# class
|
28
|
+
# class MyBinder < Domkey::View::Binder
|
29
29
|
#
|
30
30
|
# end
|
31
31
|
#
|
32
32
|
# model = {city: 'Mordor'}
|
33
33
|
# view = MyView.new
|
34
|
-
#
|
35
|
-
#
|
34
|
+
# binder = MyBinder.new view: view, model: model
|
35
|
+
# binder.set
|
36
36
|
#
|
37
|
-
class
|
37
|
+
class Binder
|
38
38
|
|
39
39
|
attr_accessor :view, :model
|
40
40
|
|
@@ -4,7 +4,7 @@ module Domkey
|
|
4
4
|
|
5
5
|
# clears all options and sets only the desired value(s)
|
6
6
|
# @param [String, Regexp] sets default designated option by String or Regexp
|
7
|
-
# @param [Array<String, Regexp>]
|
7
|
+
# @param [Array<String, Regexp>] set more than one option by default strategy
|
8
8
|
# @param [False] unselects all options
|
9
9
|
# @param [Hash{how => value}] selects by how strategy where how is a symbol :label, :index, :text, :value
|
10
10
|
# Clients need to implement individual strategy for each 'how' => 'value' pair based on what it means to be selected by what
|
@@ -13,17 +13,17 @@ module Domkey
|
|
13
13
|
set_strategy value
|
14
14
|
end
|
15
15
|
|
16
|
-
# @param []
|
17
|
-
# @return [Array<String>]
|
18
|
-
# @param [Symbol,Array<Symbol>]
|
19
|
-
# @return [Array<Hash{what => value}]
|
16
|
+
# @param opts [Symbol, Array<Symbol>] defaults to empty []. Represents a qualifier how to present selected options.
|
17
|
+
# @return [Array<String>] When opts param empty? array of default strings implemented by client as a presentation of options selected
|
18
|
+
# @param opts [Symbol,Array<Symbol>] ask for representation of options by 'what'
|
19
|
+
# @return [Array<Hash{what => value}] Whe opts is a list of symbols :index, :value, :text, :label corresponding to 'what' key
|
20
20
|
def value *opts
|
21
21
|
opts = opts.flatten
|
22
22
|
return value_by_default if (opts.empty? || opts.find { |e| e.kind_of?(String) })
|
23
23
|
value_by_options opts
|
24
24
|
end
|
25
25
|
|
26
|
-
#
|
26
|
+
# @see +value+ returns all options and not only selected ones
|
27
27
|
def options *opts
|
28
28
|
opts = opts.flatten
|
29
29
|
return options_by_default if opts.empty?
|
@@ -55,19 +55,15 @@ module Domkey
|
|
55
55
|
# strategy for selecting OptionSelectable object
|
56
56
|
def set_strategy value
|
57
57
|
case value
|
58
|
-
when String
|
59
|
-
|
60
|
-
when Regexp
|
61
|
-
set_by_regexp(value)
|
58
|
+
when String, Regexp
|
59
|
+
set_by_value(value)
|
62
60
|
when Array
|
63
61
|
value.each { |v| set_strategy(v) }
|
64
62
|
when Hash
|
65
63
|
value.each_pair do |how, value|
|
66
64
|
case how
|
67
|
-
when :label
|
65
|
+
when :label, :text
|
68
66
|
set_by_label(value)
|
69
|
-
when :text
|
70
|
-
set_strategy(value)
|
71
67
|
when :index
|
72
68
|
set_by_index(value)
|
73
69
|
when :value
|
@@ -77,26 +73,21 @@ module Domkey
|
|
77
73
|
end
|
78
74
|
end
|
79
75
|
|
80
|
-
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
def set_by_regexp value
|
76
|
+
# default strategy. set by value attribute
|
77
|
+
def set_by_value value
|
85
78
|
fail Exception::NotImplementedError, "Subclass responsible for implementing"
|
86
79
|
end
|
87
80
|
|
81
|
+
# by visible text, label of the control
|
88
82
|
def set_by_label value
|
89
83
|
fail Exception::NotImplementedError, "Subclass responsible for implementing"
|
90
84
|
end
|
91
85
|
|
86
|
+
# set by position in an index of options
|
92
87
|
def set_by_index value
|
93
88
|
fail Exception::NotImplementedError, "Subclass responsible for implementing"
|
94
89
|
end
|
95
90
|
|
96
|
-
def set_by_value value
|
97
|
-
fail Exception::NotImplementedError, "Subclass responsible for implementing"
|
98
|
-
end
|
99
|
-
|
100
91
|
end
|
101
92
|
end
|
102
93
|
end
|
@@ -10,26 +10,25 @@ module Domkey
|
|
10
10
|
include OptionSelectable
|
11
11
|
|
12
12
|
def set_by_index value
|
13
|
-
[*value].each
|
14
|
-
self[i.to_i].set(true)
|
15
|
-
end
|
13
|
+
[*value].each { |i| self[i.to_i].set(true) }
|
16
14
|
end
|
17
15
|
|
18
16
|
def set_by_label value
|
19
17
|
to_labeled.__send__(:set_strategy, value)
|
20
18
|
end
|
21
19
|
|
22
|
-
def
|
23
|
-
o =
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
20
|
+
def set_by_value value
|
21
|
+
o = case value
|
22
|
+
when String
|
23
|
+
find { |o| o.value == value }
|
24
|
+
when Regexp
|
25
|
+
find { |o| o.value.match(value) }
|
26
|
+
else
|
27
|
+
false
|
28
|
+
end
|
29
29
|
o ? o.element.set : fail(Exception::NotFoundError, "Element not found with value: #{v.inspect}")
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
32
|
def value_by_default
|
34
33
|
validate_scope
|
35
34
|
find_all { |e| e.element.set? }.map { |e| e.value }
|
@@ -77,6 +77,23 @@ module Domkey
|
|
77
77
|
Hash[package.map { |key, pageobject| [key, pageobject.options] }]
|
78
78
|
end
|
79
79
|
|
80
|
+
|
81
|
+
# @api private
|
82
|
+
# delegate to element when element responds to message
|
83
|
+
def method_missing(message, *args, &block)
|
84
|
+
if respond_to_missing?(message, false)
|
85
|
+
element.__send__(message, *args, &block)
|
86
|
+
else
|
87
|
+
super
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# @api private
|
92
|
+
# ruturn true when element.respond_to? message so we can delegate with confidence
|
93
|
+
def respond_to_missing?(message, include_private = false)
|
94
|
+
element.respond_to?(message) ? true : false
|
95
|
+
end
|
96
|
+
|
80
97
|
private
|
81
98
|
|
82
99
|
# wrap instantiator with strategy for setting and getting value for underlying object
|
@@ -7,32 +7,19 @@ module Domkey
|
|
7
7
|
|
8
8
|
include OptionSelectable
|
9
9
|
|
10
|
-
|
11
|
-
element.select value
|
12
|
-
end
|
13
|
-
|
14
|
-
def set_by_regexp value
|
15
|
-
element.select value
|
16
|
-
end
|
17
|
-
|
10
|
+
# by position in options array
|
18
11
|
def set_by_index value
|
19
|
-
|
20
|
-
when Fixnum
|
21
|
-
element.options[value].select
|
22
|
-
when Array
|
23
|
-
value.each do |i|
|
24
|
-
element.options[i].select
|
25
|
-
end
|
26
|
-
end
|
12
|
+
[*value].each { |i| element.options[i].select }
|
27
13
|
end
|
28
14
|
|
15
|
+
# by value attribute of the option
|
29
16
|
def set_by_value value
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
17
|
+
[*value].each { |v| element.select_value(v) }
|
18
|
+
end
|
19
|
+
|
20
|
+
# by visible text for the option (visible to the user)
|
21
|
+
def set_by_label value
|
22
|
+
[*value].each { |v| element.select(v) }
|
36
23
|
end
|
37
24
|
|
38
25
|
def value_by_options opts
|
@@ -42,21 +29,20 @@ module Domkey
|
|
42
29
|
end
|
43
30
|
|
44
31
|
def value_by_default
|
45
|
-
element.selected_options.map { |e| e.
|
32
|
+
element.selected_options.map { |e| e.value }
|
33
|
+
end
|
34
|
+
|
35
|
+
def options_by_default
|
36
|
+
element.options.map { |e| e.value }
|
46
37
|
end
|
47
38
|
|
48
|
-
|
49
|
-
def options
|
39
|
+
def options_by opts
|
50
40
|
element.options.map do |o|
|
51
|
-
{
|
52
|
-
value: o.value,
|
53
|
-
index: o.index}
|
41
|
+
Hash[opts.map { |opt| [opt, o.send(opt)] }]
|
54
42
|
end
|
55
43
|
end
|
56
44
|
|
57
45
|
|
58
|
-
private
|
59
|
-
|
60
46
|
def before_set
|
61
47
|
element.clear if element.multiple?
|
62
48
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Domkey::View::
|
3
|
+
describe Domkey::View::Binder do
|
4
4
|
|
5
5
|
class AddressView
|
6
6
|
include Domkey::View
|
@@ -43,9 +43,9 @@ describe Domkey::View::Cargo do
|
|
43
43
|
model = {city: 'Austin',
|
44
44
|
street: 'Lamar'}
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
extracted =
|
46
|
+
binder = Domkey::View::Binder.new model: model, view: AddressView.new
|
47
|
+
binder.set
|
48
|
+
extracted = binder.value
|
49
49
|
extracted.should eql model
|
50
50
|
end
|
51
51
|
|
@@ -56,9 +56,9 @@ describe Domkey::View::Cargo do
|
|
56
56
|
street: 'Austin'}
|
57
57
|
}
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
extracted =
|
59
|
+
binder = Domkey::View::Binder.new model: model, view: AddressView.new
|
60
|
+
binder.set
|
61
|
+
extracted = binder.value
|
62
62
|
extracted.should eql model
|
63
63
|
end
|
64
64
|
|
@@ -71,19 +71,19 @@ describe Domkey::View::Cargo do
|
|
71
71
|
delivery_date: {month: 'delivery thing'}}
|
72
72
|
}
|
73
73
|
|
74
|
-
|
75
|
-
|
76
|
-
extracted =
|
74
|
+
binder = Domkey::View::Binder.new model: model, view: AddressView.new
|
75
|
+
binder.set
|
76
|
+
extracted = binder.value
|
77
77
|
extracted.should eql model
|
78
78
|
end
|
79
79
|
|
80
|
-
it '
|
80
|
+
it 'binder' do
|
81
81
|
model = {city: 'Mordor'}
|
82
82
|
|
83
83
|
view = AddressView.new
|
84
|
-
|
85
|
-
|
86
|
-
scraped_model =
|
84
|
+
binder = Domkey::View::Binder.new view: view, model: model
|
85
|
+
binder.set
|
86
|
+
scraped_model = binder.value
|
87
87
|
|
88
88
|
scraped_model.should eql model
|
89
89
|
end
|
@@ -91,14 +91,14 @@ describe Domkey::View::Cargo do
|
|
91
91
|
it 'pageobject' do
|
92
92
|
|
93
93
|
model = {city: 'Austin', fruit: ['tomato', 'other']}
|
94
|
-
|
94
|
+
binder = AddressView.binder model
|
95
95
|
|
96
96
|
# default values when page loads before setting the values
|
97
97
|
default_page_values = {:city=>"id city class city", :fruit=>["other"]}
|
98
|
-
|
99
|
-
|
98
|
+
binder.value.should eql default_page_values
|
99
|
+
binder.set
|
100
100
|
|
101
|
-
extracted_model =
|
101
|
+
extracted_model = binder.value
|
102
102
|
extracted_model.should eql model
|
103
103
|
|
104
104
|
end
|
@@ -10,48 +10,106 @@ describe Domkey::View::OptionSelectable do
|
|
10
10
|
@widget = OptionSelectableFaker.new
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
context 'set' do
|
14
|
+
|
15
|
+
it 'set string' do
|
16
|
+
expect(@widget).to receive(:set_by_value)
|
17
|
+
@widget.set('fake')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'set regex' do
|
21
|
+
expect(@widget).to receive(:set_by_value)
|
22
|
+
@widget.set(/fake/)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'set :value' do
|
26
|
+
expect(@widget).to receive(:set_by_value)
|
27
|
+
@widget.set(:value => 'fake')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'set :label' do
|
31
|
+
expect(@widget).to receive(:set_by_label)
|
32
|
+
@widget.set(:label => 'fake')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'set :text' do
|
36
|
+
expect(@widget).to receive(:set_by_label)
|
37
|
+
@widget.set(:text => 'fake')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'set :index' do
|
41
|
+
expect(@widget).to receive(:set_by_index)
|
42
|
+
@widget.set(:index => 3)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'string' do
|
46
|
+
expect { @widget.set('fake') }.to raise_error(Domkey::Exception::NotImplementedError)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'regex' do
|
50
|
+
expect { @widget.set(/fake/) }.to raise_error(Domkey::Exception::NotImplementedError)
|
51
|
+
end
|
52
|
+
|
53
|
+
it ':label' do
|
54
|
+
expect { @widget.set(:label => 'fake') }.to raise_error(Domkey::Exception::NotImplementedError)
|
55
|
+
end
|
56
|
+
|
57
|
+
it ':text' do
|
58
|
+
expect { @widget.set(:text => 'fake') }.to raise_error(Domkey::Exception::NotImplementedError)
|
59
|
+
end
|
60
|
+
|
61
|
+
it ':index' do
|
62
|
+
expect { @widget.set(:index => 3) }.to raise_error(Domkey::Exception::NotImplementedError)
|
63
|
+
end
|
64
|
+
|
65
|
+
it ':value' do
|
66
|
+
expect { @widget.set(:value => 'fake') }.to raise_error(Domkey::Exception::NotImplementedError)
|
67
|
+
end
|
16
68
|
|
17
|
-
it 'set regex' do
|
18
|
-
expect { @widget.set(/fake/) }.to raise_error(Domkey::Exception::NotImplementedError)
|
19
69
|
end
|
20
70
|
|
21
|
-
|
22
|
-
expect { @widget.set(:label => 'fake') }.to raise_error(Domkey::Exception::NotImplementedError)
|
23
|
-
end
|
71
|
+
context 'value' do
|
24
72
|
|
25
|
-
|
26
|
-
|
27
|
-
|
73
|
+
it 'value default' do
|
74
|
+
expect(@widget).to receive(:value_by_default)
|
75
|
+
@widget.value
|
76
|
+
end
|
28
77
|
|
29
|
-
|
30
|
-
|
31
|
-
|
78
|
+
it 'value option' do
|
79
|
+
expect(@widget).to receive(:value_by_options)
|
80
|
+
@widget.value(:foo)
|
81
|
+
end
|
32
82
|
|
33
|
-
|
34
|
-
|
35
|
-
|
83
|
+
it 'default' do
|
84
|
+
expect { @widget.value }.to raise_error(Domkey::Exception::NotImplementedError)
|
85
|
+
end
|
36
86
|
|
37
|
-
|
38
|
-
|
39
|
-
|
87
|
+
it 'option' do
|
88
|
+
expect { @widget.value(:foo) }.to raise_error(Domkey::Exception::NotImplementedError)
|
89
|
+
end
|
40
90
|
|
41
|
-
it 'value option' do
|
42
|
-
expect { @widget.value(:foo) }.to raise_error(Domkey::Exception::NotImplementedError)
|
43
|
-
end
|
44
91
|
|
45
|
-
it 'options default' do
|
46
|
-
expect { @widget.options }.to raise_error(Domkey::Exception::NotImplementedError)
|
47
92
|
end
|
48
93
|
|
49
|
-
|
50
|
-
expect { @widget.options(:foo) }.to raise_error(Domkey::Exception::NotImplementedError)
|
51
|
-
end
|
94
|
+
context 'options' do
|
52
95
|
|
53
|
-
|
96
|
+
it 'options default' do
|
97
|
+
expect(@widget).to receive(:options_by_default)
|
98
|
+
@widget.options
|
99
|
+
end
|
54
100
|
|
101
|
+
it 'options opt' do
|
102
|
+
expect(@widget).to receive(:options_by)
|
103
|
+
@widget.options(:foo)
|
104
|
+
end
|
55
105
|
|
106
|
+
it 'default' do
|
107
|
+
expect { @widget.options }.to raise_error(Domkey::Exception::NotImplementedError)
|
108
|
+
end
|
56
109
|
|
110
|
+
it 'opts' do
|
111
|
+
expect { @widget.options(:foo) }.to raise_error(Domkey::Exception::NotImplementedError)
|
112
|
+
end
|
57
113
|
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# methods each pageobject should have
|
4
|
+
# set value options elements
|
5
|
+
|
6
|
+
describe Domkey::View::PageObject do
|
7
|
+
|
8
|
+
before :all do
|
9
|
+
goto_html("test.html")
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'delegate to element for missing methods' do
|
13
|
+
before :all do
|
14
|
+
@o = Domkey::View::PageObject.new -> { text_field(id: 'city1') }
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should delegate to element when element responds' do
|
18
|
+
@o.should respond_to(:id)
|
19
|
+
@o.id.should eql 'city1'
|
20
|
+
|
21
|
+
@o.should respond_to(:click)
|
22
|
+
@o.click
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should not delegate to element when element does not repsond' do
|
26
|
+
@o.should_not respond_to(:textaramabada)
|
27
|
+
expect { @o.textaramabada }.to raise_error(NoMethodError)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/spec/select_list_spec.rb
CHANGED
@@ -28,14 +28,14 @@ describe Domkey::View::SelectList do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'initial value on the test page' do
|
31
|
-
@widget.value.should eql ["
|
31
|
+
@widget.value.should eql ["2", "3"]
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'initial value by keys on the test page' do
|
35
35
|
# array
|
36
36
|
@widget.value([:index, :text, :value]).should eql [{:index=>1, :text=>"English", :value=>"2"}, {:index=>2, :text=>"Norwegian", :value=>"3"}]
|
37
37
|
# splat list
|
38
|
-
@widget.value(:index, :
|
38
|
+
@widget.value(:index, :label).should eql [{:index=>1, :label=>"English"}, {:index=>2, :label=>"Norwegian"}]
|
39
39
|
|
40
40
|
# one element array
|
41
41
|
@widget.value([:index]).should eql [{:index=>1}, {:index=>2}]
|
@@ -44,14 +44,14 @@ describe Domkey::View::SelectList do
|
|
44
44
|
|
45
45
|
end
|
46
46
|
|
47
|
-
it 'set string' do
|
48
|
-
@widget.set '
|
47
|
+
it 'set value string' do
|
48
|
+
@widget.set '1'
|
49
|
+
@widget.value.should eql ['1']
|
49
50
|
end
|
50
51
|
|
51
|
-
it 'set array string
|
52
|
-
|
53
|
-
@widget.
|
54
|
-
@widget.value.should eql ["Norwegian", "Polish"]
|
52
|
+
it 'set value array string' do
|
53
|
+
@widget.set ['1', '3']
|
54
|
+
@widget.value.should eql ['1', '3']
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'set false clears all. value is empty array' do
|
@@ -64,149 +64,158 @@ describe Domkey::View::SelectList do
|
|
64
64
|
@widget.value.should eql []
|
65
65
|
end
|
66
66
|
|
67
|
-
it 'set string clears all. sets one text item. value is one item' do
|
68
|
-
@widget.set 'Polish'
|
69
|
-
@widget.value.should eql ["Polish"]
|
70
|
-
end
|
71
|
-
|
72
67
|
it 'set string' do
|
73
68
|
@widget.set text: 'Polish'
|
74
|
-
@widget.value.should eql ["
|
69
|
+
@widget.value.should eql [""] #option has no value attribute defined
|
75
70
|
end
|
76
71
|
|
77
72
|
it 'set regexp' do
|
78
|
-
@widget.set
|
79
|
-
@widget.value.should eql ["
|
73
|
+
@widget.set /2/
|
74
|
+
@widget.value.should eql ["2"]
|
80
75
|
end
|
81
76
|
|
82
77
|
it 'set by array of texts' do
|
83
78
|
@widget.set text: ['Polish', /orwegia/]
|
84
|
-
@widget.value.should eql ["
|
79
|
+
@widget.value.should eql ["3", ""]
|
85
80
|
end
|
86
81
|
|
87
82
|
it 'set index by option position' do
|
88
83
|
@widget.set index: 1
|
89
|
-
@widget.value.should eql ['
|
84
|
+
@widget.value.should eql ['2']
|
90
85
|
@widget.value(:index, :value).should eql [{index: 1, value: '2'}]
|
91
86
|
end
|
92
87
|
|
93
88
|
it 'set index array of option positions' do
|
94
89
|
@widget.set index: [0, 2]
|
95
|
-
@widget.value.should eql ["
|
90
|
+
@widget.value.should eql ["1", "3"]
|
96
91
|
end
|
97
92
|
|
98
93
|
it 'set value attribute string' do
|
99
94
|
@widget.set value: '2'
|
100
|
-
@widget.value.should eql ['
|
95
|
+
@widget.value.should eql ['2']
|
101
96
|
end
|
102
97
|
|
103
98
|
it 'set value attribute array of strings' do
|
104
99
|
@widget.set value: ['2', '1']
|
105
|
-
@widget.value.should eql ["
|
100
|
+
@widget.value.should eql ["1", "2"]
|
106
101
|
end
|
107
102
|
|
108
103
|
it 'set by many qualifiers at once' do
|
109
104
|
@widget.set value: ['2', '1'],
|
110
105
|
text: 'Swedish',
|
111
106
|
index: 3
|
112
|
-
@widget.value.should eql [
|
107
|
+
@widget.value.should eql ["1", "2", "", "Swedish"]
|
113
108
|
end
|
114
109
|
|
115
|
-
it 'options' do
|
116
|
-
@widget.options.should eql [
|
117
|
-
{:text=>"English", :value=>"2", :index=>1},
|
118
|
-
{:text=>"Norwegian", :value=>"3", :index=>2},
|
119
|
-
{:text=>"Polish", :value=>"", :index=>3},
|
120
|
-
{:text=>"Swedish", :value=>"Swedish", :index=>4}]
|
110
|
+
it 'options by default' do
|
111
|
+
@widget.options.should eql ["1", "2", "3", "", "Swedish"]
|
121
112
|
end
|
122
113
|
|
123
|
-
|
114
|
+
it 'options by opts' do
|
124
115
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
116
|
+
expected = [{:text=>"Danish", :value=>"1", :index=>0},
|
117
|
+
{:text=>"English", :value=>"2", :index=>1},
|
118
|
+
{:text=>"Norwegian", :value=>"3", :index=>2},
|
119
|
+
{:text=>"Polish", :value=>"", :index=>3},
|
120
|
+
{:text=>"Swedish", :value=>"Swedish", :index=>4}]
|
129
121
|
|
130
|
-
|
131
|
-
|
132
|
-
|
122
|
+
@widget.options(:text, :value, :index).should eql expected
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context "Single" do
|
128
|
+
|
129
|
+
before :all do
|
130
|
+
view = SelectListExampleView.new
|
131
|
+
@widget = view.singlelist
|
132
|
+
end
|
133
133
|
|
134
|
-
|
135
|
-
|
136
|
-
|
134
|
+
before :each do
|
135
|
+
goto_html("test.html")
|
136
|
+
end
|
137
137
|
|
138
|
-
|
139
|
-
|
140
|
-
|
138
|
+
it 'initial value' do
|
139
|
+
@widget.value.should eql ['Default']
|
140
|
+
end
|
141
141
|
|
142
|
-
|
143
|
-
|
144
|
-
|
142
|
+
it 'value keys' do
|
143
|
+
@widget.value([:index, :value, :text]).should eql [{index: 3, value: 'Default', text: 'Default'}]
|
144
|
+
end
|
145
145
|
|
146
|
-
|
147
|
-
|
148
|
-
|
146
|
+
it 'set string selects value' do
|
147
|
+
@widget.set 'tomato'
|
148
|
+
@widget.value.should eql ['tomato']
|
149
149
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
end
|
150
|
+
@widget.set 'gurken'
|
151
|
+
@widget.value.should eql ['gurken']
|
152
|
+
end
|
154
153
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
154
|
+
it 'set when value not present should error' do
|
155
|
+
expect { @widget.set '' }.to raise_error(Watir::Exception::NoValueFoundException)
|
156
|
+
@widget.value.should eql ['Default'] #interesting quirk
|
157
|
+
end
|
159
158
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
159
|
+
it 'set array of text' do
|
160
|
+
@widget.set ['gurken', 'tomato'] #cycle on single select list
|
161
|
+
@widget.value.should eql ['tomato'] # the last one set
|
162
|
+
end
|
164
163
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
164
|
+
it 'set by array of text' do
|
165
|
+
@widget.set text: ['Other', 'Tomato']
|
166
|
+
@widget.value.should eql ['tomato']
|
167
|
+
end
|
169
168
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
169
|
+
it 'set false has no effect. value is selected item text' do
|
170
|
+
@widget.set false
|
171
|
+
@widget.value.should eql ['Default']
|
172
|
+
end
|
174
173
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
174
|
+
it 'set empty array has no effect. value is selected item text' do
|
175
|
+
@widget.set []
|
176
|
+
@widget.value.should eql ['Default']
|
177
|
+
end
|
179
178
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
179
|
+
it 'set index position' do
|
180
|
+
@widget.set index: 1
|
181
|
+
@widget.value.should eql ['gurken']
|
182
|
+
end
|
184
183
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
184
|
+
it 'set index array' do
|
185
|
+
@widget.set index: [2, 1]
|
186
|
+
@widget.value.should eql ['gurken'] # the last one wins
|
187
|
+
end
|
189
188
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
@widget.value.should eql ['Other']
|
195
|
-
end
|
189
|
+
it 'set value attribute string' do
|
190
|
+
@widget.set value: 'tomato'
|
191
|
+
@widget.value.should eql ['tomato']
|
192
|
+
end
|
196
193
|
|
197
|
-
|
194
|
+
it 'set value attribute array of strings' do
|
195
|
+
@widget.set value: ['tomato', 'gurken']
|
196
|
+
@widget.value.should eql ['gurken']
|
197
|
+
end
|
198
198
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
199
|
+
it 'set by many qualifiers at once' do
|
200
|
+
@widget.set value: ['gurken'],
|
201
|
+
text: 'Tomato',
|
202
|
+
index: 2
|
203
|
+
@widget.value.should eql ['']
|
204
|
+
end
|
203
205
|
|
204
|
-
|
206
|
+
it 'options default' do
|
205
207
|
|
206
|
-
|
208
|
+
@widget.options.should eql ['tomato', 'gurken', '', 'Default']
|
207
209
|
|
208
210
|
end
|
209
211
|
|
210
|
-
|
212
|
+
it 'options by specifiers' do
|
213
|
+
expected = [{:text=>"Tomato", :value=>"tomato", :index=>0},
|
214
|
+
{:text=>"Cucumber", :value=>"gurken", :index=>1},
|
215
|
+
{:text=>"Other", :value=>"", :index=>2},
|
216
|
+
{:text=>"Default", :value=>"Default", :index=>3}]
|
211
217
|
|
212
|
-
|
218
|
+
@widget.options(:text, :value, :index).should eql expected
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: domkey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rubytester
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: watir-webdriver
|
@@ -103,7 +103,7 @@ files:
|
|
103
103
|
- lib/domkey/exception.rb
|
104
104
|
- lib/domkey/version.rb
|
105
105
|
- lib/domkey/view.rb
|
106
|
-
- lib/domkey/view/
|
106
|
+
- lib/domkey/view/binder.rb
|
107
107
|
- lib/domkey/view/checkbox_group.rb
|
108
108
|
- lib/domkey/view/label_mapper.rb
|
109
109
|
- lib/domkey/view/labeled_group.rb
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/domkey/view/select_list.rb
|
116
116
|
- lib/domkey/view/widgetry/dispatcher.rb
|
117
117
|
- lib/domkey/view/widgetry/package.rb
|
118
|
+
- spec/binder_spec.rb
|
118
119
|
- spec/browser_spec.rb
|
119
120
|
- spec/checkbox_group_spec.rb
|
120
121
|
- spec/html/test.html
|
@@ -122,13 +123,13 @@ files:
|
|
122
123
|
- spec/option_selectable_spec.rb
|
123
124
|
- spec/page_object_collection_spec.rb
|
124
125
|
- spec/page_object_decorators_spec.rb
|
126
|
+
- spec/page_object_delegates_spec.rb
|
125
127
|
- spec/page_object_spec.rb
|
126
128
|
- spec/page_spec.rb
|
127
129
|
- spec/radio_group_spec.rb
|
128
130
|
- spec/select_list_spec.rb
|
129
131
|
- spec/selenium_webdriver_api_example.rb
|
130
132
|
- spec/spec_helper.rb
|
131
|
-
- spec/view_cargo_spec.rb
|
132
133
|
- spec/view_dom_spec.rb
|
133
134
|
- spec/view_doms_spec.rb
|
134
135
|
- spec/watirspec_pageobjects/watirspec_spec.rb
|
@@ -157,6 +158,7 @@ signing_key:
|
|
157
158
|
specification_version: 4
|
158
159
|
summary: Domain Specifc PageObject for Selenium Watir-Webdriver
|
159
160
|
test_files:
|
161
|
+
- spec/binder_spec.rb
|
160
162
|
- spec/browser_spec.rb
|
161
163
|
- spec/checkbox_group_spec.rb
|
162
164
|
- spec/html/test.html
|
@@ -164,13 +166,13 @@ test_files:
|
|
164
166
|
- spec/option_selectable_spec.rb
|
165
167
|
- spec/page_object_collection_spec.rb
|
166
168
|
- spec/page_object_decorators_spec.rb
|
169
|
+
- spec/page_object_delegates_spec.rb
|
167
170
|
- spec/page_object_spec.rb
|
168
171
|
- spec/page_spec.rb
|
169
172
|
- spec/radio_group_spec.rb
|
170
173
|
- spec/select_list_spec.rb
|
171
174
|
- spec/selenium_webdriver_api_example.rb
|
172
175
|
- spec/spec_helper.rb
|
173
|
-
- spec/view_cargo_spec.rb
|
174
176
|
- spec/view_dom_spec.rb
|
175
177
|
- spec/view_doms_spec.rb
|
176
178
|
- spec/watirspec_pageobjects/watirspec_spec.rb
|