Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions ios_tests/lib/ios/specs/ios/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ def before_first
ios_password(2).must_equal 8226.chr('UTF-8') * 2
end

t 'get_page' do
get_page # writes to std out
end

t 'page' do
page # writes to std out
end
Expand All @@ -31,8 +27,8 @@ def before_first
id 'Buttons' # 'Various uses of UIButton'
end

t 'ios_version' do
ios_version.wont_be_empty
t 'platform_version' do
platform_version.wont_be_empty
end

t 'tags_include' do
Expand Down
2 changes: 0 additions & 2 deletions lib/appium_lib/android/android.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
require_relative 'device'

require_relative 'common/helper'
require_relative 'common/patch'
require_relative 'common/client_xpath'

require_relative 'element/alert'
require_relative 'element/button'
Expand Down
51 changes: 0 additions & 51 deletions lib/appium_lib/android/common/client_xpath.rb

This file was deleted.

16 changes: 0 additions & 16 deletions lib/appium_lib/android/common/patch.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/appium_lib/common/wait.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative '../core/wait'
require_relative '../core/common/wait'

module Appium
module Common
Expand Down
2 changes: 0 additions & 2 deletions lib/appium_lib/core/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module Appium
module Core
module Commands
COMMAND_NO_ARG = {
# core
shake: [:post, 'session/:session_id/appium/device/shake'.freeze],
launch_app: [:post, 'session/:session_id/appium/app/launch'.freeze],
close_app: [:post, 'session/:session_id/appium/app/close'.freeze],
Expand All @@ -13,7 +12,6 @@ module Commands
}.freeze

COMMAND = {
# core
available_contexts: [:get, 'session/:session_id/contexts'.freeze],
set_context: [:post, 'session/:session_id/context'.freeze],
app_strings: [:post, 'session/:session_id/appium/app/strings'.freeze],
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/appium_lib/core/core.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require_relative 'command'
require_relative 'error'
require_relative 'patch'
require_relative 'search_context'
require_relative 'wait'
require_relative 'device'
require_relative 'capabilities'
require_relative 'driver'

require_relative 'common/error'
require_relative 'common/log'
require_relative 'common/wait'

require_relative 'element/window'

Expand Down
18 changes: 18 additions & 0 deletions lib/appium_lib/core/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,24 @@ def appium_server_version
{}
end

# Return the platform version as an array of integers
# @return [Array<Integer>]
def platform_version
p_version = @driver.capabilities['platformVersion']
p_version.split('.').map(&:to_i)
end

# Takes a png screenshot and saves to the target path.
#
# Example: screenshot '/tmp/hi.png'
#
# @param png_save_path [String] the full path to save the png
# @return [nil]
def screenshot(png_save_path)
@driver.save_screenshot png_save_path
nil
end

private

# @private
Expand Down
9 changes: 9 additions & 0 deletions lib/appium_lib/core/patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ def name
attribute :name
end

# Enable access to iOS accessibility label
# accessibility identifier is supported as 'name'
def label
attribute :label
end

# Alias for type
alias type send_keys

# For use with mobile tap.
#
# ```ruby
Expand Down
21 changes: 15 additions & 6 deletions lib/appium_lib/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ def initialize(opts = {}, global_driver = nil)
# Extend each driver's methods
extend_for(device: @core.device, automation_name: @core.automation_name)

# apply os specific patches
patch_webdriver_element

# for command
patch_remote_driver_core_commands(bridge: :oss)
patch_remote_driver_core_commands(bridge: :w3c)
Expand Down Expand Up @@ -197,7 +194,7 @@ def extend_for(device:, automation_name:)
extend Appium::Android::Device
end
when :ios
case driver
case automation_name
when :xcuitest
extend Appium::Ios
extend Appium::Ios::SearchContext
Expand All @@ -213,6 +210,7 @@ def extend_for(device:, automation_name:)
extend Appium::Ios
extend Appium::Ios::SearchContext
extend Appium::Ios::Device
patch_webdriver_element
end
when :mac
# no Mac specific extentions
Expand Down Expand Up @@ -325,6 +323,18 @@ def appium_server_version
{}
end

# Return the platform version as an array of integers
# @return [Array<Integer>]
def platform_version
@core.platform_version
end

# @private
def ios_version
warn '[DEPRECATION] ios_version will be removed. Please use platform_version instead.'
platform_version
end

# Returns the client's version info
#
# ```ruby
Expand Down Expand Up @@ -399,8 +409,7 @@ def restart
# @param png_save_path [String] the full path to save the png
# @return [nil]
def screenshot(png_save_path)
@driver.save_screenshot png_save_path
nil
@core.screenshot png_save_path
end

# Quits the driver
Expand Down
101 changes: 6 additions & 95 deletions lib/appium_lib/ios/common/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def start_element(type, attrs = [])
_print_attr(type, page['name'], page['label'], page['value'], page['hint'], page['visible'])
end

# @private
def _print_attr(type, name, label, value, hint, visible) # rubocop:disable Metrics/ParameterLists
if name == label && name == value
puts type.to_s if name || label || value || hint || visible
Expand Down Expand Up @@ -43,89 +44,6 @@ def ios_password(length = 1)
8226.chr('UTF-8') * length
end

# Returns a string of interesting elements. iOS only.
#
# Defaults to inspecting the 1st windows source only.
# use get_page(get_source) for all window sources
#
# @option element [Object] the element to search. omit to search everything
# @option class_name [String,Symbol] the class name to filter on. case insensitive include match.
# @return [String]
# @deprecated
def get_page(element = source_window(0), class_name = nil)
warn '[DEPRECATION] get_page will be removed. Please use page or source instead.'

lazy_load_strings # populate @strings_xml
class_name = class_name.to_s.downcase

# @private
def empty(ele)
(ele['name'] || ele['label'] || ele['value']).nil?
end

# @private
def fix_space(s)
# if s is an int, we can't call .empty
return nil if s.nil? || (s.respond_to?(:empty) && s.empty?)
# ints don't respond to force encoding
# ensure we're converting to a string
unless s.respond_to? :force_encoding
s_s = s.to_s
return s_s.empty? ? nil : s_s
end
# char code 160 (name, label) vs 32 (value) will break comparison.
# convert string to binary and remove 160.
# \xC2\xA0
s = s.force_encoding('binary').gsub("\xC2\xA0".force_encoding('binary'), ' ') if s
s.empty? ? nil : s.force_encoding('UTF-8')
end

unless empty(element) || element['visible'] == false
name = fix_space element['name']
label = fix_space element['label']
value = fix_space element['value']
hint = fix_space element['hint']
visible = fix_space element['visible']
type = fix_space element['type']

# if class_name is set, mark non-matches as invisible
visible = (type.downcase.include? class_name).to_s if class_name
if visible && visible == 'true'

UITestElementsPrinter.new._print_attr(type, name, label, value, hint, visible)

# there may be many ids with the same value.
# output all exact matches.
attributes = [name, label, value, hint].select { |attr| !attr.nil? }
partial = {}
id_matches = @strings_xml.select do |key, val|
next if val.nil? || val.empty?
partial[key] = val if attributes.detect { |attr| attr.include?(val) }
attributes.detect { |attr| val == attr }
end

# If there are no exact matches, display partial matches.
id_matches = partial if id_matches.empty?

unless id_matches.empty?
match_str = ''
max_len = id_matches.keys.max_by(&:length).length

# [0] = key, [1] = val
id_matches.each do |key, val|
arrow_space = ' ' * (max_len - key.length).to_i
match_str += ' ' * 7 + "#{key} #{arrow_space}=> #{val}\n"
end
puts " id: #{match_str.strip}\n"
end
end
end

children = element['children']
children.each { |c| get_page c, class_name } if children
nil
end

# Prints a string of interesting elements to the console.
#
# Example
Expand Down Expand Up @@ -163,20 +81,20 @@ def page(opts = {})

# Gets the JSON source of window number
# @return [JSON]
def source_window(window_number = nil)
warn '[DEPRECATION] The argument window_number will be removed. Plesse remove window_number' unless window_number
def source_window(_window_number = nil)
warn '[DEPRECATION] source_window will be removed. Please use source instead.'
get_source
end

# @private
# Prints parsed page source to console.
#
# example: page_window 0
#
# @param window_number [Integer] the int index of the target window
# @return [void]
def page_window(window_number = 0)
get_page source_window window_number
nil
def page_window(_window_number = 0)
warn '[DEPRECATION] page_window will be removed. Please use source instead.'
end

# Find by id
Expand All @@ -186,13 +104,6 @@ def id(id)
find_element(:id, id)
end

# Return the iOS version as an array of integers
# @return [Array<Integer>]
def ios_version
ios_version = execute_script 'UIATarget.localTarget().systemVersion()'
ios_version.split('.').map(&:to_i)
end

# Get the element of type class_name at matching index.
# @param class_name [String] the class name to find
# @param index [Integer] the index
Expand Down
6 changes: 0 additions & 6 deletions lib/appium_lib/ios/common/patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ module Ios
# will trigger only when invoked.
def patch_webdriver_element
Selenium::WebDriver::Element.class_eval do
# Enable access to iOS accessibility label
# accessibility identifier is supported as 'name'
def label
attribute('label')
end

# Cross platform way of entering text into a textfield
def type(text, driver = $driver)
driver.execute_script %(au.getElement('#{ref}').setValue('#{text}');)
Expand Down
Loading