sparkling_watir 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: 3380d869ffa3595391cc478a5d93bdb6236a767040550d964afd5e22da2aef9f
4
- data.tar.gz: 2bb22863cad09f16c5b67d71350c5c582a2ebaa59783f1c6cb34e6643f9cc9e6
3
+ metadata.gz: 6d1718777f4727027f7138b2693954512a8f9ec34947923c544f04e4223dc9bc
4
+ data.tar.gz: c63f086a9ea7a9730c04a5339f6a4344748bcde91a3e51331bb071a629556b10
5
5
  SHA512:
6
- metadata.gz: 617137f0d20e8d8b47b6b9fb156fb07ebb336cc221693fe83a29ca8161e48c689da354edc829ba284df1217252b5be33e4277c0272add29fc3a2108bc4bd5c87
7
- data.tar.gz: 8b56fb08ebee6400ec7eeee70ac03c7f7797bdecc18fa1daff0b8f766018af25a13563589e999eac3f6a212fc2b15d249e93fb7685e36a56984967f7af5ec8c2
6
+ metadata.gz: e84c10cf081151adcd7578d5de4133acf80366f96ee0b3b1b55f94691e94a990d2039b0c3d022c9e0e68c20de1cdafff1f71fc69b0c69292fca90685178ec211
7
+ data.tar.gz: 5199b89a3ad87ee8aeb84064f0ec1ae31f645818b19828d97fea5727e81dd2cd42959db657b20abda386319f4e9af9e5a82b9c467d37bc4bcdf6ee9d3cca152a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sparkling_watir (0.1.0)
4
+ sparkling_watir (0.1.1)
5
5
  appium_lib_core (~> 7.0.0)
6
6
  watir (~> 7.1.0)
7
7
 
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'gestures'
4
3
  require_relative 'wait'
5
4
 
6
5
  module SparklingWatir
@@ -8,17 +7,19 @@ module SparklingWatir
8
7
  # This is a element in the native app context
9
8
  #
10
9
  class Element
11
- attr_reader :driver
10
+ attr_reader :driver, :selector
11
+ attr_accessor :element
12
12
 
13
13
  include Waitable
14
14
 
15
- def initialize(driver, selector)
15
+ def initialize(driver = nil, selector = nil, element = nil)
16
16
  @driver = driver
17
17
  @selector = selector
18
+ @element = element
18
19
  end
19
20
 
20
21
  def wd
21
- @element || locate
22
+ element || locate
22
23
  end
23
24
 
24
25
  def exists?
@@ -32,7 +33,7 @@ module SparklingWatir
32
33
 
33
34
  def present?
34
35
  assert_exists
35
- @element.displayed?
36
+ element&.displayed?
36
37
  rescue Watir::Exception::UnknownObjectException
37
38
  false
38
39
  end
@@ -41,21 +42,21 @@ module SparklingWatir
41
42
 
42
43
  def enabled?
43
44
  assert_exists
44
- @element.enabled?
45
+ element&.enabled?
45
46
  rescue Watir::Exception::UnknownObjectException
46
47
  false
47
48
  end
48
49
 
49
50
  def coordinates
50
51
  assert_exists
51
- @element.location
52
+ element&.location
52
53
  end
53
54
 
54
55
  alias location coordinates
55
56
 
56
57
  def size
57
58
  assert_exists
58
- @element.size
59
+ element&.size
59
60
  end
60
61
 
61
62
  def bounds
@@ -84,16 +85,15 @@ module SparklingWatir
84
85
  private
85
86
 
86
87
  def locate
87
- @element = @driver.find_element(@selector.keys.first, @selector.values.first)
88
+ @element ||= driver&.find_element(selector)
88
89
  rescue Selenium::WebDriver::Error::NoSuchElementError
89
90
  nil
90
91
  end
91
92
 
92
93
  def assert_exists
93
- locate unless @element
94
- return if @element
94
+ locate unless element
95
95
 
96
- raise Watir::Exception::UnknownObjectException
96
+ raise Watir::Exception::UnknownObjectException unless element
97
97
  end
98
98
  end
99
99
  end
@@ -0,0 +1,57 @@
1
+ require_relative 'element'
2
+
3
+ module SparklingWatir
4
+ class ElementCollection
5
+ include Enumerable
6
+
7
+ attr_reader :driver, :selector
8
+
9
+ def initialize(driver, selector)
10
+ @driver = driver
11
+ @selector = selector
12
+ @collection = create_collection
13
+ end
14
+
15
+ def add(element)
16
+ @collection << element
17
+ end
18
+
19
+ def each
20
+ @collection.each do |element|
21
+ yield element
22
+ end
23
+ end
24
+
25
+ alias length count
26
+ alias size count
27
+
28
+ alias empty? none?
29
+
30
+ alias exist? any?
31
+ alias exists? any?
32
+
33
+ def to_a
34
+ @collection
35
+ end
36
+
37
+ def [](value)
38
+ @collection[value]
39
+ end
40
+
41
+ def first
42
+ @collection.first
43
+ end
44
+
45
+ def last
46
+ @collection.last
47
+ end
48
+
49
+ private
50
+
51
+ def create_collection
52
+ elements = driver.find_elements selector
53
+
54
+ elements.map { |element| Element.new(driver, nil, element) }
55
+ end
56
+ end
57
+ end
@@ -30,6 +30,10 @@ module SparklingWatir
30
30
  Element.new(driver, selector)
31
31
  end
32
32
 
33
+ def elements(selector)
34
+ ElementCollection.new(driver, selector)
35
+ end
36
+
33
37
  def screenshot
34
38
  Screenshot.new driver
35
39
  end
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'sparkling_watir'
8
- spec.version = '0.1.0'
8
+ spec.version = '0.1.1'
9
9
  spec.authors = ['Agustin Pequeno']
10
10
  spec.email = ['agustin.pe94@gmail.com']
11
11
  spec.homepage = 'https://github.com/aguspe/sparkling_watir'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sparkling_watir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Agustin Pequeno
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-20 00:00:00.000000000 Z
11
+ date: 2023-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -138,6 +138,7 @@ files:
138
138
  - Rakefile
139
139
  - lib/sparkling_watir.rb
140
140
  - lib/sparkling_watir/element.rb
141
+ - lib/sparkling_watir/element_collection.rb
141
142
  - lib/sparkling_watir/gestures.rb
142
143
  - lib/sparkling_watir/logger.rb
143
144
  - lib/sparkling_watir/screenshot.rb