appium_lib_core 4.4.0 → 5.0.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
@@ -95,6 +95,11 @@ module Appium
95
95
  # @param [Bool] visualize Makes the endpoint to return an image, which contains the visualized result of
96
96
  # the corresponding picture matching operation. This option is disabled by default.
97
97
  # @param [Float, nil] threshold [0.5] At what normalized threshold to reject
98
+ # @param [bool, nil] multiple Whether to enable the support of multiple image occurrences @since Appium 1.21.0.
99
+ # @param [integer, nil] match_neighbour_threshold The pixel distance between matches we consider to be part of
100
+ # the same template match @since Appium 1.21.0.
101
+ # This option is only considered if multiple matches mode is enabled.
102
+ # 10 pixels by default.
98
103
  #
99
104
  # @example
100
105
  # @driver.find_image_occurrence full_image: "image data 1", partial_image: "image data 2"
@@ -102,12 +107,15 @@ module Appium
102
107
  # visual = @@driver.find_image_occurrence full_image: image1, partial_image: image2, visualize: true
103
108
  # File.write 'find_result_visual.png', Base64.decode64(visual['visualization']) # if the image is PNG
104
109
  #
105
- def find_image_occurrence(full_image:, partial_image:, visualize: false, threshold: nil)
110
+ def find_image_occurrence(full_image:, partial_image:, visualize: false, threshold: nil,
111
+ multiple: nil, match_neighbour_threshold: nil)
106
112
  raise "visualize should be #{MATCH_TEMPLATE[:visualize]}" unless MATCH_TEMPLATE[:visualize].member?(visualize)
107
113
 
108
114
  options = {}
109
115
  options[:visualize] = visualize
110
116
  options[:threshold] = threshold unless threshold.nil?
117
+ options[:multiple] = multiple unless multiple.nil?
118
+ options[:matchNeighbourThreshold] = match_neighbour_threshold unless match_neighbour_threshold.nil?
111
119
 
112
120
  compare_images(mode: :matchTemplate, first_image: full_image, second_image: partial_image, options: options)
113
121
  end
@@ -79,11 +79,7 @@ module Appium
79
79
  end
80
80
 
81
81
  def create_bridge_command(method, &block)
82
- ::Appium::Core::Base::Bridge::MJSONWP.class_eval do
83
- undef_method method if method_defined? method
84
- block_given? ? class_eval(&block) : define_method(method) { execute method }
85
- end
86
- ::Appium::Core::Base::Bridge::W3C.class_eval do
82
+ ::Appium::Core::Base::Bridge.class_eval do
87
83
  undef_method method if method_defined? method
88
84
  block_given? ? class_eval(&block) : define_method(method) { execute method }
89
85
  end
@@ -368,10 +368,10 @@ module Appium
368
368
 
369
369
  begin
370
370
  # included https://github.com/SeleniumHQ/selenium/blob/43f8b3f66e7e01124eff6a5805269ee441f65707/rb/lib/selenium/webdriver/remote/driver.rb#L29
371
- @driver = ::Appium::Core::Base::Driver.new(http_client: @http_client,
372
- desired_capabilities: @caps,
373
- url: @custom_url,
374
- listener: @listener)
371
+ @driver = ::Appium::Core::Base::Driver.new(listener: @listener,
372
+ http_client: @http_client,
373
+ desired_capabilities: @caps,
374
+ url: @custom_url)
375
375
 
376
376
  if @direct_connect
377
377
  d_c = DirectConnections.new(@driver.capabilities)
@@ -460,7 +460,9 @@ module Appium
460
460
  # @core.appium_server_version #=> {}
461
461
  #
462
462
  def appium_server_version
463
- @driver&.remote_status
463
+ return {} if @driver.nil?
464
+
465
+ @driver.remote_status
464
466
  rescue StandardError
465
467
  # Ignore error case in a case the target appium server
466
468
  # does not support `/status` API.
@@ -12,16 +12,12 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- # rubocop:disable Style/ClassAndModuleChildren
16
15
  module Appium
17
16
  module Core
18
17
  # Implement useful features for element.
19
18
  # Patch for Selenium Webdriver.
20
- class Selenium::WebDriver::Element
21
- # To extend Appium related SearchContext into ::Selenium::WebDriver::Element
19
+ class Element < ::Selenium::WebDriver::Element
22
20
  include ::Appium::Core::Base::SearchContext
23
-
24
- # TODO: Probably can remove own TakesScreenshot since Selenium 4
25
21
  include ::Appium::Core::Base::TakesScreenshot
26
22
 
27
23
  # Returns the value of attributes like below. Read each platform to know more details.
@@ -152,7 +148,6 @@ module Appium
152
148
  end
153
149
  File.open(png_path, 'wb') { |f| f << screenshot_as(:png) }
154
150
  end
155
- end
151
+ end # class Element
156
152
  end # module Core
157
153
  end # module Appium
158
- # rubocop:enable Style/ClassAndModuleChildren
@@ -21,7 +21,7 @@ module Appium
21
21
  # will trigger as soon as the file is required. in contrast a method
22
22
  # will trigger only when invoked.
23
23
  def self.patch_webdriver_element
24
- ::Selenium::WebDriver::Element.class_eval do
24
+ ::Appium::Core::Element.class_eval do
25
25
  # Cross platform way of entering text into a textfield
26
26
  def type(text, driver)
27
27
  driver.execute_script %(au.getElement('#{ref}').setValue('#{text}');)
@@ -14,7 +14,7 @@
14
14
 
15
15
  module Appium
16
16
  module Core
17
- VERSION = '4.4.0' unless defined? ::Appium::Core::VERSION
18
- DATE = '2021-02-13' unless defined? ::Appium::Core::DATE
17
+ VERSION = '5.0.0.beta3' unless defined? ::Appium::Core::VERSION
18
+ DATE = '2021-04-15' unless defined? ::Appium::Core::DATE
19
19
  end
20
20
  end
data/release_notes.md CHANGED
@@ -1,3 +1,17 @@
1
+ #### v4.5.0 2021-03-14
2
+
3
+ - [656230e](https://github.com/appium/ruby_lib_core/commit/656230e688ed86414c06efaa73bce7359933cc91) Release 4.5.0
4
+ - [a0a3cfc](https://github.com/appium/ruby_lib_core/commit/a0a3cfc71783bed3d1b0e7afbf6bc0a27bf60a48) feat: add speed option (#318)
5
+ - [16b4f09](https://github.com/appium/ruby_lib_core/commit/16b4f0991deb639314857c3cbece1e4d00393646) feat: add multiple and match_neighbour_threshold (#313)
6
+ - [d195a5b](https://github.com/appium/ruby_lib_core/commit/d195a5ba48c2e1a7229e0145eac616fd886c1ee0) ci: use node 12
7
+
8
+
9
+ #### v4.4.1 2021-02-15
10
+
11
+ - [dc34419](https://github.com/appium/ruby_lib_core/commit/dc34419dfcc4dd8d499a6407d45ab3efe70c2445) Release 4.4.1
12
+ - [3085048](https://github.com/appium/ruby_lib_core/commit/3085048b4816e3415017ebb188e653c8e229a05e) chore: return {} in nil case as well
13
+
14
+
1
15
  #### v4.4.0 2021-02-13
2
16
 
3
17
  - [06c68fb](https://github.com/appium/ruby_lib_core/commit/06c68fbe3ffdbb7b068d2f71ad6841c66dbabf8f) Release 4.4.0
data/script/commands.rb CHANGED
@@ -18,26 +18,18 @@ require './lib/appium_lib_core'
18
18
  module Script
19
19
  class CommandsChecker
20
20
  attr_reader :spec_commands,
21
- :implemented_mjsonwp_commands, :implemented_w3c_commands, :implemented_core_commands,
22
- :webdriver_oss_commands, :webdriver_w3c_commands
21
+ :implemented_w3c_commands, :implemented_core_commands,
22
+ :webdriver_w3c_commands
23
23
 
24
24
  # Set commands implemented in this core library.
25
25
  #
26
- # - implemented_mjsonwp_commands: All commands include ::Selenium::WebDriver::Remote::OSS::Bridge::COMMANDS
27
- # - implemented_w3c_commands: All commands include ::Selenium::WebDriver::Remote::W3C::Bridge::COMMANDS
26
+ # - implemented_w3c_commands: All commands include ::Selenium::WebDriver::Remote::Bridge::COMMANDS
28
27
  # - implemented_core_commands: All commands except for selenium-webdriver's commands
29
- # - webdriver_oss_commands: ::Selenium::WebDriver::Remote::OSS::Bridge::COMMANDS
30
- # - webdriver_w3c_commands: ::Selenium::WebDriver::Remote::W3C::Bridge::COMMANDS
31
28
  #
32
29
  def initialize
33
30
  @spec_commands = nil
34
31
 
35
- @implemented_mjsonwp_commands = convert_driver_commands Appium::Core::Commands::MJSONWP::COMMANDS
36
- @implemented_w3c_commands = convert_driver_commands Appium::Core::Commands::W3C::COMMANDS
37
32
  @implemented_core_commands = convert_driver_commands Appium::Core::Commands::COMMANDS
38
-
39
- @webdriver_oss_commands = convert_driver_commands Appium::Core::Base::Commands::OSS
40
- @webdriver_w3c_commands = convert_driver_commands Appium::Core::Base::Commands::W3C
41
33
  end
42
34
 
43
35
  # Get the bellow url's file.
@@ -80,18 +72,6 @@ module Script
80
72
  end
81
73
  end
82
74
 
83
- # All commands which haven't been implemented in ruby core library yet.
84
- # @return [Hash]
85
- #
86
- def all_diff_commands_mjsonwp
87
- result = compare_commands(@spec_commands, @implemented_mjsonwp_commands)
88
-
89
- white_list.each { |v| result.delete v }
90
- w3c_spec.each { |v| result.delete v }
91
-
92
- result
93
- end
94
-
95
75
  # All commands which haven't been implemented in ruby core library yet.
96
76
  # @return [Hash]
97
77
  #
@@ -111,20 +91,6 @@ module Script
111
91
  result
112
92
  end
113
93
 
114
- def diff_webdriver_oss
115
- result = compare_commands(@spec_commands, @webdriver_oss_commands)
116
- white_list.each { |v| result.delete v }
117
- w3c_spec.each { |v| result.delete v }
118
- result
119
- end
120
-
121
- def diff_webdriver_w3c
122
- result = compare_commands(@spec_commands, @webdriver_w3c_commands)
123
- white_list.each { |v| result.delete v }
124
- mjsonwp_spec.each { |v| result.delete v }
125
- result
126
- end
127
-
128
94
  def compare_commands(command1, with_command2)
129
95
  return {} if command1.nil?
130
96
  return command1 if with_command2.nil?
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appium_lib_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.0
4
+ version: 5.0.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuaki MATSUO
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-14 00:00:00.000000000 Z
11
+ date: 2021-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selenium-webdriver
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '3.14'
20
- - - ">="
17
+ - - '='
21
18
  - !ruby/object:Gem::Version
22
- version: 3.14.1
19
+ version: 4.0.0.beta3
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '3.14'
30
- - - ">="
24
+ - - '='
31
25
  - !ruby/object:Gem::Version
32
- version: 3.14.1
26
+ version: 4.0.0.beta3
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: faye-websocket
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -120,28 +114,28 @@ dependencies:
120
114
  requirements:
121
115
  - - "~>"
122
116
  - !ruby/object:Gem::Version
123
- version: 3.11.0
117
+ version: 3.12.1
124
118
  type: :development
125
119
  prerelease: false
126
120
  version_requirements: !ruby/object:Gem::Requirement
127
121
  requirements:
128
122
  - - "~>"
129
123
  - !ruby/object:Gem::Version
130
- version: 3.11.0
124
+ version: 3.12.1
131
125
  - !ruby/object:Gem::Dependency
132
126
  name: rubocop
133
127
  requirement: !ruby/object:Gem::Requirement
134
128
  requirements:
135
129
  - - '='
136
130
  - !ruby/object:Gem::Version
137
- version: 1.8.1
131
+ version: 1.12.0
138
132
  type: :development
139
133
  prerelease: false
140
134
  version_requirements: !ruby/object:Gem::Requirement
141
135
  requirements:
142
136
  - - '='
143
137
  - !ruby/object:Gem::Version
144
- version: 1.8.1
138
+ version: 1.12.0
145
139
  - !ruby/object:Gem::Dependency
146
140
  name: appium_thor
147
141
  requirement: !ruby/object:Gem::Requirement
@@ -262,11 +256,10 @@ files:
262
256
  - lib/appium_lib_core/common.rb
263
257
  - lib/appium_lib_core/common/base.rb
264
258
  - lib/appium_lib_core/common/base/bridge.rb
265
- - lib/appium_lib_core/common/base/bridge/mjsonwp.rb
266
- - lib/appium_lib_core/common/base/bridge/w3c.rb
267
259
  - lib/appium_lib_core/common/base/capabilities.rb
268
- - lib/appium_lib_core/common/base/command.rb
269
260
  - lib/appium_lib_core/common/base/driver.rb
261
+ - lib/appium_lib_core/common/base/has_location.rb
262
+ - lib/appium_lib_core/common/base/has_network_connection.rb
270
263
  - lib/appium_lib_core/common/base/http_default.rb
271
264
  - lib/appium_lib_core/common/base/platform.rb
272
265
  - lib/appium_lib_core/common/base/remote_status.rb
@@ -274,9 +267,6 @@ files:
274
267
  - lib/appium_lib_core/common/base/screenshot.rb
275
268
  - lib/appium_lib_core/common/base/search_context.rb
276
269
  - lib/appium_lib_core/common/command.rb
277
- - lib/appium_lib_core/common/command/common.rb
278
- - lib/appium_lib_core/common/command/mjsonwp.rb
279
- - lib/appium_lib_core/common/command/w3c.rb
280
270
  - lib/appium_lib_core/common/device/app_management.rb
281
271
  - lib/appium_lib_core/common/device/app_state.rb
282
272
  - lib/appium_lib_core/common/device/battery_status.rb
@@ -305,6 +295,7 @@ files:
305
295
  - lib/appium_lib_core/common/ws/websocket.rb
306
296
  - lib/appium_lib_core/device.rb
307
297
  - lib/appium_lib_core/driver.rb
298
+ - lib/appium_lib_core/element.rb
308
299
  - lib/appium_lib_core/ios.rb
309
300
  - lib/appium_lib_core/ios/device.rb
310
301
  - lib/appium_lib_core/ios/device/clipboard.rb
@@ -321,7 +312,6 @@ files:
321
312
  - lib/appium_lib_core/mac2/bridge.rb
322
313
  - lib/appium_lib_core/mac2/device.rb
323
314
  - lib/appium_lib_core/mac2/device/screen.rb
324
- - lib/appium_lib_core/patch.rb
325
315
  - lib/appium_lib_core/version.rb
326
316
  - lib/appium_lib_core/windows.rb
327
317
  - lib/appium_lib_core/windows/bridge.rb
@@ -341,12 +331,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
341
331
  requirements:
342
332
  - - ">="
343
333
  - !ruby/object:Gem::Version
344
- version: '2.4'
334
+ version: '2.5'
345
335
  required_rubygems_version: !ruby/object:Gem::Requirement
346
336
  requirements:
347
- - - ">="
337
+ - - ">"
348
338
  - !ruby/object:Gem::Version
349
- version: '0'
339
+ version: 1.3.1
350
340
  requirements: []
351
341
  rubygems_version: 3.1.2
352
342
  signing_key:
@@ -1,85 +0,0 @@
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
- module Appium
16
- module Core
17
- class Base
18
- class Bridge
19
- class MJSONWP < ::Selenium::WebDriver::Remote::OSS::Bridge
20
- include Device::DeviceLock
21
- include Device::Keyboard
22
- include Device::ImeActions
23
- include Device::Setting
24
- include Device::Context
25
- include Device::Value
26
- include Device::FileManagement
27
- include Device::KeyEvent
28
- include Device::ImageComparison
29
- include Device::AppManagement
30
- include Device::AppState
31
- include Device::ScreenRecord::Command
32
- include Device::Device
33
- include Device::TouchActions
34
- include Device::ExecuteDriver
35
-
36
- def commands(command)
37
- ::Appium::Core::Commands::MJSONWP::COMMANDS[command]
38
- end
39
-
40
- # Returns all available sessions on the Appium server instance
41
- def sessions
42
- execute :get_all_sessions
43
- end
44
-
45
- def status
46
- execute :status
47
- end
48
-
49
- # For Appium
50
- def log_event(vendor, event)
51
- execute :post_log_event, {}, { vendor: vendor, event: event }
52
- end
53
-
54
- # For Appium
55
- def log_events(type = nil)
56
- args = {}
57
- args['type'] = type unless type.nil?
58
-
59
- execute :get_log_events, {}, args
60
- end
61
-
62
- def take_element_screenshot(element)
63
- execute :take_element_screenshot, id: element.ref
64
- end
65
-
66
- def take_viewport_screenshot
67
- # TODO: this hasn't been supported by Espresso driver
68
- execute_script('mobile: viewportScreenshot')
69
- end
70
-
71
- def send_actions(_data)
72
- raise Error::UnsupportedOperationError, '#send_actions has not been supported in MJSONWP'
73
- end
74
-
75
- # For Appium
76
- # @param [Hash] id The id which can get as a response from server
77
- # @return [::Selenium::WebDriver::Element]
78
- def convert_to_element(id)
79
- ::Selenium::WebDriver::Element.new self, element_id_from(id)
80
- end
81
- end # class MJSONWP
82
- end # class Bridge
83
- end # class Base
84
- end # module Core
85
- end # module Appium
@@ -1,257 +0,0 @@
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
- module Appium
16
- module Core
17
- class Base
18
- class Bridge
19
- class W3C < ::Selenium::WebDriver::Remote::W3C::Bridge
20
- include Device::DeviceLock
21
- include Device::Keyboard
22
- include Device::ImeActions
23
- include Device::Setting
24
- include Device::Context
25
- include Device::Value
26
- include Device::FileManagement
27
- include Device::KeyEvent
28
- include Device::ImageComparison
29
- include Device::AppManagement
30
- include Device::AppState
31
- include Device::ScreenRecord::Command
32
- include Device::Device
33
- include Device::TouchActions
34
- include Device::ExecuteDriver
35
- include Device::Orientation
36
-
37
- def commands(command)
38
- ::Appium::Core::Commands::W3C::COMMANDS[command]
39
- end
40
-
41
- # Returns all available sessions on the Appium server instance
42
- def sessions
43
- execute :get_all_sessions
44
- end
45
-
46
- def status
47
- execute :status
48
- end
49
-
50
- # Perform touch actions for W3C module.
51
- # Generate +touch+ pointer action here and users can use this via +driver.action+
52
- # - https://seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/W3CActionBuilder.html
53
- # - https://seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/PointerActions.html
54
- # - https://seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/KeyActions.html
55
- #
56
- # 'mouse' action is by default in the Ruby client. Appium server force the +mouse+ action to +touch+ once in
57
- # the server side. So we don't consider the case.
58
- #
59
- # @example
60
- #
61
- # element = @driver.find_element(:id, "some id")
62
- # @driver.action.click(element).perform # The 'click' is a part of 'PointerActions'
63
- #
64
- def action(async = false)
65
- # Used for default duration of each touch actions
66
- # Override from 250 milliseconds to 50 milliseconds
67
- action_builder = super
68
- action_builder.default_move_duration = 0.05
69
- action_builder
70
- end
71
-
72
- # Port from MJSONWP
73
- def get_timeouts
74
- execute :get_timeouts
75
- end
76
-
77
- # Port from MJSONWP
78
- def session_capabilities
79
- ::Selenium::WebDriver::Remote::W3C::Capabilities.json_create execute(:get_capabilities)
80
- end
81
-
82
- # Port from MJSONWP
83
- def send_keys_to_active_element(key)
84
- text = ::Selenium::WebDriver::Keys.encode(key).join('')
85
- execute :send_keys_to_active_element, {}, { value: text.split(//) }
86
- end
87
-
88
- # For Appium
89
- # override
90
- def page_source
91
- # For W3C
92
- # execute_script('var source = document.documentElement.outerHTML;' \
93
- # 'if (!source) { source = new XMLSerializer().serializeToString(document); }' \
94
- # 'return source;')
95
- execute :get_page_source
96
- end
97
-
98
- # For Appium
99
- # override
100
- def element_displayed?(element)
101
- # For W3C
102
- # https://github.com/SeleniumHQ/selenium/commit/b618499adcc3a9f667590652c5757c0caa703289
103
- # execute_atom :isDisplayed, element
104
- execute :is_element_displayed, id: element.ref
105
- end
106
-
107
- # For Appium
108
- # override
109
- def element_attribute(element, name)
110
- # For W3C in Selenium Client
111
- # execute_atom :getAttribute, element, name
112
- execute :get_element_attribute, id: element.ref, name: name
113
- end
114
-
115
- # For Appium
116
- # override
117
- def find_element_by(how, what, parent = nil)
118
- how, what = convert_locators(how, what)
119
-
120
- id = if parent
121
- execute :find_child_element, { id: parent }, { using: how, value: what }
122
- else
123
- execute :find_element, {}, { using: how, value: what }
124
- end
125
- ::Selenium::WebDriver::Element.new self, element_id_from(id)
126
- end
127
-
128
- # For Appium
129
- # override
130
- def find_elements_by(how, what, parent = nil)
131
- how, what = convert_locators(how, what)
132
-
133
- ids = if parent
134
- execute :find_child_elements, { id: parent }, { using: how, value: what }
135
- else
136
- execute :find_elements, {}, { using: how, value: what }
137
- end
138
-
139
- ids.map { |id| ::Selenium::WebDriver::Element.new self, element_id_from(id) }
140
- end
141
-
142
- # For Appium
143
- # @param [Hash] id The id which can get as a response from server
144
- # @return [::Selenium::WebDriver::Element]
145
- def convert_to_element(id)
146
- ::Selenium::WebDriver::Element.new self, element_id_from(id)
147
- end
148
-
149
- # For Appium
150
- # override
151
- # called in 'extend DriverExtensions::HasNetworkConnection'
152
- def network_connection
153
- execute :get_network_connection
154
- end
155
-
156
- # For Appium
157
- # override
158
- # called in 'extend DriverExtensions::HasNetworkConnection'
159
- def network_connection=(type)
160
- execute :set_network_connection, {}, { parameters: { type: type } }
161
- end
162
-
163
- # For Appium
164
- # No implementation for W3C webdriver module
165
- # called in 'extend DriverExtensions::HasLocation'
166
- def location
167
- obj = execute(:get_location) || {}
168
- ::Selenium::WebDriver::Location.new obj['latitude'], obj['longitude'], obj['altitude']
169
- end
170
-
171
- # For Appium
172
- # No implementation for W3C webdriver module
173
- # called in +extend DriverExtensions::HasLocation+
174
- # It has below code as well. We should consider the same context in Selenium 4 as backward compatibility.
175
- #
176
- # def location=(loc)
177
- # # note: Location = Struct.new(:latitude, :longitude, :altitude)
178
- # raise TypeError, "expected #{Location}, got #{loc.inspect}:#{loc.class}" unless loc.is_a?(Location)
179
- #
180
- # @bridge.set_location loc.latitude, loc.longitude, loc.altitude
181
- # end
182
- #
183
- def set_location(lat, lon, alt = 0.0)
184
- loc = { latitude: lat, longitude: lon, altitude: alt }
185
- execute :set_location, {}, { location: loc }
186
- end
187
-
188
- #
189
- # logs
190
- #
191
- # For Appium
192
- # No implementation for W3C webdriver module
193
- def available_log_types
194
- types = execute :get_available_log_types
195
- Array(types).map(&:to_sym)
196
- end
197
-
198
- # For Appium
199
- # No implementation for W3C webdriver module
200
- def log(type)
201
- data = execute :get_log, {}, { type: type.to_s }
202
-
203
- Array(data).map do |l|
204
- begin
205
- ::Selenium::WebDriver::LogEntry.new l.fetch('level', 'UNKNOWN'), l.fetch('timestamp'), l.fetch('message')
206
- rescue KeyError
207
- next
208
- end
209
- end
210
- end
211
-
212
- # For Appium
213
- def log_event(vendor, event)
214
- execute :post_log_event, {}, { vendor: vendor, event: event }
215
- end
216
-
217
- # For Appium
218
- def log_events(type = nil)
219
- args = {}
220
- args['type'] = type unless type.nil?
221
-
222
- execute :get_log_events, {}, args
223
- end
224
-
225
- def take_viewport_screenshot
226
- execute_script('mobile: viewportScreenshot')
227
- end
228
-
229
- def take_element_screenshot(element)
230
- execute :take_element_screenshot, id: element.ref
231
- end
232
-
233
- private
234
-
235
- # Don't convert locators for Appium Client
236
- # TODO: Only for Appium. Ideally, we'd like to keep the selenium-webdriver
237
- def convert_locators(how, what)
238
- # case how
239
- # when 'class name'
240
- # how = 'css selector'
241
- # what = ".#{escape_css(what)}"
242
- # when 'id'
243
- # how = 'css selector'
244
- # what = "##{escape_css(what)}"
245
- # when 'name'
246
- # how = 'css selector'
247
- # what = "*[name='#{escape_css(what)}']"
248
- # when 'tag name'
249
- # how = 'css selector'
250
- # end
251
- [how, what]
252
- end
253
- end # class W3C
254
- end # class Bridge
255
- end # class Base
256
- end # module Core
257
- end # module Appium