percy-appium-app 0.0.1 → 0.0.2.pre.beta.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
  SHA256:
3
- metadata.gz: ba54dc346521591705be68354e98b25018a98a1af988b9d05c7b3e6d6120b92f
4
- data.tar.gz: 5fe4abc08f138a09c1f5c95f327f9bebb8c9d4f7899cd0ffbe233d2d95cb5e86
3
+ metadata.gz: dc24fb11453d4229be74084dcbf4fd87956c644bea38edf77b841cb154e4e214
4
+ data.tar.gz: cfdf2bf47fc198a729020862676caf4580a9a40df65c47264e2b614ae9869c4e
5
5
  SHA512:
6
- metadata.gz: 5434a1ce14329a48bf5411050de8c466ec40e77f3545fa159d566d077d28d88ce027a7ed87ea3a3cf0cc6a851350376a7218d93e6250de93cc165e5ba6179196
7
- data.tar.gz: 2a8f9febe81d0490ed25d4f8bca3a2b24851a62d5c51ea33527629e72e810de9a4e0e94593f88727ffe42c25237c43aab785529d1e7bb4d24b5fd81488fedd8e
6
+ metadata.gz: 49ba2a7afbd146dc3e4c32052f769c7359a79e8e8ec62fd11147da1f950d4dbc4e892c5a63f6d2851848f75e163d4e19eeca5f8c56c21d0db848004d285dcd9f
7
+ data.tar.gz: 77cb99772da0e0739dcbe64085d138c689981d7d40942363edf6642da81cd96cded01d3614eedd31f682a88bef35dd8d0ec59a69633ace69f9b6cc92e6f42b3a
data/Gemfile CHANGED
@@ -11,3 +11,4 @@ gem 'tempfile'
11
11
  gem 'webmock', '~> 3.18', '>= 3.18.1'
12
12
  gem 'webrick', '~> 1.3', '>= 1.3.1'
13
13
  gem 'rake', '~> 13.0'
14
+ gem 'rspec-core'
data/README.md CHANGED
@@ -1 +1,193 @@
1
- # percy-appium-ruby
1
+ # percy-appium-ruby
2
+
3
+ [Percy](https://percy.io) visual testing for Ruby Appium.
4
+
5
+ ## Installation
6
+
7
+ npm install `@percy/cli`:
8
+
9
+ ```sh-session
10
+ $ npm install --save-dev @percy/cli
11
+ ```
12
+
13
+ gem install Percy appium package:
14
+
15
+ ```ssh-session
16
+ $ gem install percy-appium-app
17
+ ```
18
+
19
+
20
+ ## Usage
21
+
22
+ This is an example test using the `percy_screenshot` function.
23
+
24
+ ``` ruby
25
+ require 'appium_lib'
26
+ require 'percy-appium-app'
27
+
28
+ username = '<BROWSERSTACK_USERNAME>'
29
+ access_key = '<ACCESS_KEY>'
30
+
31
+ capabilities = {
32
+ 'platformName' => 'android',
33
+ 'platformVersion' => '13.0',
34
+ 'deviceName' => 'Google Pixel 7',
35
+ 'bstack:options' => {
36
+ 'appiumVersion' => '2.0.1'
37
+ },
38
+ 'app' => '<APP LINK>',
39
+ 'appium:percyOptions' => {
40
+ # enabled is default True. This can be used to disable visual testing for certain capabilities
41
+ 'enabled' => true
42
+ }
43
+ }
44
+
45
+ appium_driver = Appium::Driver.new(
46
+ {
47
+ 'caps' => capabilities,
48
+ 'appium_lib' => {
49
+ server_url: "https://#{username}:#{access_key}@hub-cloud.browserstack.com/wd/hub"
50
+ }
51
+ }, true
52
+ )
53
+ driver = appium_driver.start_driver
54
+
55
+ # take a screenshot
56
+ percy_screenshot(driver, 'here is some name')
57
+ ```
58
+
59
+ Running the test above normally will result in the following log:
60
+
61
+ ```sh-session
62
+ [percy] Percy is not running, disabling screenshots
63
+ ```
64
+
65
+ When running with [`percy
66
+ app:exec`](https://github.com/percy/cli/tree/master/packages/cli-exec#app-exec), and your project's
67
+ `PERCY_TOKEN`, a new Percy build will be created and screenshots will be uploaded to your project.
68
+
69
+ ```sh-session
70
+ $ export PERCY_TOKEN=[your-project-token]
71
+ $ percy app:exec -- [ruby test command]
72
+ [percy] Percy has started!
73
+ [percy] Created build #1: https://percy.io/[your-project]
74
+ [percy] Screenshot taken "Ruby example"
75
+ [percy] Stopping percy...
76
+ [percy] Finalized build #1: https://percy.io/[your-project]
77
+ [percy] Done!
78
+ ```
79
+
80
+ ## Configuration
81
+
82
+ `percy_screenshot(driver, name[, **kwargs])`
83
+
84
+ - `driver` (**required**) - A appium driver instance
85
+ - `name` (**required**) - The screenshot name; must be unique to each screenshot
86
+ - `device_name` (**optional**) - The device name used for capturing screenshot
87
+ - `orientation` (**optional**) - Orientation of device while capturing screeenshot; Allowed values [`portrait` | `landscape`]
88
+ - `status_bar_height` (**optional**) - Height of status bar; int
89
+ - `nav_bar_height` (**optional**) - Height of navigation bar; int
90
+ - `fullpage` (**optional**) - [Alpha] Only supported on App Automate driver sessions [ needs @percy/cli 1.20.2+ ]; boolean
91
+ - `screen_lengths` (**optional**) - [Alpha] Max screen lengths for fullPage; int
92
+ - In case scrollview is overlapping with other app elements. Offsets can be provided to reduce the area which needs to be considered for scrolling:
93
+ - `top_scrollview_offset`: (**optional**) - [Alpha] Offset from top of scrollview; int
94
+ - `bottom_scrollview_offset` (**optional**) - [Alpha] Offset from bottom of scrollview; int
95
+ - `full_screen` (**optional**) - Indicate whether app is full screen; boolean [ needs @percy/cli 1.20.2+ ];
96
+ - `sync` (**optional**) - Waits for screenshot to be processed and gives the processed result of screenshot [needs @percy/cli v1.28.0-beta.0+]; boolean
97
+ - `scrollable_xpath` (**optional**) - [Alpha] Scrollable element xpath for fullpage [ needs @percy/cli 1.20.2+ ]; string
98
+ - `scrollable_id` (**optional**) - [Alpha] Scrollable element accessibility id for fullpage [ needs @percy/cli 1.20.2+ ]; string
99
+ - `ignore_regions_xpaths` (**optional**) - Elements xpaths that user want to ignore in visual diff [ needs @percy/cli 1.23.0+ ]; list of string
100
+ - `ignore_region_accessibility_ids` (**optional**) - Elements accessibility_ids that user want to ignore in visual diff [ needs @percy/cli 1.23.0+ ]; list of string
101
+ - `ignore_region_appium_elements` (**optional**) - Appium elements that user want to ignore in visual diff [ needs @percy/cli 1.23.0+ ]; list of appium element object
102
+ - `custom_ignore_regions` (**optional**) - Custom locations that user want to ignore in visual diff [ needs @percy/cli 1.23.0+ ]; list of ignore_region object
103
+ - IgnoreRegion:-
104
+ - Description: This class represents a rectangular area on a screen that needs to be ignored for visual diff.
105
+ - Constructor:
106
+ ```
107
+ init(self, top, bottom, left, right)
108
+ ```
109
+ - Parameters:
110
+ - `top` (int): Top coordinate of the ignore region.
111
+ - `bottom` (int): Bottom coordinate of the ignore region.
112
+ - `left` (int): Left coordinate of the ignore region.
113
+ - `right` (int): Right coordinate of the ignore region.
114
+
115
+ ## Running with Hybrid Apps
116
+
117
+ For a hybrid app, we need to switch to native context before taking screenshot.
118
+
119
+ - Add a helper method similar to following for say flutter based hybrid app:
120
+ ```ruby
121
+ def percy_screenshot_flutter(driver, name: str, **kwargs):
122
+ driver.switch_to.context('NATIVE_APP')
123
+ percy_screenshot(driver, name, **kwargs)
124
+ driver.switch_to.context('FLUTTER')
125
+ end
126
+ ```
127
+
128
+ - Call PercyScreenshotFlutter helper function when you want to take screenshot.
129
+ ```ruby
130
+ percy_screenshot_flutter(driver, name, **kwargs)
131
+ ```
132
+
133
+ > Note:
134
+ >
135
+ > For other hybrid apps the `driver.switch_to.context('FLUTTER')` would change to context that it uses like say WEBVIEW etc.
136
+ >
137
+
138
+ ## Running Percy on Automate
139
+ `percy_screenshot(driver, name, options)` [ needs @percy/cli 1.27.0-beta.0+ ];
140
+ - `driver` (**required**) - A appium driver instance
141
+ - `name` (**required**) - The screenshot name; must be unique to each screenshot
142
+ - `options` (**optional**) - There are various options supported by percy_screenshot to server further functionality.
143
+ - `sync` - Boolean value by default it falls back to `false`, Gives the processed result around screenshot [From CLI v1.28.0-beta.0+].
144
+ - `freeze_animated_image` - Boolean value by default it falls back to `false`, you can pass `true` and percy will freeze image based animations.
145
+ - `freeze_image_by_selectors` -List of selectors. Images will be freezed which are passed using selectors. For this to work `freeze_animated_image` must be set to true.
146
+ - `freeze_image_by_xpaths` - List of xpaths. Images will be freezed which are passed using xpaths. For this to work `freeze_animated_image` must be set to true.
147
+ - `percy_css` - Custom CSS to be added to DOM before the screenshot being taken. Note: This gets removed once the screenshot is taken.
148
+ - `ignore_region_xpaths` - List of xpaths. elements in the DOM can be ignored using xpath
149
+ - `ignore_region_selectors` - List of selectors. elements in the DOM can be ignored using selectors.
150
+ - `ignore_region_appium_elements` - List of appium web-element. elements can be ignored using appium_elements.
151
+ - `custom_ignore_regions` - List of custom objects. elements can be ignored using custom boundaries. Just passing a simple object for it like below.
152
+ - example: ```{"top": 10, "right": 10, "bottom": 120, "left": 10}```
153
+ - In above example it will draw rectangle of ignore region as per given coordinates.
154
+ - `top` (int): Top coordinate of the ignore region.
155
+ - `bottom` (int): Bottom coordinate of the ignore region.
156
+ - `left` (int): Left coordinate of the ignore region.
157
+ - `right` (int): Right coordinate of the ignore region.
158
+ - `consider_region_xpaths` - List of xpaths. elements in the DOM can be considered for diffing and will be ignored by Intelli Ignore using xpaths.
159
+ - `consider_region_selectors` - List of selectors. elements in the DOM can be considered for diffing and will be ignored by Intelli Ignore using selectors.
160
+ - `consider_region_appium_elements` - List of appium web-element. elements can be considered for diffing and will be ignored by Intelli Ignore using appium_elements.
161
+ - `custom_consider_regions` - List of custom objects. elements can be considered for diffing and will be ignored by Intelli Ignore using custom boundaries
162
+ - example:```{"top": 10, "right": 10, "bottom": 120, "left": 10}```
163
+ - In above example it will draw rectangle of consider region will be drawn.
164
+ - Parameters:
165
+ - `top` (int): Top coordinate of the consider region.
166
+ - `bottom` (int): Bottom coordinate of the consider region.
167
+ - `left` (int): Left coordinate of the consider region.
168
+ - `right` (int): Right coordinate of the consider region.
169
+
170
+ ### Creating Percy on automate build
171
+ Note: Automate Percy Token starts with `auto` keyword. The command can be triggered using `exec` keyword.
172
+
173
+ ```sh-session
174
+ $ export PERCY_TOKEN=[your-project-token]
175
+ $ percy exec -- [ruby test command]
176
+ [percy] Percy has started!
177
+ [percy] [Ruby example] : Starting automate screenshot ...
178
+ [percy] Screenshot taken "Ruby example"
179
+ [percy] Stopping percy...
180
+ [percy] Finalized build #1: https://percy.io/[your-project]
181
+ [percy] Done!
182
+ ```
183
+
184
+ Refer to docs here: [Percy on Automate](https://docs.percy.io/docs/integrate-functional-testing-with-visual-testing)
185
+
186
+ ### Migrating Config
187
+
188
+ If you have a previous Percy configuration file, migrate it to the newest version with the
189
+ [`config:migrate`](https://github.com/percy/cli/tree/master/packages/cli-config#percy-configmigrate-filepath-output) command:
190
+
191
+ ```sh-session
192
+ $ percy config:migrate
193
+ ```
data/percy/environment.rb CHANGED
@@ -4,22 +4,24 @@ require 'appium_lib'
4
4
  require 'appium_lib/version'
5
5
  require_relative 'version'
6
6
 
7
- class Environment
8
- @percy_build_id = nil
9
- @percy_build_url = nil
10
- @session_type = nil
7
+ module Percy
8
+ class Percy::Environment
9
+ @percy_build_id = nil
10
+ @percy_build_url = nil
11
+ @session_type = nil
11
12
 
12
- class << self
13
- attr_accessor :percy_build_id, :percy_build_url, :session_type
13
+ class << self
14
+ attr_accessor :percy_build_id, :percy_build_url, :session_type
14
15
 
15
- def get_client_info(flag = false)
16
- sdk_version = SDK_VERSION
17
- flag ? "percy-appium-app-ruby/#{sdk_version}" : "percy-appium-app/#{sdk_version}"
18
- end
16
+ def get_client_info(flag = false)
17
+ sdk_version = Percy::VERSION
18
+ flag ? "percy-appium-app-ruby/#{sdk_version}" : "percy-appium-app/#{sdk_version}"
19
+ end
19
20
 
20
- def get_env_info
21
- appium_version = Appium::VERSION # This assumes the 'appium_lib' gem provides a VERSION constant.
22
- ["appium/#{appium_version}", "ruby/#{RUBY_VERSION}"]
21
+ def get_env_info
22
+ appium_version = Appium::VERSION # This assumes the 'appium_lib' gem provides a VERSION constant.
23
+ ["appium/#{appium_version}", "ruby/#{RUBY_VERSION}"]
24
+ end
23
25
  end
24
26
  end
25
27
  end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  class BaseException < StandardError; end
4
2
 
5
3
  class UnsupportedDevice < BaseException; end
@@ -6,50 +6,51 @@ require_relative 'percy_options'
6
6
  require_relative '../providers/provider_resolver'
7
7
  require_relative '../metadata/metadata_resolver'
8
8
 
9
- class AppPercy
10
- attr_accessor :metadata, :provider
9
+ module Percy
10
+ class AppPercy
11
+ attr_accessor :metadata, :provider
11
12
 
12
- def initialize(driver)
13
- raise DriverNotSupported unless driver.is_a?(Appium::Core::Base::Driver)
13
+ def initialize(driver)
14
+ raise DriverNotSupported unless driver.is_a?(Appium::Core::Base::Driver)
14
15
 
15
- @driver = driver
16
- @metadata = MetadataResolver.resolve(@driver)
17
- @provider = ProviderResolver.resolve(@driver)
18
- @percy_options = PercyOptions.new(@metadata.capabilities)
19
- end
16
+ @driver = driver
17
+ @metadata = Percy::MetadataResolver.resolve(@driver)
18
+ @provider = Percy::ProviderResolver.resolve(@driver)
19
+ @percy_options = Percy::PercyOptions.new(@metadata.capabilities)
20
+ end
20
21
 
21
- def screenshot(name, **kwargs)
22
- return nil unless @percy_options.enabled
22
+ def screenshot(name, **kwargs)
23
+ return nil unless @percy_options.enabled
23
24
 
24
- raise TypeError, 'Argument name should be a String' unless name.is_a?(String)
25
+ raise TypeError, 'Argument name should be a String' unless name.is_a?(String)
25
26
 
26
- device_name = kwargs[:device_name]
27
- raise TypeError, 'Argument device_name should be a String' if device_name && !device_name.is_a?(String)
27
+ device_name = kwargs[:device_name]
28
+ raise TypeError, 'Argument device_name should be a String' if device_name && !device_name.is_a?(String)
28
29
 
29
- fullscreen = kwargs[:full_screen]
30
- if fullscreen && !fullscreen.is_a?(TrueClass) && !fullscreen.is_a?(FalseClass)
31
- raise TypeError,
32
- 'Argument fullscreen should be a Boolean'
33
- end
30
+ fullscreen = kwargs[:full_screen]
31
+ if fullscreen && !fullscreen.is_a?(TrueClass) && !fullscreen.is_a?(FalseClass)
32
+ raise TypeError,
33
+ 'Argument fullscreen should be a Boolean'
34
+ end
34
35
 
35
- status_bar_height = kwargs[:status_bar_height]
36
- if status_bar_height && !status_bar_height.is_a?(Integer)
37
- raise TypeError,
38
- 'Argument status_bar_height should be an Integer'
39
- end
36
+ status_bar_height = kwargs[:status_bar_height]
37
+ if status_bar_height && !status_bar_height.is_a?(Integer)
38
+ raise TypeError,
39
+ 'Argument status_bar_height should be an Integer'
40
+ end
41
+
42
+ nav_bar_height = kwargs[:nav_bar_height]
43
+ raise TypeError, 'Argument nav_bar_height should be an Integer' if nav_bar_height && !nav_bar_height.is_a?(Integer)
40
44
 
41
- nav_bar_height = kwargs[:nav_bar_height]
42
- raise TypeError, 'Argument nav_bar_height should be an Integer' if nav_bar_height && !nav_bar_height.is_a?(Integer)
45
+ orientation = kwargs[:orientation]
46
+ if orientation && !orientation.is_a?(String)
47
+ raise TypeError,
48
+ 'Argument orientation should be a String and portrait/landscape'
49
+ end
43
50
 
44
- orientation = kwargs[:orientation]
45
- if orientation && !orientation.is_a?(String)
46
- raise TypeError,
47
- 'Argument orientation should be a String and portrait/landscape'
51
+ @provider.screenshot(name, **kwargs)
48
52
  end
49
53
 
50
- @provider.screenshot(name, **kwargs)
51
- nil
54
+ attr_reader :percy_options
52
55
  end
53
-
54
- attr_reader :percy_options
55
56
  end
data/percy/lib/cache.rb CHANGED
@@ -1,53 +1,54 @@
1
1
  # frozen_string_literal: true
2
+ module Percy
3
+ class Cache
4
+ attr_reader :cache
5
+
6
+ @@cache = {}
7
+ CACHE_TIMEOUT = 5 * 60 # 5 * 60 seconds
8
+ TIMEOUT_KEY = 'last_access_time'
9
+
10
+ SESSION_DETAILS = 'session_details'
11
+ SYSTEM_BARS = 'system_bars'
12
+ WINDOW_SIZE = 'window_size'
13
+ VIEWPORT = 'viewport'
14
+ SESSION_CAPABILITIES = 'session_capabilities'
15
+ CAPABILITIES = 'capabilities'
16
+ COMMAND_EXECUTOR_URL = 'command_executor_url'
17
+
18
+ def cache
19
+ @@cache
20
+ end
2
21
 
3
- class Cache
4
- attr_reader :cache
5
-
6
- @@cache = {}
7
- CACHE_TIMEOUT = 5 * 60 # 5 * 60 seconds
8
- TIMEOUT_KEY = 'last_access_time'
9
-
10
- SESSION_DETAILS = 'session_details'
11
- SYSTEM_BARS = 'system_bars'
12
- WINDOW_SIZE = 'window_size'
13
- VIEWPORT = 'viewport'
14
- SESSION_CAPABILITIES = 'session_capabilities'
15
- CAPABILITIES = 'capabilities'
16
- COMMAND_EXECUTOR_URL = 'command_executor_url'
17
-
18
- def cache
19
- @@cache
20
- end
22
+ def self.set_cache(session_id, property, value)
23
+ raise TypeError, 'Argument session_id should be a String' unless session_id.is_a?(String)
24
+ raise TypeError, 'Argument property should be a String' unless property.is_a?(String)
21
25
 
22
- def self.set_cache(session_id, property, value)
23
- raise TypeError, 'Argument session_id should be a String' unless session_id.is_a?(String)
24
- raise TypeError, 'Argument property should be a String' unless property.is_a?(String)
26
+ session = @@cache.fetch(session_id, {})
27
+ session[TIMEOUT_KEY] = Time.now.to_i
28
+ session[property] = value
29
+ @@cache[session_id] = session
30
+ end
25
31
 
26
- session = @@cache.fetch(session_id, {})
27
- session[TIMEOUT_KEY] = Time.now.to_i
28
- session[property] = value
29
- @@cache[session_id] = session
30
- end
32
+ def self.get_cache(session_id, property)
33
+ cleanup_cache
31
34
 
32
- def self.get_cache(session_id, property)
33
- cleanup_cache
35
+ raise TypeError, 'Argument session_id should be a String' unless session_id.is_a?(String)
36
+ raise TypeError, 'Argument property should be a String' unless property.is_a?(String)
34
37
 
35
- raise TypeError, 'Argument session_id should be a String' unless session_id.is_a?(String)
36
- raise TypeError, 'Argument property should be a String' unless property.is_a?(String)
38
+ session = @@cache.fetch(session_id, {})
39
+ session.fetch(property, nil)
40
+ end
37
41
 
38
- session = @@cache.fetch(session_id, {})
39
- session.fetch(property, nil)
40
- end
42
+ def self.cleanup_cache
43
+ now = Time.now.to_i
44
+ session_ids = []
41
45
 
42
- def self.cleanup_cache
43
- now = Time.now.to_i
44
- session_ids = []
46
+ @@cache.each do |session_id, session|
47
+ timestamp = session[TIMEOUT_KEY]
48
+ session_ids << session_id if now - timestamp >= CACHE_TIMEOUT
49
+ end
45
50
 
46
- @@cache.each do |session_id, session|
47
- timestamp = session[TIMEOUT_KEY]
48
- session_ids << session_id if now - timestamp >= CACHE_TIMEOUT
51
+ session_ids.each { |session_id| @@cache.delete(session_id) }
49
52
  end
50
-
51
- session_ids.each { |session_id| @@cache.delete(session_id) }
52
53
  end
53
54
  end