domkey 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+ module DomkeyExample
3
+ class DomIsWatirproc
4
+ include Domkey::View
5
+ #pageobject is watirproc
6
+ dom(:street) { text_field(id: 'street1') }
7
+ dom(:city) { text_field(id: 'city1') }
8
+ end
9
+
10
+ class DomIsHashOfDom # or doom
11
+ include Domkey::View
12
+
13
+ # Possible api to compose pageobject with pair of hash => lambda definition
14
+ dom(:address) do
15
+ {
16
+ street: -> { text_field(id: 'street1') },
17
+ city: -> { text_field(id: 'city1') }
18
+ }
19
+ end
20
+
21
+ ## alternative api design
22
+
23
+ #dom(:address) do
24
+ # Proc.new { Hash.new(:street => dom(:street) { text_field(id: 'street2') }) }
25
+ # {:street => (dom(:street) { text_field(id: 'street2') })} #literal hash
26
+ #end
27
+
28
+ #composed
29
+ #dom(:address) do
30
+ # {street: street,
31
+ # city: city}
32
+ #end
33
+
34
+ ## pageobject is composed
35
+ #domkey(:address) do
36
+ # dom(:street) { text_field(id: 'street1') }
37
+ # dom(:city) { text_field(id: 'city') }
38
+ #end
39
+ end
40
+ end
41
+
42
+ describe Domkey::View do
43
+
44
+ before :all do
45
+ Domkey.browser.goto("file://" + __dir__ + "/html/test.html")
46
+ end
47
+
48
+ it 'domw is watirproc' do
49
+ view = DomkeyExample::DomIsWatirproc.new
50
+ view.should respond_to(:street)
51
+ view.street.should be_kind_of(Domkey::View::PageObject)
52
+
53
+ # talk to browser
54
+ view.street.set 'hello dom'
55
+ view.street.value.should eql 'hello dom'
56
+ end
57
+
58
+ it 'dom is hash of dom' do
59
+ view = DomkeyExample::DomIsHashOfDom.new
60
+
61
+ view.should respond_to(:address)
62
+
63
+ view.address.watirproc.should respond_to(:each_pair)
64
+ view.address.watirproc.should_not be_empty
65
+
66
+ view.address.watirproc.each_pair do |k, v|
67
+ k.should be_kind_of(Symbol)
68
+ v.should be_kind_of(Domkey::View::PageObject) #should respond to set and value
69
+ end
70
+
71
+ view.address.element.should respond_to(:each_pair)
72
+ view.address.element.each_pair do |k, v|
73
+ v.should be_kind_of(Watir::TextField) #resolve suitecase
74
+ end
75
+
76
+
77
+ view.address.element.keys.should eql [:street, :city]
78
+
79
+ # talk to browser
80
+ value = {street: 'Quantanemera', city: 'Austin'}
81
+ view.address.set value
82
+ v = view.address.value
83
+ v.should eql value
84
+
85
+ #set partial address (omit some keys)
86
+ view.address.set street: 'Lamarski'
87
+ view.address.value.should eql street: 'Lamarski', city: 'Austin'
88
+
89
+ end
90
+ end
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'rspec'
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ add_filter "/spec/"
6
+ end
7
+ require 'domkey'
8
+ SimpleCov.command_name "test:units"
9
+
10
+ RSpec.configure do |config|
11
+ config.after :all do
12
+ Domkey.browser.close
13
+ end
14
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+ module DomkeyExample
3
+
4
+ class SingleDom
5
+ include Domkey::View
6
+ dom(:street) { text_field(class: 'street1') }
7
+
8
+ def container
9
+ SingleDomContainer.new browser.div(id: 'container')
10
+ end
11
+ end
12
+
13
+ class SingleDomContainer
14
+ include Domkey::View
15
+ dom(:street) { text_field(class: 'street1') }
16
+ end
17
+
18
+ end
19
+
20
+ describe Domkey::View do
21
+
22
+ before :all do
23
+ Domkey.browser.goto("file://" + __dir__ + "/html/test.html")
24
+ end
25
+
26
+ it 'dom single element' do
27
+ view = DomkeyExample::SingleDom.new
28
+ view.should respond_to(:street)
29
+ view.street.should be_kind_of(Domkey::View::PageObject)
30
+ view.street.value.should == ''
31
+ view.street.set 'bla'
32
+ view.street.value.should == 'bla'
33
+ view.container.street.value.should == ''
34
+ view
35
+ end
36
+
37
+ end
38
+
39
+ #require 'benchmark'
40
+ #Benchmark.bm do |bm|
41
+ # howmany = 50
42
+ # # setup browser
43
+ # Domkey.browser.goto("file://" + __dir__ + "/html/test.html")
44
+ # view = DomkeyExample::SingleDom.new Domkey.browser
45
+ # bm.report('domkey') do
46
+ # howmany.times do
47
+ # view.street.set 'value'
48
+ # view.street.value
49
+ # end
50
+ # end
51
+ # bm.report('watir-') do
52
+ # howmany.times do
53
+ # Domkey.browser.text_field(class: 'street1').set 'value'
54
+ # Domkey.browser.text_field(class: 'street1').value
55
+ # end
56
+ # end
57
+ #end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+ module DomkeyExample
3
+ class Doms
4
+ include Domkey::View
5
+ doms(:streets) { text_fields(class: 'street1') }
6
+ end
7
+ end
8
+
9
+ describe Domkey::View do
10
+
11
+ before :all do
12
+ Domkey.browser.goto("file://" + __dir__ + "/html/test.html")
13
+ end
14
+
15
+ it 'doms collection' do
16
+ view = DomkeyExample::Doms.new
17
+ view.should respond_to(:streets)
18
+ view.streets.should be_kind_of(Domkey::View::PageObjectCollection)
19
+ view.streets.each { |e| e.should be_kind_of(Domkey::View::PageObject) }
20
+ view.streets.should_not respond_to(:value) # or should it?
21
+ view.streets.should_not respond_to(:set) # or should it?
22
+
23
+
24
+ # talk to the browser
25
+ view.streets.each { |e| e.set "hello" }
26
+ view.streets.map { |e| e.value }.should eql ["hello", "hello", "hello"]
27
+ end
28
+
29
+ end
30
+
31
+ #require 'benchmark'
32
+ #Benchmark.bm do |bm|
33
+ # howmany = 50
34
+ # # setup browser
35
+ # Domkey.browser.goto("file://" + __dir__ + "/html/test.html")
36
+ # view = DomkeyExample::Doms.new Domkey.browser
37
+ # bm.report('domkey') do
38
+ # howmany.times do
39
+ # view.streets.each { |e| e.set "hello" }
40
+ # view.streets.map { |e| e.value }
41
+ # end
42
+ # end
43
+ # bm.report('watir-') do
44
+ # howmany.times do
45
+ # Domkey.browser.text_fields(class: 'street1').each { |e| e.set "hello" }
46
+ # Domkey.browser.text_field(class: 'street1').map { |e| e.value }
47
+ # end
48
+ # end
49
+ #end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: domkey
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - rubytester
8
+ - marekj
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-03-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: watir-webdriver
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 0.6.4
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 0.6.4
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '1.5'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '1.5'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '10.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '10.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '2.14'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '2.14'
70
+ - !ruby/object:Gem::Dependency
71
+ name: simplecov
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ description: Domain Specifc PageObject for Selenium Watir-Webdriver. PageObject that
85
+ models business domain first and browser code second
86
+ email:
87
+ - github@rubytester.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - .gitignore
93
+ - .rspec
94
+ - .travis.yml
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - domkey.gemspec
100
+ - lib/domkey.rb
101
+ - lib/domkey/browser_session.rb
102
+ - lib/domkey/exception.rb
103
+ - lib/domkey/version.rb
104
+ - lib/domkey/view.rb
105
+ - lib/domkey/view/page_object.rb
106
+ - lib/domkey/view/page_object_collection.rb
107
+ - spec/browser_spec.rb
108
+ - spec/html/test.html
109
+ - spec/page_object_collection_spec.rb
110
+ - spec/page_object_decorators_spec.rb
111
+ - spec/page_object_spec.rb
112
+ - spec/page_spec.rb
113
+ - spec/spec_helper.rb
114
+ - spec/view_dom_spec.rb
115
+ - spec/view_doms_spec.rb
116
+ homepage: ''
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ~>
127
+ - !ruby/object:Gem::Version
128
+ version: '2.0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.2.1
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Domain Specifc PageObject for Selenium Watir-Webdriver
140
+ test_files:
141
+ - spec/browser_spec.rb
142
+ - spec/html/test.html
143
+ - spec/page_object_collection_spec.rb
144
+ - spec/page_object_decorators_spec.rb
145
+ - spec/page_object_spec.rb
146
+ - spec/page_spec.rb
147
+ - spec/spec_helper.rb
148
+ - spec/view_dom_spec.rb
149
+ - spec/view_doms_spec.rb