domkey 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +3 -0
- data/README.md +2 -4
- data/Rakefile +4 -1
- data/lib/domkey/version.rb +1 -1
- data/lib/domkey/view.rb +42 -4
- data/lib/domkey/view/cargo.rb +92 -0
- data/lib/domkey/view/checkbox_group.rb +75 -0
- data/lib/domkey/view/label_mapper.rb +18 -0
- data/lib/domkey/view/labeled_group.rb +50 -0
- data/lib/domkey/view/page_object.rb +85 -85
- data/lib/domkey/view/page_object_collection.rb +31 -49
- data/lib/domkey/view/radio_group.rb +70 -0
- data/lib/domkey/view/watir_widget.rb +106 -0
- data/lib/domkey/view/widgetry_package.rb +48 -0
- data/spec/checkbox_group_spec.rb +81 -0
- data/spec/html/test.html +61 -5
- data/spec/labeled_group_spec.rb +118 -0
- data/spec/page_object_collection_spec.rb +14 -14
- data/spec/page_object_decorators_spec.rb +41 -52
- data/spec/page_object_spec.rb +23 -18
- data/spec/page_spec.rb +12 -12
- data/spec/radio_group_spec.rb +85 -0
- data/spec/selenium_webdriver_api_example.rb +42 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/view_cargo_spec.rb +106 -0
- data/spec/view_dom_spec.rb +50 -16
- data/spec/view_doms_spec.rb +7 -7
- data/spec/watir_widget_select_spec.rb +176 -0
- data/spec/watirspec_pageobjects/watirspec_spec.rb +12 -0
- metadata +24 -2
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Domkey::View::LabeledGroup do
|
4
|
+
|
5
|
+
class LabeledGroupExampleView
|
6
|
+
include Domkey::View
|
7
|
+
|
8
|
+
def radio_group
|
9
|
+
RadioGroup.new -> { radios(name: 'tool') }
|
10
|
+
end
|
11
|
+
|
12
|
+
#labeled radio_group with tool: as semantic descriptor
|
13
|
+
def tool
|
14
|
+
LabeledGroup.new(radio_group)
|
15
|
+
end
|
16
|
+
|
17
|
+
def checkbox_group
|
18
|
+
CheckboxGroup.new -> { checkboxes(name: 'fruit') }
|
19
|
+
end
|
20
|
+
|
21
|
+
#labeled checkbox_group with fruit: as semantic descriptor
|
22
|
+
def fruit
|
23
|
+
LabeledGroup.new(checkbox_group)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:view) { LabeledGroupExampleView.new }
|
28
|
+
|
29
|
+
before :all do
|
30
|
+
goto_html("test.html")
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'radio group' do
|
34
|
+
|
35
|
+
context 'wrapped directly' do
|
36
|
+
|
37
|
+
it 'set string' do
|
38
|
+
view.tool.set 'Tomato'
|
39
|
+
view.tool.value.should eql ['Tomato']
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'set regex' do
|
43
|
+
view.tool.set /umber$/
|
44
|
+
view.tool.value.should eql ['Cucumber']
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'set array' do
|
48
|
+
view.tool.set ['Tomato', 'Cucumber']
|
49
|
+
view.tool.value.should eql ['Cucumber']
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'set array string and regex' do
|
53
|
+
view.tool.set ['Tomato', /cumber$/]
|
54
|
+
view.tool.value.should eql ['Cucumber']
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'set value text not found should error' do
|
58
|
+
expect { view.tool.set 'yepyep' }.to raise_error
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'set value regexp not found should error' do
|
62
|
+
expect { view.tool.set /fofofo/ }.to raise_error
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'options' do
|
66
|
+
view.tool.options.should eql ["Cucumber", "Tomato", "Other"]
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'to_labeled' do
|
72
|
+
|
73
|
+
it 'set string' do
|
74
|
+
view.tool.to_labeled.set 'Tomato'
|
75
|
+
view.tool.to_labeled.value.should eql ['Tomato']
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'set array' do
|
79
|
+
view.tool.to_labeled.set ['Tomato', 'Cucumber']
|
80
|
+
view.tool.to_labeled.value.should eql ['Cucumber']
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'checkbox group' do
|
87
|
+
|
88
|
+
context 'wrapped directly' do
|
89
|
+
|
90
|
+
it 'set single' do
|
91
|
+
view.fruit.set 'Tomatorama'
|
92
|
+
view.fruit.value.should eql ['Tomatorama']
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'set array' do
|
96
|
+
view.fruit.set ['Tomatorama', 'Cucumberama']
|
97
|
+
view.fruit.value.should eql ['Cucumberama', 'Tomatorama']
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'options' do
|
101
|
+
view.fruit.options.should eql ["Cucumberama", "Tomatorama", "Other"]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'to_labeled' do
|
106
|
+
|
107
|
+
it 'set single' do
|
108
|
+
view.fruit.to_labeled.set 'Tomatorama'
|
109
|
+
view.fruit.to_labeled.value.should eql ['Tomatorama']
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'set array' do
|
113
|
+
view.fruit.to_labeled.set ['Tomatorama', 'Cucumberama']
|
114
|
+
view.fruit.to_labeled.value.should eql ['Cucumberama', 'Tomatorama']
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -3,26 +3,26 @@ require 'spec_helper'
|
|
3
3
|
describe Domkey::View::PageObjectCollection do
|
4
4
|
|
5
5
|
before :all do
|
6
|
-
|
6
|
+
goto_html("test.html")
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'init error' do
|
10
|
-
# TODO. tighter scope what can be a
|
10
|
+
# TODO. tighter scope what can be a package
|
11
11
|
expect { Domkey::View::PageObjectCollection.new 'foo' }.to raise_error(Domkey::Exception::Error)
|
12
12
|
end
|
13
13
|
|
14
14
|
context 'when container is browser by default' do
|
15
15
|
|
16
|
-
context '
|
16
|
+
context 'package is package defining collection' do
|
17
17
|
|
18
18
|
before :each do
|
19
|
-
#
|
20
|
-
#
|
19
|
+
# package is definition of watir collection
|
20
|
+
# package when instantiated must respond to :each
|
21
21
|
# test sample:
|
22
22
|
# we have 3 text_fields with class that begins with street
|
23
|
-
|
23
|
+
package = lambda { text_fields(class: /^street/) }
|
24
24
|
|
25
|
-
@cbs = Domkey::View::PageObjectCollection.new
|
25
|
+
@cbs = Domkey::View::PageObjectCollection.new package
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'count or size' do
|
@@ -63,7 +63,7 @@ describe Domkey::View::PageObjectCollection do
|
|
63
63
|
|
64
64
|
end
|
65
65
|
|
66
|
-
context '
|
66
|
+
context 'package is hash' do
|
67
67
|
|
68
68
|
before :all do
|
69
69
|
# would we do that? give me all text_fields :street and all text_fields :city ? in one collection?
|
@@ -74,10 +74,10 @@ describe Domkey::View::PageObjectCollection do
|
|
74
74
|
Domkey.browser.text_fields(class: /^city/).count.should == 4
|
75
75
|
|
76
76
|
# when I define my keyed collection
|
77
|
-
|
78
|
-
|
77
|
+
package = {street: lambda { text_fields(class: /^street/) },
|
78
|
+
city: lambda { text_fields(class: /^city/) }}
|
79
79
|
|
80
|
-
@cbs = Domkey::View::PageObjectCollection.new
|
80
|
+
@cbs = Domkey::View::PageObjectCollection.new package
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'count' do
|
@@ -115,11 +115,11 @@ describe Domkey::View::PageObjectCollection do
|
|
115
115
|
|
116
116
|
end
|
117
117
|
|
118
|
-
context '
|
118
|
+
context 'package is pageobjectcollection' do
|
119
119
|
|
120
120
|
it 'initialize' do
|
121
|
-
|
122
|
-
pageobjectcollection = Domkey::View::PageObjectCollection.new
|
121
|
+
package = lambda { text_fields(class: /^street/) }
|
122
|
+
pageobjectcollection = Domkey::View::PageObjectCollection.new package
|
123
123
|
|
124
124
|
@cbs = Domkey::View::PageObjectCollection.new pageobjectcollection
|
125
125
|
end
|
@@ -1,32 +1,29 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
# domain specific page objects composed from regular page object
|
4
|
-
# PageObject is a type of object that responds to set and value.
|
5
|
-
# it is the Role it plays
|
6
|
-
# DateSelector is a type of decoration for domain specific pageobject
|
7
|
-
module Domkey
|
8
3
|
|
9
|
-
|
4
|
+
describe 'PageObject Decorators' do
|
10
5
|
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
# domain specific page objects composed from regular page object
|
7
|
+
# PageObject is a type of object that responds to set and value.
|
8
|
+
# it is the Role it plays
|
9
|
+
# DateSelector is a type of decoration for domain specific pageobject
|
14
10
|
|
15
|
-
def set value
|
16
|
-
watirproc.each_pair { |k, po| po.set(value.send(k)) }
|
17
|
-
end
|
18
11
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
12
|
+
#example of specialized domain specific pageobject.
|
13
|
+
# behavior of set and value
|
14
|
+
class DateSelectorPageObject < Domkey::View::PageObject
|
15
|
+
|
16
|
+
def set value
|
17
|
+
package.each_pair { |k, po| po.set(value.send(k)) }
|
24
18
|
end
|
25
|
-
end
|
26
|
-
end
|
27
19
|
|
20
|
+
def value
|
21
|
+
h = {}
|
22
|
+
package.each_pair { |k, po| h[k] = po.value }
|
23
|
+
Date.parse "%s/%s/%s" % [h[:year], h[:month], h[:day]]
|
24
|
+
end
|
25
|
+
end
|
28
26
|
|
29
|
-
module DomkeySpecHelper
|
30
27
|
|
31
28
|
class CheckboxTextField
|
32
29
|
|
@@ -77,27 +74,23 @@ module DomkeySpecHelper
|
|
77
74
|
h = pageobject.value
|
78
75
|
Date.parse "%s/%s/%s" % [h[:year], h[:month], h[:day]]
|
79
76
|
end
|
80
|
-
|
81
77
|
end
|
82
78
|
|
83
|
-
end
|
84
|
-
|
85
|
-
describe 'PageObject Decorators' do
|
86
79
|
|
87
80
|
before :all do
|
88
|
-
|
81
|
+
goto_html("test.html")
|
89
82
|
end
|
90
83
|
|
91
84
|
context 'DateSelector' do
|
92
85
|
|
93
|
-
it 'as pageobject component wrapped by
|
86
|
+
it 'as pageobject component wrapped by composite' do
|
94
87
|
|
95
88
|
watir_object = {day: lambda { text_field(id: 'day_field') },
|
96
89
|
month: lambda { text_field(id: 'month_field') },
|
97
90
|
year: lambda { text_field(id: 'year_field') }}
|
98
91
|
|
99
92
|
foo = Domkey::View::PageObject.new watir_object
|
100
|
-
dmy =
|
93
|
+
dmy = DateSelector.new foo
|
101
94
|
|
102
95
|
dmy.set Date.today
|
103
96
|
dmy.value.should eql Date.today
|
@@ -110,7 +103,7 @@ describe 'PageObject Decorators' do
|
|
110
103
|
year: lambda { text_field(id: 'year_field') }}
|
111
104
|
|
112
105
|
#foo = Domkey::Page::PageObject.new watir_object, @container
|
113
|
-
dmy =
|
106
|
+
dmy = DateSelectorPageObject.new watir_object
|
114
107
|
|
115
108
|
dmy.set Date.today
|
116
109
|
dmy.value.should eql Date.today
|
@@ -118,36 +111,32 @@ describe 'PageObject Decorators' do
|
|
118
111
|
|
119
112
|
end
|
120
113
|
|
121
|
-
|
122
114
|
context 'CheckboxTextField' do
|
123
115
|
|
116
|
+
it 'as pageobject component wrapped by composite' do
|
124
117
|
|
125
|
-
|
126
|
-
|
127
|
-
watir_object = {switch: lambda { checkbox(id: 'feature_checkbox1') },
|
128
|
-
blurb: lambda { text_field(id: 'feature_textarea1') }}
|
129
|
-
|
130
|
-
#pageobject as component
|
131
|
-
foo = Domkey::View::PageObject.new watir_object
|
132
|
-
|
133
|
-
foo.set switch: true, blurb: 'I am a blurb'
|
134
|
-
foo.set switch: false
|
135
|
-
foo.set switch: true
|
118
|
+
pageobject = Domkey::View::PageObject.new switch: -> { checkbox(id: 'feature_checkbox1') },
|
119
|
+
blurb: -> { textarea(id: 'feature_textarea1') }
|
136
120
|
|
137
|
-
#
|
138
|
-
|
121
|
+
# turn switch on and enter text in text area
|
122
|
+
pageobject.set switch: true, blurb: 'I am a blurb text after you turn on switch'
|
123
|
+
pageobject.set switch: false # => turn switch off, clear textarea blurb entry
|
124
|
+
pageobject.set switch: true # => turn switch on
|
139
125
|
|
140
|
-
|
141
|
-
|
142
|
-
tbcf.set 'hhkhkjhj'
|
126
|
+
# wrap with composite and handle specific behavior to set and value
|
127
|
+
cbtf = CheckboxTextField.new(pageobject)
|
143
128
|
|
129
|
+
cbtf.set true
|
130
|
+
cbtf.set false
|
131
|
+
cbtf.set 'Domain Specific Behavior to set value - check checkbox and enter text'
|
132
|
+
cbtf.value.should eql('Domain Specific Behavior to set value - check checkbox and enter text')
|
144
133
|
end
|
145
134
|
|
146
135
|
context 'building array of CheckboxTextFields in the view' do
|
147
136
|
|
148
137
|
it 'algorithm from predictable pattern' do
|
149
138
|
|
150
|
-
#given predictable pattern that
|
139
|
+
#given predictable pattern that signals the presence of pageobjects
|
151
140
|
divs = Domkey::View::PageObjectCollection.new lambda { divs(:id, /^feature_/) }
|
152
141
|
|
153
142
|
features = divs.map do |div|
|
@@ -156,19 +145,19 @@ describe 'PageObject Decorators' do
|
|
156
145
|
id = div.element.id.split("_").last
|
157
146
|
|
158
147
|
#definiton for each PageObject
|
159
|
-
watir_object = {switch:
|
160
|
-
blurb:
|
161
|
-
label:
|
148
|
+
watir_object = {switch: -> { checkbox(id: "feature_checkbox#{id}") },
|
149
|
+
blurb: -> { text_field(id: "feature_textarea#{id}") },
|
150
|
+
label: -> { label(for: "feature_checkbox#{id}") }}
|
162
151
|
|
163
152
|
pageobject = Domkey::View::PageObject.new watir_object
|
164
153
|
#domain specific pageobject
|
165
|
-
|
154
|
+
CheckboxTextField.new(pageobject)
|
166
155
|
end
|
167
156
|
|
168
157
|
# array of Domain Specific PageObjects
|
169
158
|
features.first.set 'bla'
|
170
159
|
features.map { |e| e.value }.should eql ["bla", false]
|
171
|
-
features.map { |e| e.pageobject.element(:label).text }.should eql ["
|
160
|
+
features.map { |e| e.pageobject.element(:label).text }.should eql ["Enable Checkbox for TextArea", "Golf Course"]
|
172
161
|
features.find { |e| e.label == 'Golf Course' }.value.should be_false
|
173
162
|
end
|
174
163
|
|
@@ -187,7 +176,7 @@ describe 'PageObject Decorators' do
|
|
187
176
|
pageobject = PageObject.new switch: -> { checkbox(id: "feature_checkbox#{i}") },
|
188
177
|
blurb: -> { text_field(id: "feature_textarea#{i}") },
|
189
178
|
label: -> { label(for: "feature_checkbox#{i}") }
|
190
|
-
|
179
|
+
CheckboxTextField.new(pageobject)
|
191
180
|
end
|
192
181
|
end
|
193
182
|
|
data/spec/page_object_spec.rb
CHANGED
@@ -6,35 +6,36 @@ require 'spec_helper'
|
|
6
6
|
describe Domkey::View::PageObject do
|
7
7
|
|
8
8
|
before :all do
|
9
|
-
|
9
|
+
goto_html("test.html")
|
10
10
|
end
|
11
11
|
|
12
12
|
context 'exceptions' do
|
13
13
|
|
14
|
-
it 'bad proc for
|
14
|
+
it 'bad proc for package argument' do
|
15
15
|
expect { Domkey::View::PageObject.new lambda { 'foo' } }.to raise_error(Domkey::Exception::Error)
|
16
16
|
end
|
17
17
|
|
18
|
-
it 'bad object for
|
18
|
+
it 'bad object for package argument' do
|
19
19
|
expect { Domkey::View::PageObject.new(Object.new) }.to raise_error(Domkey::Exception::Error)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
context 'when container is browser by default and' do
|
24
24
|
|
25
|
-
it '
|
26
|
-
|
27
|
-
street
|
25
|
+
it 'package is package' do
|
26
|
+
package = lambda { text_field(id: 'street1') }
|
27
|
+
street = Domkey::View::PageObject.new package
|
28
28
|
|
29
|
-
street.
|
29
|
+
street.package.should be_kind_of(Proc)
|
30
30
|
street.element.should be_kind_of(Watir::TextField) #one default element
|
31
31
|
|
32
32
|
# talk to browser
|
33
33
|
street.set 'Lamar'
|
34
34
|
street.value.should eql 'Lamar'
|
35
|
+
street.options.should be_empty # by default options are empty
|
35
36
|
end
|
36
37
|
|
37
|
-
it '
|
38
|
+
it 'package is pageobject' do
|
38
39
|
# setup
|
39
40
|
watir_object = lambda { text_field(id: 'street1') }
|
40
41
|
pageobject = Domkey::View::PageObject.new watir_object
|
@@ -42,22 +43,23 @@ describe Domkey::View::PageObject do
|
|
42
43
|
# test
|
43
44
|
street = Domkey::View::PageObject.new pageobject
|
44
45
|
|
45
|
-
street.
|
46
|
+
street.package.should be_kind_of(Proc)
|
46
47
|
street.element.should be_kind_of(Watir::TextField)
|
47
48
|
|
48
49
|
|
49
50
|
# talk to browser
|
50
51
|
street.set 'zooom' #sending string here so no hash like in composed object
|
51
52
|
street.value.should eql 'zooom'
|
53
|
+
street.options.should be_empty
|
52
54
|
end
|
53
55
|
|
54
|
-
it '
|
55
|
-
hash
|
56
|
-
|
57
|
-
address
|
56
|
+
it 'package is proc hash where values are packages' do
|
57
|
+
hash = {street1: lambda { text_field(id: 'street1') }, city: lambda { text_field(id: 'city1') }}
|
58
|
+
package = lambda { hash }
|
59
|
+
address = Domkey::View::PageObject.new package
|
58
60
|
|
59
|
-
address.
|
60
|
-
address.
|
61
|
+
address.package.should respond_to(:each_pair)
|
62
|
+
address.package.each_pair do |k, v|
|
61
63
|
k.should be_kind_of(Symbol)
|
62
64
|
v.should be_kind_of(Domkey::View::PageObject) #should respond to set and value
|
63
65
|
end
|
@@ -67,16 +69,17 @@ describe Domkey::View::PageObject do
|
|
67
69
|
v.should be_kind_of(Watir::TextField) #resolve suitecase
|
68
70
|
end
|
69
71
|
|
72
|
+
address.options.should eql({:street1=>[], :city=>[]})
|
70
73
|
end
|
71
74
|
|
72
|
-
it '
|
75
|
+
it 'package is hash where values are packages' do
|
73
76
|
|
74
77
|
hash = {street1: lambda { text_field(id: 'street1') }, city: lambda { text_field(id: 'city1') }}
|
75
78
|
|
76
79
|
address = Domkey::View::PageObject.new hash
|
77
80
|
|
78
|
-
address.
|
79
|
-
address.
|
81
|
+
address.package.should respond_to(:each_pair)
|
82
|
+
address.package.each_pair do |k, v|
|
80
83
|
k.should be_kind_of(Symbol)
|
81
84
|
v.should be_kind_of(Domkey::View::PageObject) #should respond to set and value
|
82
85
|
end
|
@@ -120,6 +123,8 @@ describe Domkey::View::PageObject do
|
|
120
123
|
e = lambda { text_field(class: 'city') }
|
121
124
|
city = Domkey::View::PageObject.new e, container
|
122
125
|
city.set 'Hellocontainer'
|
126
|
+
city.value.should eql 'Hellocontainer'
|
127
|
+
city.options.should be_empty
|
123
128
|
|
124
129
|
#verify
|
125
130
|
Domkey.browser.div(:id, 'container').text_field(:class, 'city').value.should == 'Hellocontainer'
|