watir 6.4.3 → 6.5.0

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: 02350fa770d3f560edf82f8fdb3efb33667b5c79
4
- data.tar.gz: f25ed98f3c07012a3e7e6f940939872bd08e0a7b
3
+ metadata.gz: 6e19bc6a7d28d78bba208d88dd97a58bce85fc9d
4
+ data.tar.gz: 0031cc40646d67219270b7914369df5a7e084144
5
5
  SHA512:
6
- metadata.gz: 62938c328cc2a16ac0d4ba6c48aa2bc09f0ac155a73adcd1bf63449120ed49139ecdba3cda0a4eab39e7eb4d6cde1e598e0a023f867be83aca6813336b5b4f94
7
- data.tar.gz: 7b206faceabf70654fb6217fdcd7bb2be3f2ba9096c13dcbf97aaf68c5ea1af09e3d959b1c069397bf46caa7e5d990feae92fe77e7ced866df13c95e95ae5667
6
+ metadata.gz: f71791589c4bc26c594d25ffb755fec75a8cbf41c2d93e0bf8c9671573a66e2fac01a21618159c169fa79a25387963a5a79c6940a329b177939b305ede9c3dbd
7
+ data.tar.gz: 7ca2f02eb0a3c950f2e8b8e16ce8e1acb9c3dd8766637d8bc5c3594b49634c0dce2af3d7ec216add6d36f81968df69eb3b35215bd5a43c216b2c04883d350c98
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 6.5.0 (2017-07-25)
2
+
3
+ * Add support for locating multiple classes using :class parameter
4
+
1
5
  ### 6.4.3 (2017-07-19)
2
6
 
3
7
  * Fix bug with element relocation from ElementCollection
@@ -2,7 +2,7 @@ module Watir
2
2
  module Locators
3
3
  class Element
4
4
  class SelectorBuilder
5
- VALID_WHATS = [String, Regexp, TrueClass, FalseClass].freeze
5
+ VALID_WHATS = [Array, String, Regexp, TrueClass, FalseClass].freeze
6
6
  WILDCARD_ATTRIBUTE = /^(aria|data)_(.+)$/
7
7
 
8
8
  def initialize(query_scope, selector, valid_attributes)
@@ -35,6 +35,9 @@ module Watir
35
35
  raise TypeError, "expected TrueClass or FalseClass, got #{what.inspect}:#{what.class}"
36
36
  end
37
37
  else
38
+ if what.is_a?(Array) && how != :class
39
+ raise TypeError, "Only :class locator can have a value of an Array"
40
+ end
38
41
  unless VALID_WHATS.any? { |t| what.is_a? t }
39
42
  raise TypeError, "expected one of #{VALID_WHATS.inspect}, got #{what.inspect}:#{what.class}"
40
43
  end
@@ -26,7 +26,9 @@ module Watir
26
26
  # @todo Get rid of building
27
27
  def attribute_expression(building, selectors)
28
28
  f = selectors.map do |key, val|
29
- if val.is_a?(Array)
29
+ if val.is_a?(Array) && key == :class
30
+ "(" + val.map { |v| build_class_match(v) }.join(" and ") + ")"
31
+ elsif val.is_a?(Array)
30
32
  "(" + val.map { |v| equal_pair(building, key, v) }.join(" or ") + ")"
31
33
  elsif val == true
32
34
  attribute_presence(key)
@@ -42,8 +44,10 @@ module Watir
42
44
  # @todo Get rid of building
43
45
  def equal_pair(building, key, value)
44
46
  if key == :class
45
- klass = XpathSupport.escape " #{value} "
46
- "contains(concat(' ', @class, ' '), #{klass})"
47
+ if value.strip.include?(' ')
48
+ warn 'Using the :class locator to locate multiple classes with a String value is deprecated; use an Array instead'
49
+ end
50
+ build_class_match(value)
47
51
  elsif key == :label && @should_use_label_element
48
52
  # we assume :label means a corresponding label element, not the attribute
49
53
  text = "normalize-space()=#{XpathSupport.escape value}"
@@ -72,6 +76,16 @@ module Watir
72
76
 
73
77
  private
74
78
 
79
+ def build_class_match(value)
80
+ if value.match(/^!/)
81
+ klass = XpathSupport.escape " #{value[1..-1]} "
82
+ "not(contains(concat(' ', @class, ' '), #{klass}))"
83
+ else
84
+ klass = XpathSupport.escape " #{value} "
85
+ "contains(concat(' ', @class, ' '), #{klass})"
86
+ end
87
+ end
88
+
75
89
  def attribute_presence(attribute)
76
90
  lhs_for(nil, attribute)
77
91
  end
@@ -303,7 +303,7 @@ describe Watir::Locators::Element::Locator do
303
303
  it "raises a TypeError if selector value is not a String, Regexp or Boolean" do
304
304
  num_type = RUBY_VERSION[/^\d+\.(\d+)/, 1].to_i >= 4 ? 'Integer' : 'Fixnum'
305
305
  expect { locate_one(tag_name: 123) }.to \
306
- raise_error(TypeError, %[expected one of [String, Regexp, TrueClass, FalseClass], got 123:#{num_type}])
306
+ raise_error(TypeError, %[expected one of [Array, String, Regexp, TrueClass, FalseClass], got 123:#{num_type}])
307
307
  end
308
308
 
309
309
  it "raises a MissingWayOfFindingObjectException if the attribute is not valid" do
@@ -1,5 +1,3 @@
1
- require 'active_support/ordered_hash'
2
-
3
1
  module LocatorSpecHelper
4
2
  def browser
5
3
  @browser ||= double(Watir::Browser, wd: driver)
@@ -48,7 +46,7 @@ module LocatorSpecHelper
48
46
  when Hash
49
47
  selector
50
48
  when Array
51
- ActiveSupport::OrderedHash[*selector]
49
+ Hash[*selector]
52
50
  else
53
51
  raise ArgumentError, "couldn't create hash for #{selector.inspect}"
54
52
  end
@@ -237,16 +237,42 @@ describe "Element" do
237
237
  it "matches when the element has several classes" do
238
238
  e = browser.div(class: "b")
239
239
  expect(e).to exist
240
- expect(e.class_name).to eq "a b"
240
+ expect(e.class_name).to eq "a b c"
241
241
  end
242
242
 
243
243
  it "does not match only part of the class name" do
244
- expect(browser.div(class: "c")).to_not exist
244
+ expect(browser.div(class: "bc")).to_not exist
245
245
  end
246
246
 
247
247
  it "matches part of the class name when given a regexp" do
248
248
  expect(browser.div(class: /c/)).to exist
249
249
  end
250
+
251
+ context "with multiple classes" do
252
+ it "matches when the element has a single class" do
253
+ e = browser.div(class: ["a"])
254
+ expect(e).to exist
255
+ expect(e.class_name).to eq "a"
256
+ end
257
+
258
+ it "matches a non-ordered subset" do
259
+ e = browser.div(class: ["c", "a"])
260
+ expect(e).to exist
261
+ expect(e.class_name).to eq "a b c"
262
+ end
263
+
264
+ it "matches one with a negation" do
265
+ e = browser.div(class: ["!a"])
266
+ expect(e).to exist
267
+ expect(e.class_name).to eq "abc"
268
+ end
269
+
270
+ it "matches multiple with a negation" do
271
+ e = browser.div(class: ["a", "!c", "b"])
272
+ expect(e).to exist
273
+ expect(e.class_name).to eq "a b"
274
+ end
275
+ end
250
276
  end
251
277
 
252
278
  context "attribute presence" do
@@ -2,6 +2,7 @@
2
2
  <html>
3
3
  <body>
4
4
  <div class="a">a</div>
5
+ <div class="a b c">a b c</div>
5
6
  <div class="a b">a b</div>
6
7
  <div class="abc">abc</div>
7
8
  </body>
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'watir'
5
- s.version = '6.4.3'
5
+ s.version = '6.5.0'
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ['Alex Rodionov', 'Titus Fortner']
8
8
  s.email = ['p0deje@gmail.com', 'titusfortner@gmail.com']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watir
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.4.3
4
+ version: 6.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Rodionov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-07-19 00:00:00.000000000 Z
12
+ date: 2017-07-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: selenium-webdriver
@@ -481,7 +481,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
481
481
  version: '0'
482
482
  requirements: []
483
483
  rubyforge_project: watir
484
- rubygems_version: 2.5.2
484
+ rubygems_version: 2.6.11
485
485
  signing_key:
486
486
  specification_version: 4
487
487
  summary: Watir powered by Selenium