Module: Appium

Defined in:
lib/appium_lib/common/helper.rb,
lib/appium_lib/driver.rb,
lib/appium_lib/logger.rb,
lib/appium_lib/ios/patch.rb,
lib/appium_lib/ios/helper.rb,
lib/appium_lib/common/wait.rb,
lib/appium_lib/common/patch.rb,
lib/appium_lib/android/patch.rb,
lib/appium_lib/device/device.rb,
lib/appium_lib/android/helper.rb,
lib/appium_lib/common/version.rb,
lib/appium_lib/ios/element/text.rb,
lib/appium_lib/ios/element/alert.rb,
lib/appium_lib/device/multi_touch.rb,
lib/appium_lib/ios/element/button.rb,
lib/appium_lib/ios/mobile_methods.rb,
lib/appium_lib/ios/element/generic.rb,
lib/appium_lib/android/client_xpath.rb,
lib/appium_lib/android/element/text.rb,
lib/appium_lib/device/touch_actions.rb,
lib/appium_lib/android/element/alert.rb,
lib/appium_lib/common/element/window.rb,
lib/appium_lib/ios/element/textfield.rb,
lib/appium_lib/android/element/button.rb,
lib/appium_lib/android/mobile_methods.rb,
lib/appium_lib/android/element/generic.rb,
lib/appium_lib/android/element/textfield.rb

Overview

UIAButton methods

Defined Under Namespace

Modules: Android, Common, Device, Ios, Logger Classes: Driver, MultiTouch, TouchAction

Constant Summary collapse

VERSION =

Version and Date are defined on the ‘Appium’ module, not ‘Appium::Common’

'8.0.2'
DATE =
'2016-01-29'

Class Method Summary collapse

Class Method Details

.load_appium_txt(opts = {}) ⇒ hash

Load appium.txt (toml format) the basedir of this file + appium.txt is what’s used

“‘

caps

app = “path/to/app”

appium_lib

port = 8080 “‘

:app is expanded :require is expanded all keys are converted to symbols

Parameters:

  • opts (Hash) (defaults to: {})

    file: ‘/path/to/appium.txt’, verbose: true

Returns:

  • (hash)

    the symbolized hash with updated :app and :require keys



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/appium_lib/driver.rb', line 70

def self.load_appium_txt(opts = {})
  fail 'opts must be a hash' unless opts.is_a? Hash
  fail 'opts must not be empty' if opts.empty?

  file = opts[:file]
  fail 'Must pass file' unless file
  verbose = opts.fetch :verbose, false

  parent_dir = File.dirname file
  toml       = File.expand_path File.join parent_dir, 'appium.txt'
  Appium::Logger.info "appium.txt path: #{toml}" if verbose

  toml_exists = File.exist? toml
  Appium::Logger.info "Exists? #{toml_exists}" if verbose

  fail "toml doesn't exist #{toml}" unless toml_exists
  require 'tomlrb'
  Appium::Logger.info "Loading #{toml}" if verbose

  data = Tomlrb.load_file(toml, symbolize_keys: true)
  Appium::Logger.ap_info data unless data.empty? if verbose

  if data && data[:caps] && data[:caps][:app] && !data[:caps][:app].empty?
    data[:caps][:app] = Appium::Driver.absolute_app_path data
  end

  # return list of require files as an array
  # nil if require doesn't exist
  if data && data[:appium_lib] && data[:appium_lib][:require]
    r = data[:appium_lib][:require]
    r = r.is_a?(Array) ? r : [r]
    # ensure files are absolute
    r.map! do |f|
      file = File.exist?(f) ? f : File.join(parent_dir, f)
      file = File.expand_path file

      File.exist?(file) ? file : nil
    end
    r.compact! # remove nils

    files = []

    # now expand dirs
    r.each do |item|
      unless File.directory? item
        # save file
        files << item
        next # only look inside folders
      end
      Dir.glob(File.expand_path(File.join(item, '**', '*.rb'))) do |f|
        # do not add folders to the file list
        files << File.expand_path(f) unless File.directory? f
      end
    end

    # Must not sort files. File order is specified in appium.txt
    data[:appium_lib][:require] = files
  end

  data
end

.promote_appium_methods(class_array) ⇒ Object

Promote appium methods to class instance methods

To promote methods to all classes:

“‘ruby Appium.promote_appium_methods Object “`

It’s better to promote on specific classes instead of Object

“‘ruby # promote on rspec Appium.promote_appium_methods RSpec::Core::ExampleGroup “`

“‘ruby # promote on minispec Appium.promote_appium_methods Minitest::Spec “`

Parameters:

  • class_array (Array<Class>)

    An array of classes



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/appium_lib/driver.rb', line 208

def self.promote_appium_methods(class_array)
  fail 'Driver is nil' if $driver.nil?
  # Wrap single class into an array
  class_array = [class_array] unless class_array.class == Array
  # Promote Appium driver methods to class instance methods.
  class_array.each do |klass|
    $driver.public_methods(false).each do |m|
      klass.class_eval do
        define_method m do |*args, &block|
          begin
            # Prefer existing method.
            # super will invoke method missing on driver
            super(*args, &block)

            # minitest also defines a name method,
            # so rescue argument error
            # and call the name method on $driver
          rescue NoMethodError, ArgumentError
            $driver.send m, *args, &block if $driver.respond_to?(m)
          end
        end
      end
    end
  end
  nil # return nil
end

.promote_singleton_appium_methods(modules) ⇒ Object

This method is intended to work with page objects that share a common module. For example, Page::HomePage, Page::SignIn those could be promoted on with Appium.promote_singleton_appium_methods Page

If you are promoting on an individual class then you should use Appium.promote_appium_methods instead. The singleton method is intended only for the shared module use case.

if modules is a module instead of an array, then the constants of that module are promoted on. otherwise, the array of modules will be used as the promotion target.



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/appium_lib/driver.rb', line 157

def self.promote_singleton_appium_methods(modules)
  fail 'Driver is nil' if $driver.nil?

  target_modules = []

  if modules.is_a? Module
    modules.constants.each do |sub_module|
      target_modules << modules.const_get(sub_module)
    end
  else
    fail 'modules must be a module or an array' unless modules.is_a? Array
    target_modules = modules
  end

  target_modules.each do |const|
    # noinspection RubyResolve
    $driver.public_methods(false).each do |m|
      const.send(:define_singleton_method, m) do |*args, &block|
        begin
          super(*args, &block) # promote.rb
        rescue NoMethodError, ArgumentError
          $driver.send m, *args, &block if $driver.respond_to?(m)
        end
        # override unless there's an existing method with matching arity
      end unless const.respond_to?(m) && const.method(m).arity == $driver.method(m).arity
    end
  end
end

.symbolize_keys(hash) ⇒ Object

convert all keys (including nested) to symbols

based on deep_symbolize_keys & deep_transform_keys from rails github.com/rails/docrails/blob/a3b1105ada3da64acfa3843b164b14b734456a50/activesupport/lib/active_support/core_ext/hash/keys.rb#L84



136
137
138
139
140
141
142
143
144
# File 'lib/appium_lib/driver.rb', line 136

def self.symbolize_keys(hash)
  fail 'symbolize_keys requires a hash' unless hash.is_a? Hash
  result = {}
  hash.each do |key, value|
    key = key.to_sym rescue key # rubocop:disable Style/RescueModifier
    result[key] = value.is_a?(Hash) ? symbolize_keys(value) : value
  end
  result
end