page-object 0.9.2 → 0.9.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c01b813ea17360d98a97206dd1dc24a8928c9dd
4
- data.tar.gz: 9cc17aafde0461e9c883e97415ae0d642e979f7f
3
+ metadata.gz: 8c3bfa3ecdb6fcee1e7ba4384511ee6479e86597
4
+ data.tar.gz: 49404e73c224e8dfa6b68a3e878bce44a9e8c203
5
5
  SHA512:
6
- metadata.gz: 8de08d4d39d7fb91fdaf4fa9d38a430a649502c1d0ffb47eb92d20e60ec5699c60ea73801828eb4e5a90ccd5774379dd4649151b844f7f4dc166e8589467957f
7
- data.tar.gz: ff1478fc9c7438771b0ac4e427a00230950e47e2933c259ebae7ea8a3c7a61b573e010b90b6653d67af2edd7b03b0f9ab413c06d3f1a1717a7c202469ac71272
6
+ metadata.gz: 2ed2bdca4c6adc2148ee442a28ff39a8a1ffe71b2bdf2287a0fbfab78cb4250b628ca161a41d536c46b95ac8b4ba46c2340ff966f121e496ae6b94ea3a211741
7
+ data.tar.gz: db51a5b4cf3ef8598355ed6192ff71a84ce6fe452192b0b4450a53f5acf3846a8c05bf2c111d5ff5efa13b398de737475c85cc73725152d14986aafeb4db785b
data/.travis.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.2
4
3
  - 1.9.3
5
4
  - 2.0.0
6
5
  - jruby-19mode
data/ChangeLog CHANGED
@@ -1,3 +1,12 @@
1
+ === Version 0.9.3 / 2013-10-24
2
+ * Enhancements
3
+ * Added class_name method to Element
4
+ * Added select_text method to Element
5
+ * Added wait_for_expected_title and expected_element_visible methods (Thanks smartkiwi)
6
+ * Updated to use the latest selenium-webdriver 2.37.0
7
+ * Fixes
8
+ * Fixed issue with custom widgets on Ruby 1.8.7 (Thanks X Zhang)
9
+
1
10
  === Version 0.9.2 / 2013-8-23
2
11
  * Enhancements
3
12
  * Added elements method to accessor so one can gen methods for generic collections of elements
@@ -313,3 +313,11 @@ Feature: Elements
313
313
  Scenario: Accessing an HTML 5 element using the element method
314
314
  When I retrieve the figure using the element
315
315
  Then I should see the figure contains an image
316
+
317
+ Scenario: Getting the class name for an element
318
+ When I search for the paragraph by "id"
319
+ Then I should know the paragraph class is "p_class"
320
+
321
+ @focus
322
+ Scenario: Selecting the text for an element
323
+ Then I should be able to select "Elements" from the paragraph
@@ -478,7 +478,6 @@ Feature: Multi Elements
478
478
  And the title for file field 2 should be "File Field 2"
479
479
  And the title for file field 3 should be "File Field 3"
480
480
 
481
- @focus
482
481
  Scenario: Selecting multple generic element types
483
482
  When I select the multiple elements with a tag label
484
483
  Then I should have 3 labels
@@ -18,3 +18,11 @@ end
18
18
  Then /^I should see that the paragraph exists$/ do
19
19
  @page.p_id?.should == true
20
20
  end
21
+
22
+ Then(/^I should know the paragraph class is "(.*?)"$/) do |class_name|
23
+ @page.p_id_element.class_name.should == class_name
24
+ end
25
+
26
+ Then(/^I should be able to select "(.*?)" from the paragraph$/) do |text|
27
+ @page.p_id_element.select_text text
28
+ end
@@ -48,6 +48,34 @@ module PageObject
48
48
  end
49
49
  alias_method :direct_url, :page_url
50
50
 
51
+ #
52
+ # Creates a method that waits the expected_title of a page to match the actual.
53
+ # @param [String] expected_title the literal expected title for the page
54
+ # @param [Regexp] expected_title the expected title pattern for the page
55
+ # @param [optional, Integer] timeout default value is nil - do not wait
56
+ # @return [boolean]
57
+ # @raise An exception if expected_title does not match actual title
58
+ #
59
+ # @example Specify 'Google' as the expected title of a page
60
+ # expected_title "Google"
61
+ # page.has_expected_title?
62
+ #
63
+ def wait_for_expected_title(expected_title, timeout=::PageObject.default_element_wait)
64
+ define_method("wait_for_expected_title?") do
65
+ page_title = title
66
+ has_expected_title = (expected_title === page_title)
67
+ if not has_expected_title and not timeout.nil?
68
+ wait_until(timeout, "Expected title '#{expected_title}' instead of '#{page_title}'") do
69
+ has_expected_title = (expected_title === page_title)
70
+ has_expected_title
71
+ end
72
+ end
73
+ raise "Expected title '#{expected_title}' instead of '#{page_title}'" unless has_expected_title
74
+ has_expected_title
75
+ end
76
+ end
77
+
78
+
51
79
  #
52
80
  # Creates a method that compares the expected_title of a page against the actual.
53
81
  # @param [String] expected_title the literal expected title for the page
@@ -85,6 +113,25 @@ module PageObject
85
113
  end
86
114
  end
87
115
 
116
+ #
117
+ # Creates a method that provides a way to initialize a page based upon an expected element to become visible.
118
+ # This is useful for pages that load dynamic content and might have hidden elements that are not shown.
119
+ # @param [Symbol] the name given to the element in the declaration
120
+ # @param [optional, Integer] timeout default value is 5 seconds
121
+ # @param [optional, boolean] also check that element to be visible if set to true
122
+ # @return [boolean]
123
+ #
124
+ # @example Specify a text box named :address expected on the page within 10 seconds
125
+ # expected_element_visible(:address, 10)
126
+ # page.has_expected_element_visible?
127
+ #
128
+ def expected_element_visible(element_name, timeout=::PageObject.default_element_wait, check_visible=false)
129
+ define_method("has_expected_element_visible?") do
130
+ self.respond_to? "#{element_name}_element" and self.send("#{element_name}_element").when_present timeout
131
+ self.respond_to? "#{element_name}_element" and self.send("#{element_name}_element").when_visible timeout
132
+ end
133
+ end
134
+
88
135
  #
89
136
  # Identify an element as existing within a frame or iframe. A frame parameter
90
137
  # is passed to the block and must be passed to the other calls to PageObject.
@@ -52,6 +52,13 @@ module PageObject
52
52
  element.inspect
53
53
  end
54
54
 
55
+ #
56
+ # retrieve the class name for an element
57
+ #
58
+ def class_name
59
+ attribute 'class'
60
+ end
61
+
55
62
  # @private
56
63
  def self.watir_identifier_for identifier
57
64
  if should_build_watir_xpath(identifier)
@@ -156,6 +156,15 @@ module PageObject
156
156
  bridge.executeScript("return arguments[0].focus()", element)
157
157
  end
158
158
 
159
+ #
160
+ # Select the provided text
161
+ #
162
+ def select_text(text)
163
+ Watir::Atoms.load(:selectText)
164
+ script = "return (%s).apply(null, arguments)" % ATOMS.fetch(:selectText)
165
+ bridge.executeScript(script, element, text)
166
+ end
167
+
159
168
  #
160
169
  # Click this element
161
170
  #
@@ -1,3 +1,5 @@
1
+ require 'watir-webdriver/extensions/select_text'
2
+
1
3
  module PageObject
2
4
  module Platforms
3
5
  #
@@ -141,6 +143,13 @@ module PageObject
141
143
  def focus
142
144
  element.focus
143
145
  end
146
+
147
+ #
148
+ # Select the provided text
149
+ #
150
+ def select_text(text)
151
+ element.select_text text
152
+ end
144
153
 
145
154
  #
146
155
  # Waits until the element is present
@@ -1,4 +1,4 @@
1
1
  module PageObject
2
2
  # @private
3
- VERSION = "0.9.2"
3
+ VERSION = "0.9.3"
4
4
  end
@@ -29,7 +29,11 @@ module PageObject
29
29
 
30
30
  def self.define_accessors(base, widget_tag, widget_class)
31
31
  accessors_module = Module.new do
32
- define_method widget_tag do |name, identifier={:index => 0}, &block|
32
+ define_method widget_tag do |name, *identifier_args, &block|
33
+
34
+ identifier = identifier_args.first
35
+ identifier = {:index => 0} if identifier.nil?
36
+
33
37
  define_method("#{name}_element") do
34
38
  return call_block(&block) if block
35
39
  platform.send("#{widget_tag}_for", identifier.clone)
data/page-object.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.require_paths = ["lib"]
22
22
 
23
23
  s.add_dependency 'watir-webdriver', '>= 0.6.4'
24
- s.add_dependency 'selenium-webdriver', '>= 2.35.0'
24
+ s.add_dependency 'selenium-webdriver', '>= 2.37.0'
25
25
  s.add_dependency 'page_navigation', '>= 0.8'
26
26
 
27
27
  s.add_development_dependency 'rspec', '>= 2.12.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: page-object
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Morgan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-23 00:00:00.000000000 Z
11
+ date: 2013-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: watir-webdriver
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '>='
32
32
  - !ruby/object:Gem::Version
33
- version: 2.35.0
33
+ version: 2.37.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
- version: 2.35.0
40
+ version: 2.37.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: page_navigation
43
43
  requirement: !ruby/object:Gem::Requirement