appium_lib_core 1.1.0 → 1.2.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
  SHA1:
3
- metadata.gz: fb8a3502ee734114622e3474545af77b125ec43d
4
- data.tar.gz: fe71c68a3d9006e06381d5d04219bbbaa777d35b
3
+ metadata.gz: f293c0d7c354e724d630c6bf05615648826eae78
4
+ data.tar.gz: 1b46da98cf8d8865e81774035bd0a186f25dcf4a
5
5
  SHA512:
6
- metadata.gz: 29224ca9a8bde5e159eb7e9bb0d37c73a73ed595aeb21849a4da3b47bf2f09c50bd2f0906d419b824e32f57c15a43e9bb6ea4a1b0d17799b307987a00f0b816d
7
- data.tar.gz: 58fc2392b7963aff9b934d746196438889af995f2a902327ded1b79c9e4abf23088fea5ddca7eeb0628ab1a538b6b9b4931686defabe172f6ecf64fc97187e1c
6
+ metadata.gz: 58c4837373409a8f1d64551b737e75cfac7d552774dee51bf46fc64fd900c8e3eaa6f30137e201c73a6ef8f1bc2c8814d0b41068ddc7041518083941c360fa21
7
+ data.tar.gz: e76ae72453b6e21fd96dabb9c2525652be2319883dd326a56143ef687597670cc60efcd387b34345c00bb964d32420d1c5a12a7437237dc20d0bc98a73871f03
data/.rubocop.yml CHANGED
@@ -16,11 +16,13 @@ Metrics/PerceivedComplexity:
16
16
  Max: 8
17
17
  Style/Documentation:
18
18
  Enabled: false
19
- Style/AccessorMethodName:
20
- Enabled: false
21
19
  Style/CommentedKeyword:
22
20
  Enabled: false
23
21
  Style/PercentLiteralDelimiters:
24
22
  Enabled: false
23
+ Style/BracesAroundHashParameters:
24
+ Enabled: false
25
25
  Lint/NestedMethodDefinition:
26
26
  Enabled: false
27
+ Naming/AccessorMethodName:
28
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@ All notable changes to this project will be documented in this file.
3
3
 
4
4
  ## [Unreleased]
5
5
  ### Enhancements
6
+
7
+ ### Bug fixes
8
+
9
+ ### Deprecations
10
+
11
+ ## [1.2.0] - 2017-12-23
12
+ ### Enhancements
13
+ - Append `appium:` prefix for capabilities automatically due to W3C format.
14
+ - add take element screenshot for oss module [#33](https://github.com/appium/ruby_lib_core/pull/33)
15
+ - add w3c touch action tests and some supports for w3c [#35](https://github.com/appium/ruby_lib_core/pull/35)
16
+ - IME related
17
+ - Touch actions based on W3C spec
18
+
19
+ ### Bug fixes
20
+
21
+ ### Deprecations
22
+
23
+ ## [1.1.0] - 2017-12-16
24
+ ### Enhancements
6
25
  - Add guidelines in `.github`
7
26
  - session/:session_id/appium/device/keyevent [#21](https://github.com/appium/ruby_lib_core/issues/21)
8
27
 
@@ -22,12 +22,12 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_runtime_dependency 'selenium-webdriver', '~> 3.4', '>= 3.4.1'
25
+ spec.add_runtime_dependency 'selenium-webdriver', '~> 3.5'
26
26
  spec.add_runtime_dependency 'json', '>= 1.8'
27
27
 
28
28
  spec.add_development_dependency 'bundler', '~> 1.14'
29
29
  spec.add_development_dependency 'rake', '~> 10.0'
30
- spec.add_development_dependency 'yard', '~> 0.9'
30
+ spec.add_development_dependency 'yard', '~> 0.9.11'
31
31
  spec.add_development_dependency 'minitest', '~> 5.0'
32
32
  spec.add_development_dependency 'minitest-reporters', '~> 1.1'
33
33
  spec.add_development_dependency 'webmock', '~> 3.1.0'
@@ -1,6 +1,8 @@
1
1
  # The following files have selenium-webdriver related stuff.
2
2
  require_relative 'base/driver'
3
3
  require_relative 'base/bridge'
4
+ require_relative 'base/msjsonwp_bridge'
5
+ require_relative 'base/w3c_bridge'
4
6
  require_relative 'base/capabilities'
5
7
  require_relative 'base/http_default'
6
8
  require_relative 'base/search_context'
@@ -2,6 +2,16 @@ module Appium
2
2
  module Core
3
3
  class Base
4
4
  class Bridge < ::Selenium::WebDriver::Remote::Bridge
5
+ # Almost same as self.handshake in ::Selenium::WebDriver::Remote::Bridge
6
+ #
7
+ # Implements protocol handshake which:
8
+ #
9
+ # 1. Creates session with driver.
10
+ # 2. Sniffs response.
11
+ # 3. Based on the response, understands which dialect we should use.
12
+ #
13
+ # @return [CoreBridgeMJSONWP, CoreBridgeW3C]
14
+ #
5
15
  def self.handshake(**opts)
6
16
  desired_capabilities = opts.delete(:desired_capabilities)
7
17
 
@@ -25,36 +35,54 @@ module Appium
25
35
  end
26
36
  end
27
37
 
38
+ # Append `appium:` prefix for Appium following W3C spec
39
+ # https://www.w3.org/TR/webdriver/#dfn-validate-capabilities
40
+ #
41
+ # @param [::Selenium::WebDriver::Remote::W3C::Capabilities, Hash] capabilities A capability
42
+ # @return [::Selenium::WebDriver::Remote::W3C::Capabilities]
43
+ def add_appium_prefix(capabilities)
44
+ w3c_capabilities = ::Selenium::WebDriver::Remote::W3C::Capabilities.new
45
+
46
+ capabilities = capabilities.__send__(:capabilities) unless capabilities.is_a?(Hash)
47
+ capabilities.each do |name, value|
48
+ next if value.nil?
49
+ next if value.is_a?(String) && value.empty?
50
+
51
+ capability_name = name.to_s
52
+ w3c_name = appium_prefix?(capability_name, w3c_capabilities) ? name : "appium:#{capability_name}"
53
+
54
+ w3c_capabilities[w3c_name] = value
55
+ end
56
+
57
+ w3c_capabilities
58
+ end
59
+
28
60
  private
29
61
 
62
+ APPIUM_PREFIX = 'appium:'.freeze
63
+ def appium_prefix?(capability_name, w3c_capabilities)
64
+ snake_cased_capability_names = ::Selenium::WebDriver::Remote::W3C::Capabilities::KNOWN.map(&:to_s)
65
+ camel_cased_capability_names = snake_cased_capability_names.map(&w3c_capabilities.method(:camel_case))
66
+
67
+ snake_cased_capability_names.include?(capability_name) ||
68
+ camel_cased_capability_names.include?(capability_name) ||
69
+ capability_name.start_with?(APPIUM_PREFIX)
70
+ end
71
+
30
72
  # Use capabilities directory because Appium's capability is based on W3C one.
31
- # Called in bridge.create_session(desired_capabilities)
73
+ # Called in bridge.create_session(desired_capabilities) from Parent class
32
74
  def merged_capabilities(desired_capabilities)
75
+ new_caps = add_appium_prefix(desired_capabilities)
76
+ w3c_capabilities = ::Selenium::WebDriver::Remote::W3C::Capabilities.from_oss(new_caps)
77
+
33
78
  {
34
79
  desiredCapabilities: desired_capabilities,
35
80
  capabilities: {
36
- firstMatch: [desired_capabilities]
81
+ firstMatch: [w3c_capabilities]
37
82
  }
38
83
  }
39
84
  end
40
85
  end # class Bridge
41
-
42
- class CoreBridgeMJSONWP < ::Selenium::WebDriver::Remote::OSS::Bridge
43
- def commands(command)
44
- ::Appium::Core::Commands::COMMANDS_EXTEND_MJSONWP[command]
45
- end
46
- end # class CoreBridgeMJSONWP
47
-
48
- class CoreBridgeW3C < ::Selenium::WebDriver::Remote::W3C::Bridge
49
- def commands(command)
50
- case command
51
- when :status, :is_element_displayed
52
- ::Appium::Core::Commands::COMMANDS_EXTEND_MJSONWP[command]
53
- else
54
- ::Appium::Core::Commands::COMMANDS_EXTEND_W3C[command]
55
- end
56
- end
57
- end # class CoreBridgeW3C
58
86
  end # class Base
59
87
  end # module Core
60
88
  end # module Appium
@@ -20,10 +20,21 @@ module Appium
20
20
  extend ::Selenium::WebDriver::DriverExtensions::HasTouchScreen
21
21
  extend ::Selenium::WebDriver::DriverExtensions::HasLocation
22
22
  extend ::Selenium::WebDriver::DriverExtensions::HasNetworkConnection
23
+ elsif @bridge.dialect == :w3c
24
+ # TODO: Only for Appium. Ideally, we'd like to remove the below like selenium-webdriver
25
+ extend ::Selenium::WebDriver::DriverExtensions::HasTouchScreen
26
+ extend ::Selenium::WebDriver::DriverExtensions::HasLocation
27
+ extend ::Selenium::WebDriver::DriverExtensions::HasNetworkConnection
23
28
  end
24
29
  super(@bridge, listener: listener)
25
30
  end
26
31
 
32
+ # Get the dialect value
33
+ # @return [:oss|:w3c]
34
+ def dialect
35
+ @bridge.dialect
36
+ end
37
+
27
38
  # Get the device window's size.
28
39
  # @return [Selenium::WebDriver::Dimension]
29
40
  #
@@ -0,0 +1,11 @@
1
+ module Appium
2
+ module Core
3
+ class Base
4
+ class CoreBridgeMJSONWP < ::Selenium::WebDriver::Remote::OSS::Bridge
5
+ def commands(command)
6
+ ::Appium::Core::Commands::COMMANDS_EXTEND_MJSONWP[command]
7
+ end
8
+ end # class CoreBridgeMJSONWP
9
+ end # class Base
10
+ end # module Core
11
+ end # module Appium
@@ -0,0 +1,65 @@
1
+ module Appium
2
+ module Core
3
+ class Base
4
+ class CoreBridgeW3C < ::Selenium::WebDriver::Remote::W3C::Bridge
5
+ def commands(command)
6
+ ::Appium::Core::Commands::COMMANDS_EXTEND_W3C[command]
7
+ end
8
+
9
+ def action(async = false)
10
+ ::Selenium::WebDriver::W3CActionBuilder.new self,
11
+ ::Selenium::WebDriver::Interactions.pointer(:touch, name: 'touch'),
12
+ ::Selenium::WebDriver::Interactions.key('keyboard'),
13
+ async
14
+ end
15
+ alias actions action
16
+
17
+ # override
18
+ def find_element_by(how, what, parent = nil)
19
+ how, what = convert_locators(how, what)
20
+
21
+ id = if parent
22
+ execute :find_child_element, { id: parent }, { using: how, value: what }
23
+ else
24
+ execute :find_element, {}, { using: how, value: what }
25
+ end
26
+ ::Selenium::WebDriver::Element.new self, element_id_from(id)
27
+ end
28
+
29
+ # override
30
+ def find_elements_by(how, what, parent = nil)
31
+ how, what = convert_locators(how, what)
32
+
33
+ ids = if parent
34
+ execute :find_child_elements, { id: parent }, { using: how, value: what }
35
+ else
36
+ execute :find_elements, {}, { using: how, value: what }
37
+ end
38
+
39
+ ids.map { |id| ::Selenium::WebDriver::Element.new self, element_id_from(id) }
40
+ end
41
+
42
+ private
43
+
44
+ # Don't convert locators for Appium Client
45
+ # TODO: Only for Appium. Ideally, we'd like to keep the selenium-webdriver
46
+ def convert_locators(how, what)
47
+ # case how
48
+ # when 'class name'
49
+ # how = 'css selector'
50
+ # what = ".#{escape_css(what)}"
51
+ # when 'id'
52
+ # how = 'css selector'
53
+ # what = "##{escape_css(what)}"
54
+ # when 'name'
55
+ # how = 'css selector'
56
+ # what = "*[name='#{escape_css(what)}']"
57
+ # when 'tag name'
58
+ # how = 'css selector'
59
+ # end
60
+ [how, what]
61
+ end
62
+ end # class CoreBridgeW3C
63
+ end # class Base
64
+ end # module Core
65
+ end # module Appium
@@ -72,8 +72,27 @@ module Appium
72
72
  COMMANDS = {}.merge(COMMAND).merge(COMMAND_ANDROID).merge(COMMAND_IOS)
73
73
  .merge(COMMAND_NO_ARG).freeze
74
74
 
75
- COMMANDS_EXTEND_MJSONWP = COMMANDS.merge(::Appium::Core::Base::Commands::OSS).freeze
76
- COMMANDS_EXTEND_W3C = COMMANDS.merge(::Appium::Core::Base::Commands::W3C).freeze
75
+ COMMANDS_EXTEND_MJSONWP = COMMANDS.merge(
76
+ {
77
+ # W3C already has.
78
+ take_element_screenshot: [:get, 'session/:session_id/element/:id/screenshot'.freeze]
79
+ }
80
+ ).merge(::Appium::Core::Base::Commands::OSS).freeze
81
+ COMMANDS_EXTEND_W3C = COMMANDS.merge(
82
+ {
83
+ # ::Appium::Core::Base::Commands::OSS has the following commands and Appium also use them.
84
+ # Delegated to ::Appium::Core::Base::Commands::OSS commands
85
+ status: [:get, 'status'.freeze],
86
+ is_element_displayed: [:get, 'session/:session_id/element/:id/displayed'.freeze],
87
+
88
+ # For IME
89
+ ime_get_available_engines: [:get, 'session/:session_id/ime/available_engines'.freeze],
90
+ ime_get_active_engine: [:get, 'session/:session_id/ime/active_engine'.freeze],
91
+ ime_is_activated: [:get, 'session/:session_id/ime/activated'.freeze],
92
+ ime_deactivate: [:post, 'session/:session_id/ime/deactivate'.freeze],
93
+ ime_activate_engine: [:post, 'session/:session_id/ime/activate'.freeze]
94
+ }
95
+ ).merge(::Appium::Core::Base::Commands::W3C).freeze
77
96
  end
78
97
  end
79
98
  end
@@ -375,6 +375,16 @@ module Appium
375
375
  # @driver.switch_to_default_context
376
376
  #
377
377
 
378
+ # @!method take_element_screenshot(element, png_path)
379
+ # @param [Selenium::WebDriver::Element] element A element you'd like to take screenshot.
380
+ # @param [String] png_path A path to save the screenshot
381
+ # @return [File] Path to the screenshot.
382
+ #
383
+ # @example
384
+ #
385
+ # @driver.take_element_screenshot(element, "fine_name.png")
386
+ #
387
+
378
388
  ####
379
389
  ## class << self
380
390
  ####
@@ -454,6 +464,19 @@ module Appium
454
464
  end
455
465
  end
456
466
 
467
+ add_endpoint_method(:take_element_screenshot) do
468
+ def take_element_screenshot(element, png_path)
469
+ result = execute :take_element_screenshot, id: element.ref
470
+
471
+ extension = File.extname(png_path).downcase
472
+ if extension != '.png'
473
+ WebDriver.logger.warn 'name used for saved screenshot does not match file type. '\
474
+ 'It should end with .png extension'
475
+ end
476
+ File.open(png_path, 'wb') { |f| f << result.unpack('m')[0] }
477
+ end
478
+ end
479
+
457
480
  add_endpoint_method(:set_immediate_value) do
458
481
  def set_immediate_value(element, *value)
459
482
  keys = ::Selenium::WebDriver::Keys.encode(value)
@@ -194,6 +194,15 @@ module Appium
194
194
  raise e.message, ::Appium::Core::Error::ServerError
195
195
  end
196
196
 
197
+ Appium::Logger.debug(e.message)
198
+ {}
199
+ rescue Selenium::WebDriver::Error::WebDriverError => e
200
+ # FIXME: Temporary rescue until Appium support W3C's implicit wait
201
+ # https://github.com/jlipps/simple-wd-spec#set-timeouts
202
+ unless e.message.include?('Parameters were incorrect. We wanted {"required":["type","ms"]} and you sent ["implicit"]')
203
+ raise e.message, ::Appium::Core::Error::ServerError
204
+ end
205
+
197
206
  Appium::Logger.debug(e.message)
198
207
  {}
199
208
  end
@@ -1,6 +1,6 @@
1
1
  module Appium
2
2
  module Core
3
- VERSION = '1.1.0'.freeze unless defined? ::Appium::Core::VERSION
4
- DATE = '2017-12-16'.freeze unless defined? ::Appium::Core::DATE
3
+ VERSION = '1.2.0'.freeze unless defined? ::Appium::Core::VERSION
4
+ DATE = '2017-12-23'.freeze unless defined? ::Appium::Core::DATE
5
5
  end
6
6
  end
data/release_notes.md CHANGED
@@ -1,3 +1,13 @@
1
+ #### v1.2.0 2017-12-23
2
+
3
+ - [28f937b](https://github.com/appium/ruby_lib_core/commit/28f937bbaf15a7d99b8870b5b1ec1f063414ea3b) Release 1.2.0
4
+ - [27c1475](https://github.com/appium/ruby_lib_core/commit/27c1475d4cce8271ddc8409c14fb7bdfa1ff6834) update changelog
5
+ - [82e2526](https://github.com/appium/ruby_lib_core/commit/82e2526de95b05e8a49872e0b69835e99acc66e5) add w3c touch action tests and some supports for w3c (#35)
6
+ - [415b908](https://github.com/appium/ruby_lib_core/commit/415b90827105e84234e52f5faedde02357083b66) add take element screenshot for oss (#33)
7
+ - [9dd9c83](https://github.com/appium/ruby_lib_core/commit/9dd9c83271483727e4429e7e6602480da214e118) add adding appium-prefix for W3C format (#34)
8
+ - [cb94184](https://github.com/appium/ruby_lib_core/commit/cb94184854a9977a08f15a44843778314470a73a) update changelog
9
+
10
+
1
11
  #### v1.1.0 2017-12-16
2
12
 
3
13
  - [29b36af](https://github.com/appium/ruby_lib_core/commit/29b36af7af280308f7cfc2ee7ffa1738085e0306) Release 1.1.0
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: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuaki MATSUO
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-16 00:00:00.000000000 Z
11
+ date: 2017-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selenium-webdriver
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.4'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 3.4.1
19
+ version: '3.5'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '3.4'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 3.4.1
26
+ version: '3.5'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: json
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -78,14 +72,14 @@ dependencies:
78
72
  requirements:
79
73
  - - "~>"
80
74
  - !ruby/object:Gem::Version
81
- version: '0.9'
75
+ version: 0.9.11
82
76
  type: :development
83
77
  prerelease: false
84
78
  version_requirements: !ruby/object:Gem::Requirement
85
79
  requirements:
86
80
  - - "~>"
87
81
  - !ruby/object:Gem::Version
88
- version: '0.9'
82
+ version: 0.9.11
89
83
  - !ruby/object:Gem::Dependency
90
84
  name: minitest
91
85
  requirement: !ruby/object:Gem::Requirement
@@ -214,7 +208,9 @@ files:
214
208
  - lib/appium_lib_core/common/base/command.rb
215
209
  - lib/appium_lib_core/common/base/driver.rb
216
210
  - lib/appium_lib_core/common/base/http_default.rb
211
+ - lib/appium_lib_core/common/base/msjsonwp_bridge.rb
217
212
  - lib/appium_lib_core/common/base/search_context.rb
213
+ - lib/appium_lib_core/common/base/w3c_bridge.rb
218
214
  - lib/appium_lib_core/common/base/wait.rb
219
215
  - lib/appium_lib_core/common/command.rb
220
216
  - lib/appium_lib_core/common/device.rb