sparkling_watir 0.0.3 → 0.0.4

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
  SHA256:
3
- metadata.gz: cb95d81bc23cf2938bd4b20fa4cb06e18b7b104f4a2db9477f0e5d4b822577d0
4
- data.tar.gz: dd4d2c67b98376c94707109e38d26e938f4af779e5f92e1752b77cc7d97e78c7
3
+ metadata.gz: 7a87414a7834c36844d2e47020d15d809b925d344bf8d9f4fd9874c108834320
4
+ data.tar.gz: 6ca3f1ae39508f054faafb8f4ea9a91763e55e428fa59c2d77c4540df456000c
5
5
  SHA512:
6
- metadata.gz: 3b7d5973211467df06ede87056ad6269359c7e0fbc420831ef956a27eb28050e0dd208ad4b35b628e38a127c24840f35a359a0fb74c2c83a22e5a684847094d9
7
- data.tar.gz: 8aed1b54a5c1b2815abe4e77af649aff96efdadd217bee16869f68f9b4e4c63821759dbb1bacf550307ded1d52debd3fa34e46105c6ec4d0283a9dd800cca269
6
+ metadata.gz: 9355fff2a6b746a97e4504c8a69a155bed70acb73c27a0cf4a05a293aae62113bb0f0d22ddafa5fac8dedf85107ed48a90db83849261922753b98a8fdf45f7d2
7
+ data.tar.gz: 3ded479d13da1803805a6662fbc20f5a392a4bc2396d7ccaa68ef99c033d0bbf97a1e8559e40e3601b188ddffe2ed237c916efec26bbb51d6431e99a2fa35044
@@ -8,7 +8,6 @@ module SparklingWatir
8
8
  # This is a element in the native app context
9
9
  #
10
10
  class Element
11
- include Gestures
12
11
  include Waitable
13
12
 
14
13
  def initialize(driver, selector)
@@ -68,6 +67,10 @@ module SparklingWatir
68
67
  }
69
68
  end
70
69
 
70
+ def attribute(attribute_name)
71
+ wd.attribute(attribute_name)
72
+ end
73
+
71
74
  private
72
75
 
73
76
  def locate
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'appium_lib_core/common/touch_action/touch_actions'
4
3
  require 'selenium/webdriver/common/interactions/interactions'
5
4
 
6
5
  module SparklingWatir
@@ -16,57 +15,88 @@ module SparklingWatir
16
15
  @driver.perform_actions actions
17
16
  end
18
17
 
19
- def tap(timeout = nil)
20
- wait_until(timeout: timeout, &:present?)
18
+ def tap(opts = {})
19
+ coordinates = { x: opts[:x] || opts[:on].center[:x], y: opts[:y] || opts[:on].center[:y] }
21
20
  tap = action(:touch, 'tap')
22
- tap.create_pointer_move(duration: 0.1, x: center[:x], y: center[:y], origin: VIEWPORT)
21
+ tap.create_pointer_move(duration: 0.1, x: coordinates[:x], y: coordinates[:y], origin: VIEWPORT)
23
22
  tap.create_pointer_down(:left)
23
+ tap.create_pause(opts[:duration] || 0)
24
24
  tap.create_pointer_up(:left)
25
25
  perform tap
26
26
  end
27
27
 
28
28
  alias press tap
29
29
 
30
- def double_tap
31
- wait_until(&:present?)
30
+ def double_tap(opts = {})
32
31
  double_tap = action(:touch, 'double_tap')
33
- tap.create_pointer_move(duration: 0.1, x: center[:x], y: center[:y], origin: VIEWPORT)
32
+ coordinates = { x: opts[:x] || opts[:on].center[:x], y: opts[:y] || opts[:on].center[:y] }
33
+ double_tap.create_pointer_move(duration: 0, x: coordinates[:x], y: coordinates[:y], origin: VIEWPORT)
34
34
  double_tap.create_pointer_down(:left)
35
+ double_tap.create_pause(0.1)
35
36
  double_tap.create_pointer_up(:left)
37
+ double_tap.create_pause(0.1)
36
38
  double_tap.create_pointer_down(:left)
39
+ double_tap.create_pause(0.1)
37
40
  double_tap.create_pointer_up(:left)
38
41
 
39
42
  perform double_tap
40
43
  end
41
44
 
45
+ def long_press(opts = {})
46
+ tap(duration: opts[:duration] || 0.5, on: opts[:on])
47
+ end
48
+
42
49
  def swipe(opts = {})
43
- wait_until(&:present?)
44
- start_coordinates = self.center
45
- end_coordinates = select_direction(opts[:to].wait_until(&:exists?).center[:x], opts[:to].wait_until(&:exists?).center[:y], opts[:direction])
46
- duration = opts[:duration] || 1
47
- execute_swipe(duration, start_coordinates, end_coordinates)
50
+ coordinates = select_direction(opts[:to], opts[:direction])
51
+ execute_swipe(coordinates)
48
52
  end
49
53
 
50
54
  private
51
55
 
52
- def execute_swipe(duration, start_coordinates, end_coordinates)
56
+ def execute_swipe(coordinates)
53
57
  finger = action(:touch, 'swipe')
54
- finger.create_pointer_move(duration: duration, x: start_coordinates[:x], y: start_coordinates[:y],
58
+ finger.create_pointer_move(duration: 0, x: coordinates[:start_coordinates][:x],
59
+ y: coordinates[:start_coordinates][:y],
55
60
  origin: VIEWPORT)
56
61
  finger.create_pointer_down(:left)
57
- finger.create_pointer_move(duration: duration, x: end_coordinates[:x], y: end_coordinates[:y],
62
+ finger.create_pause(0.6)
63
+ finger.create_pointer_move(duration: 0.6, x: coordinates[:end_coordinates][:x],
64
+ y: coordinates[:end_coordinates][:y],
58
65
  origin: VIEWPORT)
59
66
  finger.create_pointer_up(:left)
67
+ finger.create_pointer_down(:left)
68
+
60
69
  perform finger
61
70
  end
62
71
 
63
- def select_direction(x, y, direction)
72
+ def select_direction(element, direction)
64
73
  case direction
65
- when :down then { x: x, y: - y } # For swipe down, increase y-coordinate
66
- when :up then { x: x, y: y * 20 } # For swipe up, decrease y-coordinate
67
- when :left, :right then { x: x, y: y }
74
+ when :down
75
+ start_x = element.center[:x]
76
+ start_y = @driver.window_size.height * 0.8
77
+ end_x = element.center[:x]
78
+ end_y = element.center[:y]
79
+ when :up
80
+ start_x = @driver.window_size.width / 2
81
+ start_y = @driver.window_size.height * 0.2
82
+ end_x = element.center[:x]
83
+ end_y = element.center[:y] / 0.5
84
+ when :left
85
+ start_x = @driver.window_size.width
86
+ start_y = element.center[:y]
87
+ end_x = element.center[:x]
88
+ end_y = element.center[:y]
89
+ when :right
90
+ start_x = @driver.window_size.width
91
+ start_y = element.center[:y]
92
+ end_x = element.center[:x]
93
+ end_y = element.center[:y]
68
94
  else raise "You selected an invalid direction. The valid directions are: :down, :up, :left, :right"
69
95
  end
96
+ {
97
+ start_coordinates: { x: start_x, y: start_y },
98
+ end_coordinates: { x: end_x, y: end_y }
99
+ }
70
100
  end
71
101
  end
72
102
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'forwardable'
16
+ require 'logger'
17
+
18
+ module SparklingWatir
19
+ module Logger
20
+ #
21
+ # @example Use logger manually
22
+ # SparklingWatir::Logger.debug('This is info message')
23
+ # SparklingWatir::Logger.warn('This is warning message')
24
+ #
25
+ class << self
26
+ extend Forwardable
27
+ def_delegators :logger, :fatal, :error, :warn, :info, :debug, :level, :level=, :formatter, :formatter=
28
+
29
+ attr_writer :logger
30
+
31
+ private
32
+
33
+ def logger
34
+ @logger ||= begin
35
+ logger = ::Logger.new($stdout)
36
+ logger.progname = 'sparkling_watir'
37
+ logger.level = ::Logger::WARN
38
+ logger.formatter = proc { |_severity, _datetime, _progname, msg| "#{msg}\n" }
39
+ logger
40
+ end
41
+ end
42
+ end # class << self
43
+ end # module Logger
44
+ end # module SparklingWatir
@@ -0,0 +1,50 @@
1
+ module SparklingWatir
2
+ class Screenshot
3
+ attr_reader :driver
4
+
5
+ def initialize(driver)
6
+ @driver = driver
7
+ end
8
+
9
+ #
10
+ # Saves screenshot to given path.
11
+ #
12
+ # @example
13
+ # driver.screenshot.save "screenshot.png"
14
+ #
15
+ # @param [String] path
16
+ #
17
+
18
+ def save(path)
19
+ driver.save_screenshot(path)
20
+ end
21
+
22
+ #
23
+ # Represents screenshot as PNG image string.
24
+ #
25
+ # @example
26
+ # driver.screenshot.png
27
+ # #=> '\x95\xC7\x8C@1\xC07\x1C(Edb\x15\xB2\vL'
28
+ #
29
+ # @return [String]
30
+ #
31
+
32
+ def png
33
+ driver.screenshot_as(:png)
34
+ end
35
+
36
+ #
37
+ # Represents screenshot as Base64 encoded string.
38
+ #
39
+ # @example
40
+ # driver.screenshot.base64
41
+ # #=> '7HWJ43tZDscPleeUuPW6HhN3x+z7vU/lufmH0qNTtTum94IBWMT46evImci1vnFGT'
42
+ #
43
+ # @return [String]
44
+ #
45
+
46
+ def base64
47
+ driver.screenshot_as(:base64)
48
+ end
49
+ end # Screenshot
50
+ end # SparklingWatir
@@ -2,17 +2,22 @@
2
2
 
3
3
  require 'appium_lib_core'
4
4
  require 'watir'
5
+ require_relative './sparkling_watir/gestures'
6
+ require_relative './sparkling_watir/logger'
7
+ require_relative './sparkling_watir/screenshot'
5
8
 
6
9
  module SparklingWatir
7
10
  #
8
- # For driving a native application or a native app context
11
+ # For driving a native application
9
12
  #
10
13
  class App
11
14
  attr_accessor :driver
12
15
 
16
+ include Gestures
17
+
13
18
  def initialize(opts)
14
- url = opts[:caps]
15
- @driver = Appium::Core::Driver.for(opts).start_driver(server_url: 'http://localhost:4723/wd/hub')
19
+ url = opts[:caps]['url']
20
+ @driver = Appium::Core::Driver.for(opts).start_driver(server_url: url)
16
21
  end
17
22
 
18
23
  def quit
@@ -25,6 +30,10 @@ module SparklingWatir
25
30
  Element.new(driver, selector)
26
31
  end
27
32
 
33
+ def screenshot
34
+ Screenshot.new self
35
+ end
36
+
28
37
  def method_missing(method_name, *arguments, &block)
29
38
  if driver.respond_to? method_name
30
39
  driver.send method_name, *arguments, &block
@@ -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.0.3'
8
+ spec.version = '0.0.4'
9
9
  spec.authors = ['Agustin Pequeno']
10
10
  spec.email = ['agustin.pe94@gmail.com']
11
11
 
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.0.3
4
+ version: 0.0.4
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-11 00:00:00.000000000 Z
11
+ date: 2023-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -138,6 +138,8 @@ files:
138
138
  - lib/sparkling_watir.rb
139
139
  - lib/sparkling_watir/element.rb
140
140
  - lib/sparkling_watir/gestures.rb
141
+ - lib/sparkling_watir/logger.rb
142
+ - lib/sparkling_watir/screenshot.rb
141
143
  - lib/sparkling_watir/wait.rb
142
144
  - lib/sparkling_watir/wait/timer.rb
143
145
  - sparkling_watir.gemspec