watir_drops 0.6.1 → 0.7.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: 2e57b1ada80896b55568b55ff341f5e2abae32f5
4
- data.tar.gz: d87ea767c146b04fbda8f7c679f31b94395aa700
3
+ metadata.gz: 280730b6901eb01a5744bc02c17e50c0d14fce76
4
+ data.tar.gz: deb0cd398b6c840f35346c37d110a70eff7de0f3
5
5
  SHA512:
6
- metadata.gz: f5348f40cabadec4f07226e6e89771fe39feed3ec396364231e1144786e40c730d6c12af430eefd90c20ddda8c45c6bae895ba7a7a69c9bccb28f4217777c831
7
- data.tar.gz: dc270caa536640de3fec8f058c133507a1be05806573a91154f93389a2666fcb4c20f418463ec15babf35acb9954fd4ae6d45740bdf5b9d07620c9d6271931af
6
+ metadata.gz: b5f878a47b275c0bd4c4865045cd30f7b0d32464105af3a11914f5c010d79b91211e5cc402f538e3d443c2068359249e03e0d1248ac4dc561b73f181a9a4e14a
7
+ data.tar.gz: d5e0bfd51542d40f8d6befc46e944a5ef762e5651d0f3134d2e3cc3d0e25ac8fe39ac6e0de09e55c3c17330c56fd7e032f80cc5bca76a0d712d8575f594f31f4
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+
2
+ --color
3
+ --format doc
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 0.7.0 (2017-02-02)
2
+
3
+ * implement #on_page? verification by url, title or element(s) (thanks Lu Cui)
4
+
1
5
  ### 0.6.1 (2017-02-01)
2
6
 
3
7
  * fix bug requiring Active Support (thanks Fedor Barannik)
@@ -5,8 +5,13 @@ module WatirDrops
5
5
  class << self
6
6
 
7
7
  attr_writer :element_list
8
+ attr_writer :required_element_list
9
+ attr_reader :require_url
10
+
11
+
12
+ def page_url(required: false)
13
+ @require_url = required
8
14
 
9
- def page_url
10
15
  define_method("page_url") do |*args|
11
16
  yield(*args)
12
17
  end
@@ -16,12 +21,24 @@ module WatirDrops
16
21
  end
17
22
  end
18
23
 
24
+
25
+ def page_title
26
+ define_method("page_title") do |*args|
27
+ yield(*args)
28
+ end
29
+ end
30
+
19
31
  def element_list
20
32
  @element_list ||= []
21
33
  end
22
34
 
35
+ def required_element_list
36
+ @required_element_list ||= []
37
+ end
38
+
23
39
  def inherited(subclass)
24
40
  subclass.element_list = element_list.dup
41
+ subclass.required_element_list = required_element_list.dup
25
42
  end
26
43
 
27
44
  def elements(name, &block)
@@ -32,7 +49,7 @@ module WatirDrops
32
49
  element_list << name.to_sym
33
50
  end
34
51
 
35
- def element(name, &block)
52
+ def element(name, required: false, &block)
36
53
  define_method(name) do |*args|
37
54
  self.instance_exec(*args, &block)
38
55
  end
@@ -54,14 +71,20 @@ module WatirDrops
54
71
  watir_element.click if val
55
72
  end
56
73
  end
57
-
58
74
  element_list << name.to_sym
75
+ required_element_list << name.to_sym if required
59
76
  end
60
77
 
61
78
  def visit(*args)
62
- new.tap { |page| page.goto(*args) }
79
+ new.tap do |page|
80
+ page.goto(*args)
81
+ exception = Selenium::WebDriver::Error::WebDriverError
82
+ message = "Expected to be on #{page.class}, but conditions not met"
83
+ raise exception, message if page.page_verifiable? && !page.on_page?
84
+ end
63
85
  end
64
86
 
87
+
65
88
  def browser=(browser_input)
66
89
  @@browser = browser_input
67
90
  end
@@ -95,8 +118,32 @@ module WatirDrops
95
118
  def inspect
96
119
  '#<%s url=%s title=%s>' % [self.class, url.inspect, title.inspect]
97
120
  end
121
+
98
122
  alias selector_string inspect
99
123
 
124
+
125
+ def on_page?
126
+ exception = Selenium::WebDriver::Error::WebDriverError
127
+ message = "Can not verify page without any requirements set"
128
+ raise exception, message unless page_verifiable?
129
+
130
+ @browser.wait_until do |browser|
131
+ !self.class.require_url || page_url.gsub("#{URI.parse(page_url).scheme}://", '') == browser.url.gsub("#{URI.parse(browser.url).scheme}://", '')
132
+ end
133
+
134
+ @browser.wait_until do |browser|
135
+ !self.respond_to?(:page_title) || browser.title == page_title
136
+ end
137
+
138
+ @browser.wait_until do |_browser|
139
+ !self.class.required_element_list.any? || self.class.required_element_list.all? { |e| send(e).present? }
140
+ end
141
+
142
+ true
143
+ rescue Watir::Wait::TimeoutError
144
+ false
145
+ end
146
+
100
147
  def method_missing(method, *args, &block)
101
148
  if @browser.respond_to?(method)
102
149
  @browser.send(method, *args, &block)
@@ -109,5 +156,8 @@ module WatirDrops
109
156
  @browser.respond_to?(method) || super
110
157
  end
111
158
 
159
+ def page_verifiable?
160
+ self.class.require_url || self.respond_to?(:page_title) || self.class.required_element_list.any?
161
+ end
112
162
  end
113
163
  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.6.1'
5
+ spec.version = '0.7.0'
6
6
  spec.authors = ['Titus Fortner']
7
7
  spec.email = ['titusfortner@gmail.com']
8
8
 
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.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Titus Fortner
@@ -118,6 +118,7 @@ extensions: []
118
118
  extra_rdoc_files: []
119
119
  files:
120
120
  - ".gitignore"
121
+ - ".rspec"
121
122
  - ".travis.yml"
122
123
  - CHANGES.md
123
124
  - Gemfile
@@ -148,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
149
  version: '0'
149
150
  requirements: []
150
151
  rubyforge_project:
151
- rubygems_version: 2.4.8
152
+ rubygems_version: 2.6.8
152
153
  signing_key:
153
154
  specification_version: 4
154
155
  summary: Page Object Framework for use with Watir