watir_drops 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1b475375851d1ea8fc17aa62fe2cfd1e437200d
4
- data.tar.gz: 4e8860a64f047f6b504d3e85cc74a3a704bf6a5b
3
+ metadata.gz: e9ff8bd28fdad499598436c884e44f46fa563035
4
+ data.tar.gz: b32d82432fff06087e5481f0386b29b454240a87
5
5
  SHA512:
6
- metadata.gz: 01462e4c5a5c0ead9be37393f56b631e17b2e6a9aeb03ff358c3a7fb3a5ebf68647cfe3ae9bd13f16df425eb94b96e4745f666c564b2caa280fb77da4c039876
7
- data.tar.gz: 17f4e13f11d2dea7439e7d3cead93150371615abc8d4275f56b0ab5242c90b86546c10f2259b24b557148881b2d937c074a33436d84126a1b0a3436c5195a668
6
+ metadata.gz: 426fb0ebf0323aec3c8ac52d87923c06d12d08f4aedf71cb088e7ff68a021f420cec5e80bd1f41b09c50390d050424a4064924d41785190915e5c958f0433bb7
7
+ data.tar.gz: 99ffbcf96242fc928336bcac3e2e906aa586e003f63fb4c18ee4523b1401dd9b968ff69995e963594f582118d75a5d34839aca5a04318094b86f39b0108f1095
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 0.5.0 (2016-02-16)
2
+
3
+ * split new definition of elements & collections into a sub-class
4
+
1
5
  ### 0.4.1 (2016-02-15)
2
6
 
3
7
  * alias fill_form with populate_page_with (page_object gem equivalent)
data/lib/watir_drops.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'watir-webdriver'
2
2
  require 'watir_drops/page_object'
3
+ require 'watir_drops/training_wheels'
@@ -21,60 +21,49 @@ module WatirDrops
21
21
  subclass.element_list = element_list.dup
22
22
  end
23
23
 
24
- Watir::Container.instance_methods(false).each do |class_method_name|
25
- define_method(class_method_name) do |instance_method_name, locator = {}, &block|
26
- define_method(instance_method_name) do |*args|
27
- if block.is_a? Proc
28
- raise StandardError, 'Can not define element with both locator and block' unless locator.empty?
29
- expected_class = browser.send(class_method_name).class
30
- element = self.instance_exec(*args, &block)
31
- return element if element.is_a? expected_class
32
- raise StandardError, "#{instance_method_name} method was defined as a #{expected_class}, but is a #{element.class}"
33
- else
34
- browser.send(class_method_name, locator)
35
- end
36
- end
24
+ def elements(name, &block)
25
+ define_method(name) do |*args|
26
+ self.instance_exec(*args, &block)
27
+ end
37
28
 
38
- define_method("#{instance_method_name}=") do |val|
39
- watir_element = self.send(instance_method_name)
40
- watir_element.wait_until_present
41
- case watir_element
42
- when Watir::Radio
43
- watir_element.set if val
44
- when Watir::CheckBox
45
- val ? watir_element.set : watir_element.clear
46
- when Watir::Select
47
- watir_element.select val
48
- when Watir::Button
49
- watir_element.click
50
- # TODO - Email & Password types are not set to UserEditable in Watir
51
- when Watir::Input
52
- watir_element.wd.clear
53
- watir_element.send_keys val
54
- else
55
- watir_element.click if val
56
- end
57
- end
29
+ element_list << name.to_sym
30
+ end
58
31
 
59
- define_method(instance_method_name.to_s.pluralize) do |*args|
60
- if block.is_a? Proc
61
- expected_class = browser.send(class_method_name.to_s.pluralize).class
32
+ def element(name, &block)
33
+ define_method(name) do |*args|
34
+ self.instance_exec(*args, &block)
35
+ end
62
36
 
63
- single_element = self.instance_exec(*args, &block)
64
- parent = single_element.instance_variable_get('@parent')
65
- selector = single_element.instance_variable_get('@selector')
66
- element_type = selector.delete(:tag_name) || 'element'
67
- element = parent.send(element_type.pluralize, selector)
37
+ define_method(name.to_s.pluralize) do |*args|
38
+ single_element = self.instance_exec(*args, &block)
39
+ parent = single_element.instance_variable_get('@parent')
40
+ selector = single_element.instance_variable_get('@selector')
41
+ element_type = selector.delete(:tag_name) || 'element'
42
+ parent.send(element_type.pluralize, selector)
43
+ end
68
44
 
69
- return element if element.is_a?(expected_class) || class_method_name == :element
70
- raise StandardError, "#{instance_method_name} method was defined as a #{expected_class}, but is a #{element.class}"
45
+ define_method("#{name}=") do |val|
46
+ watir_element = self.instance_exec &block
47
+ watir_element.wait_until_present
48
+ case watir_element
49
+ when Watir::Radio
50
+ watir_element.set if val
51
+ when Watir::CheckBox
52
+ val ? watir_element.set : watir_element.clear
53
+ when Watir::Select
54
+ watir_element.select val
55
+ when Watir::Button
56
+ watir_element.click
57
+ # TODO - Email & Password types are not set to UserEditable in Watir
58
+ when Watir::Input
59
+ watir_element.wd.clear
60
+ watir_element.send_keys val
71
61
  else
72
- browser.send(class_method_name.to_s.pluralize, locator)
73
- end
62
+ watir_element.click if val
74
63
  end
75
-
76
- element_list << instance_method_name.to_sym
77
64
  end
65
+
66
+ element_list << name.to_sym
78
67
  end
79
68
 
80
69
  def visit(*args)
@@ -88,28 +77,29 @@ module WatirDrops
88
77
  new.tap { yield if block_given? }
89
78
  end
90
79
 
91
- def browser=(*args)
92
- @@browser = block_given? ? yield(args) : args.first
80
+ def browser=(browser_input)
81
+ @@browser = browser_input
93
82
  end
94
83
 
95
84
  def browser
96
- @@browser || (WatirSession.browser if defined? WatirSession)
85
+ @@browser
97
86
  end
98
87
 
99
88
  end
100
89
 
101
- def browser
102
- self.class.browser
90
+ attr_reader :browser
91
+
92
+ def initialize(browser_input = @@browser)
93
+ @browser = browser_input
103
94
  end
104
95
 
105
96
  def fill_form(model)
106
- model = model.to_h unless model.is_a? Hash
97
+ model = model.to_h if model.is_a? OpenStruct
107
98
  intersect = self.class.element_list & model.keys
108
99
  intersect.each do |val|
109
100
  self.send("#{val}=", model[val])
110
101
  end
111
102
  end
112
- alias_method :populate_page_with, :fill_form
113
103
 
114
104
  def title
115
105
  browser.title
@@ -0,0 +1,67 @@
1
+ module WatirDrops
2
+
3
+ class TrainingWheels < PageObject
4
+
5
+ class << self
6
+
7
+ Watir::Container.instance_methods(false).each do |class_method_name|
8
+ define_method(class_method_name) do |instance_method_name, locator = {}, &block|
9
+ define_method(instance_method_name) do |*args|
10
+ if block.is_a? Proc
11
+ raise StandardError, 'Can not define element with both locator and block' unless locator.empty?
12
+ expected_class = browser.send(class_method_name).class
13
+ element = self.instance_exec(*args, &block)
14
+ return element if element.is_a? expected_class
15
+ raise StandardError, "#{instance_method_name} method was defined as a #{expected_class}, but is a #{element.class}"
16
+ else
17
+ browser.send(class_method_name, locator)
18
+ end
19
+ end
20
+
21
+ define_method("#{instance_method_name}=") do |val|
22
+ watir_element = self.send(instance_method_name)
23
+ watir_element.wait_until_present
24
+ case watir_element
25
+ when Watir::Radio
26
+ watir_element.set if val
27
+ when Watir::CheckBox
28
+ val ? watir_element.set : watir_element.clear
29
+ when Watir::Select
30
+ watir_element.select val
31
+ when Watir::Button
32
+ watir_element.click
33
+ # TODO - Email & Password types are not set to UserEditable in Watir
34
+ when Watir::Input
35
+ watir_element.wd.clear
36
+ watir_element.send_keys val
37
+ else
38
+ watir_element.click if val
39
+ end
40
+ end
41
+
42
+ define_method(instance_method_name.to_s.pluralize) do |*args|
43
+ if block.is_a? Proc
44
+ expected_class = browser.send(class_method_name.to_s.pluralize).class
45
+
46
+ single_element = self.instance_exec(*args, &block)
47
+ parent = single_element.instance_variable_get('@parent')
48
+ selector = single_element.instance_variable_get('@selector')
49
+ element_type = selector.delete(:tag_name) || 'element'
50
+ element = parent.send(element_type.pluralize, selector)
51
+
52
+ return element if element.is_a?(expected_class) || class_method_name == :element
53
+ raise StandardError, "#{instance_method_name} method was defined as a #{expected_class}, but is a #{element.class}"
54
+ else
55
+ browser.send(class_method_name.to_s.pluralize, locator)
56
+ end
57
+ end
58
+
59
+ element_list << instance_method_name.to_sym
60
+ end
61
+ end
62
+ end
63
+
64
+ alias_method :populate_page_with, :fill_form
65
+
66
+ end
67
+ end
data/watir_drops.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'watir_drops'
5
- spec.version = '0.4.1'
5
+ spec.version = '0.5.0'
6
6
  spec.authors = ['Titus Fortner']
7
7
  spec.email = ['titusfortner@gmail.com']
8
8
 
@@ -16,11 +16,12 @@ application information, allowing it to be decoupled from the tests}
16
16
  spec.require_paths = ['lib']
17
17
 
18
18
  spec.add_runtime_dependency 'activesupport', '~> 3.0'
19
+ spec.add_runtime_dependency 'watir-webdriver'
19
20
 
20
21
  spec.add_development_dependency 'bundler', '~> 1.10'
21
22
  spec.add_development_dependency 'rake', '~> 10.0'
22
23
  spec.add_development_dependency 'rspec', '~> 3.3'
23
24
  spec.add_development_dependency 'factory_girl'
24
25
  spec.add_development_dependency 'data_magic'
25
- spec.add_development_dependency 'watir_session', '~> 0.2'
26
+ spec.add_development_dependency 'watir_model'
26
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watir_drops
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Titus Fortner
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: watir-webdriver
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -95,19 +109,19 @@ dependencies:
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
- name: watir_session
112
+ name: watir_model
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - "~>"
115
+ - - ">="
102
116
  - !ruby/object:Gem::Version
103
- version: '0.2'
117
+ version: '0'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - "~>"
122
+ - - ">="
109
123
  - !ruby/object:Gem::Version
110
- version: '0.2'
124
+ version: '0'
111
125
  description: |-
112
126
  This gem leverages the Watir test framework to allow for easy modeling of specific web
113
127
  application information, allowing it to be decoupled from the tests
@@ -125,6 +139,7 @@ files:
125
139
  - Rakefile
126
140
  - lib/watir_drops.rb
127
141
  - lib/watir_drops/page_object.rb
142
+ - lib/watir_drops/training_wheels.rb
128
143
  - watir_drops.gemspec
129
144
  homepage: https://github.com/titusfortner/watir_drops
130
145
  licenses: