appium_lib_core 5.0.0.beta1 → 5.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -6
  3. data/README.md +2 -1
  4. data/Rakefile +4 -0
  5. data/appium_lib_core.gemspec +3 -3
  6. data/ci-jobs/functional_test.yml +1 -1
  7. data/docs/mobile_command.md +3 -2
  8. data/lib/appium_lib_core/android/device/auth_finger_print.rb +2 -1
  9. data/lib/appium_lib_core/common/base/bridge.rb +303 -7
  10. data/lib/appium_lib_core/common/base/device_ime.rb +49 -0
  11. data/lib/appium_lib_core/common/base/driver.rb +101 -105
  12. data/lib/appium_lib_core/common/base/driver_settings.rb +51 -0
  13. data/lib/appium_lib_core/common/base/has_location.rb +11 -4
  14. data/lib/appium_lib_core/common/base/has_network_connection.rb +1 -1
  15. data/lib/appium_lib_core/common/base/rotable.rb +1 -1
  16. data/lib/appium_lib_core/common/base/screenshot.rb +4 -3
  17. data/lib/appium_lib_core/common/base/search_context.rb +9 -4
  18. data/lib/appium_lib_core/common/base.rb +0 -2
  19. data/lib/appium_lib_core/common/command.rb +259 -3
  20. data/lib/appium_lib_core/common/device/keyevent.rb +4 -4
  21. data/lib/appium_lib_core/common/device/value.rb +4 -4
  22. data/lib/appium_lib_core/common/error.rb +4 -1
  23. data/lib/appium_lib_core/common/log.rb +4 -1
  24. data/lib/appium_lib_core/common/touch_action/touch_actions.rb +4 -1
  25. data/lib/appium_lib_core/device.rb +1 -1
  26. data/lib/appium_lib_core/driver.rb +3 -4
  27. data/lib/appium_lib_core/{patch.rb → element.rb} +9 -14
  28. data/lib/appium_lib_core/ios/uiautomation/patch.rb +1 -1
  29. data/lib/appium_lib_core/version.rb +2 -2
  30. data/lib/appium_lib_core.rb +2 -5
  31. data/release_notes.md +23 -0
  32. data/script/commands.rb +1 -12
  33. metadata +15 -17
  34. data/lib/appium_lib_core/common/base/bridge/w3c.rb +0 -348
  35. data/lib/appium_lib_core/common/base/command.rb +0 -145
  36. data/lib/appium_lib_core/common/command/common.rb +0 -110
  37. data/lib/appium_lib_core/common/command/w3c.rb +0 -56
@@ -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.
@@ -63,20 +59,20 @@ module Appium
63
59
  #
64
60
  # @example
65
61
  #
66
- # @driver.immediate_value 'hello'
62
+ # element.immediate_value 'hello'
67
63
  #
68
64
  def immediate_value(*value)
69
- @bridge.set_immediate_value(self, *value)
65
+ @bridge.set_immediate_value @id, *value
70
66
  end
71
67
 
72
68
  # Replace the value to element directly
73
69
  #
74
70
  # @example
75
71
  #
76
- # @driver.replace_value 'hello'
72
+ # element.replace_value 'hello'
77
73
  #
78
74
  def replace_value(*value)
79
- @bridge.replace_value(self, *value)
75
+ @bridge.replace_value @id, *value
80
76
  end
81
77
 
82
78
  # For use with location_rel.
@@ -112,7 +108,7 @@ module Appium
112
108
  # element.screenshot #=> "iVBORw0KGgoAAAANSUhEUgAABDgAAAB+CAIAAABOPDa6AAAAAX"
113
109
  #
114
110
  def screenshot
115
- bridge.take_element_screenshot(self)
111
+ bridge.element_screenshot @id
116
112
  end
117
113
 
118
114
  # Return an element screenshot in the given format
@@ -127,9 +123,9 @@ module Appium
127
123
  def screenshot_as(format)
128
124
  case format
129
125
  when :base64
130
- bridge.take_element_screenshot(self)
126
+ bridge.element_screenshot @id
131
127
  when :png
132
- bridge.take_element_screenshot(self).unpack('m')[0]
128
+ bridge.element_screenshot(@id).unpack('m')[0]
133
129
  else
134
130
  raise Core::Error::UnsupportedOperationError, "unsupported format: #{format.inspect}"
135
131
  end
@@ -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 = '5.0.0.beta1' unless defined? ::Appium::Core::VERSION
18
- DATE = '2021-03-21' unless defined? ::Appium::Core::DATE
17
+ VERSION = '5.0.0.rc1' unless defined? ::Appium::Core::VERSION
18
+ DATE = '2021-09-09' unless defined? ::Appium::Core::DATE
19
19
  end
20
20
  end
@@ -17,11 +17,8 @@ require 'selenium-webdriver'
17
17
  require_relative 'appium_lib_core/version'
18
18
  require_relative 'appium_lib_core/common'
19
19
  require_relative 'appium_lib_core/driver'
20
-
21
20
  require_relative 'appium_lib_core/device'
22
-
23
- # Call patch after requiring other files
24
- require_relative 'appium_lib_core/patch'
21
+ require_relative 'appium_lib_core/element'
25
22
 
26
23
  module Appium
27
24
  # convert all keys (including nested) to symbols
@@ -30,7 +27,7 @@ module Appium
30
27
  # https://github.com/rails/docrails/blob/a3b1105ada3da64acfa3843b164b14b734456a50/activesupport/lib/active_support/core_ext/hash/keys.rb#L84
31
28
  # @param [Hash] hash Hash value to make symbolise
32
29
  def self.symbolize_keys(hash)
33
- raise ArgumentError, 'symbolize_keys requires a hash' unless hash.is_a? Hash
30
+ raise ::Appium::Core::Error::ArgumentError, 'symbolize_keys requires a hash' unless hash.is_a? Hash
34
31
 
35
32
  hash.each_with_object({}) do |pair, acc|
36
33
  key = begin
data/release_notes.md CHANGED
@@ -1,3 +1,26 @@
1
+ #### v4.7.0 2021-07-17
2
+
3
+ - [0059974](https://github.com/appium/ruby_lib_core/commit/0059974b0b1d79a822db84d8b0169e8393e00ef9) Release 4.7.0
4
+ - [0f93a52](https://github.com/appium/ruby_lib_core/commit/0f93a52bbdc44bf916c9b974fe9fd09d48e5ff39) test: add more example and test (#328)
5
+ - [9e37b3b](https://github.com/appium/ruby_lib_core/commit/9e37b3bc15f72f7c0117a49945a3fe482598f374) feat: add satellites for Android emulators (#327)
6
+ - [3063a73](https://github.com/appium/ruby_lib_core/commit/3063a73fa291dc378daa53b7df2e4b0b8a6f03d2) ci: calls quit_driver to ensure close the previous session
7
+ - [43fb9e7](https://github.com/appium/ruby_lib_core/commit/43fb9e77f5492a92f4f8c5a5bda71be9c3a9e2c8) chore: tweak naming in an internal variable
8
+
9
+
10
+ #### v4.6.0 2021-06-03
11
+
12
+ - [0dacfab](https://github.com/appium/ruby_lib_core/commit/0dacfab1256e1447e1f7a5974dfcf48ee0a72b9d) Release 4.6.0
13
+ - [b9f015d](https://github.com/appium/ruby_lib_core/commit/b9f015d7dea14964a0733f2385ebcff68da1e18e) feat: allow to add commands dynamically (#325)
14
+ - [3de96ee](https://github.com/appium/ruby_lib_core/commit/3de96eea133ccbcbc5c4d77adc7d67c065a5a38c) chore(deps-dev): update webmock requirement from ~> 3.12.1 to ~> 3.13.0 (#324)
15
+ - [f1a9e79](https://github.com/appium/ruby_lib_core/commit/f1a9e79f3bd4d134e125fc2ed9adcf3d085afc9a) docs: address func test code as working example
16
+ - [eb85b1b](https://github.com/appium/ruby_lib_core/commit/eb85b1b26623436cb0aae95a00fef7bc2d795520) remove ; in a test
17
+ - [1632637](https://github.com/appium/ruby_lib_core/commit/1632637fd872c0b80dfb97b8514ada6a7164eebf) chore(deps-dev): update rubocop requirement from = 1.11.0 to = 1.12.0 (#321)
18
+ - [b9e47aa](https://github.com/appium/ruby_lib_core/commit/b9e47aa9b02f060ffa91e8410ab97dc87d3640a4) docs: add docstring
19
+ - [954a2fe](https://github.com/appium/ruby_lib_core/commit/954a2feebb768a55b496a2614d9e4dd8b702fc1e) chore(deps-dev): update rubocop requirement from = 1.8.1 to = 1.11.0 (#316)
20
+ - [a5b9651](https://github.com/appium/ruby_lib_core/commit/a5b9651aa349c10bd9759fedac6f09e27012a5e5) chore(deps-dev): update webmock requirement from ~> 3.11.0 to ~> 3.12.1 (#319)
21
+ - [485c096](https://github.com/appium/ruby_lib_core/commit/485c096273178aa5e21f28d93545fd127cbb8735) test: add assertion
22
+
23
+
1
24
  #### v4.5.0 2021-03-14
2
25
 
3
26
  - [656230e](https://github.com/appium/ruby_lib_core/commit/656230e688ed86414c06efaa73bce7359933cc91) Release 4.5.0
data/script/commands.rb CHANGED
@@ -23,17 +23,13 @@ module Script
23
23
 
24
24
  # Set commands implemented in this core library.
25
25
  #
26
- # - implemented_w3c_commands: All commands include ::Selenium::WebDriver::Remote::W3C::Bridge::COMMANDS
26
+ # - implemented_w3c_commands: All commands include ::Selenium::WebDriver::Remote::Bridge::COMMANDS
27
27
  # - implemented_core_commands: All commands except for selenium-webdriver's commands
28
- # - webdriver_w3c_commands: ::Selenium::WebDriver::Remote::W3C::Bridge::COMMANDS
29
28
  #
30
29
  def initialize
31
30
  @spec_commands = nil
32
31
 
33
- @implemented_w3c_commands = convert_driver_commands Appium::Core::Commands::W3C::COMMANDS
34
32
  @implemented_core_commands = convert_driver_commands Appium::Core::Commands::COMMANDS
35
-
36
- @webdriver_w3c_commands = convert_driver_commands Appium::Core::Base::Commands::W3C
37
33
  end
38
34
 
39
35
  # Get the bellow url's file.
@@ -95,13 +91,6 @@ module Script
95
91
  result
96
92
  end
97
93
 
98
- def diff_webdriver_w3c
99
- result = compare_commands(@spec_commands, @webdriver_w3c_commands)
100
- white_list.each { |v| result.delete v }
101
- mjsonwp_spec.each { |v| result.delete v }
102
- result
103
- end
104
-
105
94
  def compare_commands(command1, with_command2)
106
95
  return {} if command1.nil?
107
96
  return command1 if with_command2.nil?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appium_lib_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.beta1
4
+ version: 5.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuaki MATSUO
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-21 00:00:00.000000000 Z
11
+ date: 2021-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selenium-webdriver
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.0.beta2
19
+ version: 4.0.0.rc1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 4.0.0.beta2
26
+ version: 4.0.0.rc1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: faye-websocket
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -114,28 +114,28 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 3.12.1
117
+ version: 3.14.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 3.12.1
124
+ version: 3.14.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rubocop
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 1.11.0
131
+ version: 1.12.1
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 1.11.0
138
+ version: 1.12.1
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: appium_thor
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -256,10 +256,10 @@ files:
256
256
  - lib/appium_lib_core/common.rb
257
257
  - lib/appium_lib_core/common/base.rb
258
258
  - lib/appium_lib_core/common/base/bridge.rb
259
- - lib/appium_lib_core/common/base/bridge/w3c.rb
260
259
  - lib/appium_lib_core/common/base/capabilities.rb
261
- - lib/appium_lib_core/common/base/command.rb
260
+ - lib/appium_lib_core/common/base/device_ime.rb
262
261
  - lib/appium_lib_core/common/base/driver.rb
262
+ - lib/appium_lib_core/common/base/driver_settings.rb
263
263
  - lib/appium_lib_core/common/base/has_location.rb
264
264
  - lib/appium_lib_core/common/base/has_network_connection.rb
265
265
  - lib/appium_lib_core/common/base/http_default.rb
@@ -269,8 +269,6 @@ files:
269
269
  - lib/appium_lib_core/common/base/screenshot.rb
270
270
  - lib/appium_lib_core/common/base/search_context.rb
271
271
  - lib/appium_lib_core/common/command.rb
272
- - lib/appium_lib_core/common/command/common.rb
273
- - lib/appium_lib_core/common/command/w3c.rb
274
272
  - lib/appium_lib_core/common/device/app_management.rb
275
273
  - lib/appium_lib_core/common/device/app_state.rb
276
274
  - lib/appium_lib_core/common/device/battery_status.rb
@@ -299,6 +297,7 @@ files:
299
297
  - lib/appium_lib_core/common/ws/websocket.rb
300
298
  - lib/appium_lib_core/device.rb
301
299
  - lib/appium_lib_core/driver.rb
300
+ - lib/appium_lib_core/element.rb
302
301
  - lib/appium_lib_core/ios.rb
303
302
  - lib/appium_lib_core/ios/device.rb
304
303
  - lib/appium_lib_core/ios/device/clipboard.rb
@@ -315,7 +314,6 @@ files:
315
314
  - lib/appium_lib_core/mac2/bridge.rb
316
315
  - lib/appium_lib_core/mac2/device.rb
317
316
  - lib/appium_lib_core/mac2/device/screen.rb
318
- - lib/appium_lib_core/patch.rb
319
317
  - lib/appium_lib_core/version.rb
320
318
  - lib/appium_lib_core/windows.rb
321
319
  - lib/appium_lib_core/windows/bridge.rb
@@ -327,7 +325,7 @@ homepage: https://github.com/appium/ruby_lib_core/
327
325
  licenses:
328
326
  - Apache-2.0
329
327
  metadata: {}
330
- post_install_message:
328
+ post_install_message:
331
329
  rdoc_options: []
332
330
  require_paths:
333
331
  - lib
@@ -342,8 +340,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
342
340
  - !ruby/object:Gem::Version
343
341
  version: 1.3.1
344
342
  requirements: []
345
- rubygems_version: 3.1.2
346
- signing_key:
343
+ rubygems_version: 3.2.15
344
+ signing_key:
347
345
  specification_version: 4
348
346
  summary: Minimal Ruby library for Appium.
349
347
  test_files: []
@@ -1,348 +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::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
- # TODO: For compatibility. Should remove.
38
- def dialect
39
- :w3c
40
- end
41
-
42
- # TODO: fixme
43
- def browser
44
- @browser ||= begin
45
- name = @capabilities.browser_name
46
- name ? name.tr(' ', '_').downcase.to_sym : 'unknown'
47
- rescue KeyError
48
- 'unknown'
49
- end
50
- end
51
-
52
- # Prefix for extra capability defined by W3C
53
- APPIUM_PREFIX = 'appium:'
54
-
55
- # Override
56
- # Creates session handling both OSS and W3C dialects.
57
- #
58
- # @param [::Selenium::WebDriver::Remote::Capabilities, Hash] desired_capabilities A capability
59
- # @return [::Selenium::WebDriver::Remote::Capabilities]
60
- #
61
- # @example
62
- #
63
- # opts = {
64
- # caps: {
65
- # platformName: :ios,
66
- # automationName: 'XCUITest',
67
- # app: 'test/functional/app/UICatalog.app.zip',
68
- # platformVersion: '11.4',
69
- # deviceName: 'iPhone Simulator',
70
- # useNewWDA: true,
71
- # },
72
- # appium_lib: {
73
- # wait: 30
74
- # }
75
- # }
76
- # core = ::Appium::Core.for(caps)
77
- # driver = core.start_driver #=> driver.dialect == :w3c if the Appium server support W3C.
78
- #
79
- def create_session(desired_capabilities)
80
- caps = add_appium_prefix(desired_capabilities)
81
- response = execute(:new_session, {}, { capabilities: { firstMatch: [caps] } })
82
-
83
- @session_id = response['sessionId']
84
- capabilities = response['capabilities']
85
-
86
- raise ::Selenium::WebDriver::Error::WebDriverError, 'no sessionId in returned payload' unless @session_id
87
-
88
- @capabilities = json_create(capabilities)
89
- end
90
-
91
- # Append +appium:+ prefix for Appium following W3C spec
92
- # https://www.w3.org/TR/webdriver/#dfn-validate-capabilities
93
- #
94
- # @param [::Selenium::WebDriver::Remote::Capabilities, Hash] capabilities A capability
95
- # @return [::Selenium::WebDriver::Remote::Capabilities]
96
- def add_appium_prefix(capabilities)
97
- w3c_capabilities = ::Selenium::WebDriver::Remote::Capabilities.new
98
-
99
- capabilities = capabilities.__send__(:capabilities) unless capabilities.is_a?(Hash)
100
-
101
- capabilities.each do |name, value|
102
- next if value.nil?
103
- next if value.is_a?(String) && value.empty?
104
-
105
- capability_name = name.to_s
106
- w3c_name = extension_prefix?(capability_name) ? name : "#{APPIUM_PREFIX}#{capability_name}"
107
-
108
- w3c_capabilities[w3c_name] = value
109
- end
110
-
111
- w3c_capabilities
112
- end
113
-
114
- private
115
-
116
- def camel_case(str)
117
- str.gsub(/_([a-z])/) { Regexp.last_match(1).upcase }
118
- end
119
-
120
- def extension_prefix?(capability_name)
121
- snake_cased_capability_names = ::Selenium::WebDriver::Remote::Capabilities::KNOWN.map(&:to_s)
122
- camel_cased_capability_names = snake_cased_capability_names.map { |v| camel_case(v) }
123
-
124
- # Check 'EXTENSION_CAPABILITY_PATTERN'
125
- snake_cased_capability_names.include?(capability_name) ||
126
- camel_cased_capability_names.include?(capability_name) ||
127
- capability_name.match(':')
128
- end
129
-
130
- def json_create(value)
131
- @dialect = :w3c
132
- ::Selenium::WebDriver::Remote::Capabilities.json_create(value)
133
- end
134
-
135
- public
136
-
137
- def commands(command)
138
- ::Appium::Core::Commands::W3C::COMMANDS[command]
139
- end
140
-
141
- # Returns all available sessions on the Appium server instance
142
- def sessions
143
- execute :get_all_sessions
144
- end
145
-
146
- def status
147
- execute :status
148
- end
149
-
150
- # Perform touch actions for W3C module.
151
- # Generate +touch+ pointer action here and users can use this via +driver.action+
152
- # - https://seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/W3CActionBuilder.html
153
- # - https://seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/PointerActions.html
154
- # - https://seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/KeyActions.html
155
- #
156
- # 'mouse' action is by default in the Ruby client. Appium server force the +mouse+ action to +touch+ once in
157
- # the server side. So we don't consider the case.
158
- #
159
- # @example
160
- #
161
- # element = @driver.find_element(:id, "some id")
162
- # @driver.action.click(element).perform # The 'click' is a part of 'PointerActions'
163
- #
164
- def action(async = false)
165
- # Used for default duration of each touch actions
166
- # Override from 250 milliseconds to 50 milliseconds
167
- action_builder = super
168
- action_builder.default_move_duration = 0.05
169
- action_builder
170
- end
171
-
172
- # Port from MJSONWP
173
- def get_timeouts
174
- execute :get_timeouts
175
- end
176
-
177
- # Port from MJSONWP
178
- def session_capabilities
179
- ::Selenium::WebDriver::Remote::Capabilities.json_create execute(:get_capabilities)
180
- end
181
-
182
- # Port from MJSONWP
183
- def send_keys_to_active_element(key)
184
- text = ::Selenium::WebDriver::Keys.encode(key).join('')
185
- execute :send_keys_to_active_element, {}, { value: text.split(//) }
186
- end
187
-
188
- # For Appium
189
- # override
190
- def page_source
191
- # For W3C
192
- # execute_script('var source = document.documentElement.outerHTML;' \
193
- # 'if (!source) { source = new XMLSerializer().serializeToString(document); }' \
194
- # 'return source;')
195
- execute :get_page_source
196
- end
197
-
198
- # For Appium
199
- # override
200
- def element_displayed?(element)
201
- # For W3C
202
- # https://github.com/SeleniumHQ/selenium/commit/b618499adcc3a9f667590652c5757c0caa703289
203
- # execute_atom :isDisplayed, element
204
- execute :is_element_displayed, id: element.ref
205
- end
206
-
207
- # For Appium
208
- # override
209
- def element_attribute(element, name)
210
- # For W3C in Selenium Client
211
- # execute_atom :getAttribute, element, name
212
- execute :get_element_attribute, id: element.ref, name: name
213
- end
214
-
215
- # For Appium
216
- # override
217
- def find_element_by(how, what, parent = nil)
218
- how, what = convert_locators(how, what)
219
-
220
- id = if parent
221
- execute :find_child_element, { id: parent }, { using: how, value: what }
222
- else
223
- execute :find_element, {}, { using: how, value: what }
224
- end
225
- ::Selenium::WebDriver::Element.new self, element_id_from(id)
226
- end
227
-
228
- # For Appium
229
- # override
230
- def find_elements_by(how, what, parent = nil)
231
- how, what = convert_locators(how, what)
232
-
233
- ids = if parent
234
- execute :find_child_elements, { id: parent }, { using: how, value: what }
235
- else
236
- execute :find_elements, {}, { using: how, value: what }
237
- end
238
-
239
- ids.map { |id| ::Selenium::WebDriver::Element.new self, element_id_from(id) }
240
- end
241
-
242
- # For Appium
243
- # @param [Hash] id The id which can get as a response from server
244
- # @return [::Selenium::WebDriver::Element]
245
- def convert_to_element(id)
246
- ::Selenium::WebDriver::Element.new self, element_id_from(id)
247
- end
248
-
249
- # For Appium
250
- # override
251
- # called in 'extend DriverExtensions::HasNetworkConnection'
252
- def network_connection
253
- execute :get_network_connection
254
- end
255
-
256
- # For Appium
257
- # override
258
- # called in 'extend DriverExtensions::HasNetworkConnection'
259
- def network_connection=(type)
260
- execute :set_network_connection, {}, { parameters: { type: type } }
261
- end
262
-
263
- # For Appium
264
- # No implementation for W3C webdriver module
265
- # called in 'extend DriverExtensions::HasLocation'
266
- def location
267
- obj = execute(:get_location) || {}
268
- ::Selenium::WebDriver::Location.new obj['latitude'], obj['longitude'], obj['altitude']
269
- end
270
-
271
- # For Appium
272
- # No implementation for W3C webdriver module
273
- def set_location(lat, lon, alt = 0.0, speed: nil)
274
- loc = { latitude: lat, longitude: lon, altitude: alt }
275
- loc[:speed] = speed unless speed.nil?
276
- execute :set_location, {}, { location: loc }
277
- end
278
-
279
- #
280
- # logs
281
- #
282
- # For Appium
283
- # No implementation for W3C webdriver module
284
- def available_log_types
285
- types = execute :get_available_log_types
286
- Array(types).map(&:to_sym)
287
- end
288
-
289
- # For Appium
290
- # No implementation for W3C webdriver module
291
- def log(type)
292
- data = execute :get_log, {}, { type: type.to_s }
293
-
294
- Array(data).map do |l|
295
- begin
296
- ::Selenium::WebDriver::LogEntry.new l.fetch('level', 'UNKNOWN'), l.fetch('timestamp'), l.fetch('message')
297
- rescue KeyError
298
- next
299
- end
300
- end
301
- end
302
-
303
- # For Appium
304
- def log_event(vendor, event)
305
- execute :post_log_event, {}, { vendor: vendor, event: event }
306
- end
307
-
308
- # For Appium
309
- def log_events(type = nil)
310
- args = {}
311
- args['type'] = type unless type.nil?
312
-
313
- execute :get_log_events, {}, args
314
- end
315
-
316
- def take_viewport_screenshot
317
- execute_script('mobile: viewportScreenshot')
318
- end
319
-
320
- def take_element_screenshot(element)
321
- execute :take_element_screenshot, id: element.ref
322
- end
323
-
324
- private
325
-
326
- # Don't convert locators for Appium Client
327
- # TODO: Only for Appium. Ideally, we'd like to keep the selenium-webdriver
328
- def convert_locators(how, what)
329
- # case how
330
- # when 'class name'
331
- # how = 'css selector'
332
- # what = ".#{escape_css(what)}"
333
- # when 'id'
334
- # how = 'css selector'
335
- # what = "##{escape_css(what)}"
336
- # when 'name'
337
- # how = 'css selector'
338
- # what = "*[name='#{escape_css(what)}']"
339
- # when 'tag name'
340
- # how = 'css selector'
341
- # end
342
- [how, what]
343
- end
344
- end # class W3C
345
- end # class Bridge
346
- end # class Base
347
- end # module Core
348
- end # module Appium