Module: Appium

Defined in:
lib/appium_lib/common/helper.rb,
lib/appium_lib/appium.rb,
lib/appium_lib/driver.rb,
lib/appium_lib/ios/ios.rb,
lib/appium_lib/version.rb,
lib/appium_lib/common/log.rb,
lib/appium_lib/sauce_labs.rb,
lib/appium_lib/common/wait.rb,
lib/appium_lib/ios/xcuitest.rb,
lib/appium_lib/common/device.rb,
lib/appium_lib/android/android.rb,
lib/appium_lib/android/espresso.rb,
lib/appium_lib/ios/element/text.rb,
lib/appium_lib/ios/common/errors.rb,
lib/appium_lib/ios/common/helper.rb,
lib/appium_lib/ios/element/alert.rb,
lib/appium_lib/common/http_client.rb,
lib/appium_lib/common/multi_touch.rb,
lib/appium_lib/ios/element/button.rb,
lib/appium_lib/ios/element/generic.rb,
lib/appium_lib/ios/xcuitest/bridge.rb,
lib/appium_lib/ios/xcuitest/helper.rb,
lib/appium_lib/android/element/text.rb,
lib/appium_lib/android/uiautomator2.rb,
lib/appium_lib/common/touch_actions.rb,
lib/appium_lib/ios/xcuitest/command.rb,
lib/appium_lib/ios/xcuitest/element.rb,
lib/appium_lib/android/common/helper.rb,
lib/appium_lib/android/element/alert.rb,
lib/appium_lib/ios/element/textfield.rb,
lib/appium_lib/android/element/button.rb,
lib/appium_lib/android/element/generic.rb,
lib/appium_lib/android/espresso/bridge.rb,
lib/appium_lib/android/element/textfield.rb,
lib/appium_lib/ios/xcuitest/element/text.rb,
lib/appium_lib/android/uiautomator2/bridge.rb,
lib/appium_lib/android/uiautomator2/helper.rb,
lib/appium_lib/ios/xcuitest/command/source.rb,
lib/appium_lib/ios/xcuitest/element/button.rb,
lib/appium_lib/android/uiautomator2/element.rb,
lib/appium_lib/ios/xcuitest/element/generic.rb,
lib/appium_lib/ios/xcuitest/command/gestures.rb,
lib/appium_lib/android/common/command/command.rb,
lib/appium_lib/ios/xcuitest/element/textfield.rb,
lib/appium_lib/ios/xcuitest/command/pasteboard.rb,
lib/appium_lib/android/uiautomator2/element/button.rb,
lib/appium_lib/ios/xcuitest/command/multi_app_handler.rb

Overview

XCUIElementTypeButton methods

Defined Under Namespace

Modules: Android, Common, Device, Http, Ios Classes: Driver, MultiTouch, SauceLabs, TouchAction

Constant Summary collapse

REQUIRED_VERSION_XCUITEST =
'1.6.0'.freeze
VERSION =

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

'9.9.2'.freeze
DATE =
'2018-02-12'.freeze

Class Method Summary collapse

Class Method Details

.expand_required_files(base_dir, file_paths) ⇒ Array

Returns list of require files as an array, nil if require doesn't exist

Parameters:

  • base_dir (String)

    parent directory of loaded appium.txt (toml)

  • file_paths (String)

Returns:

  • (Array)

    list of require files as an array, nil if require doesn't exist



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
# File 'lib/appium_lib/appium.rb', line 84

def expand_required_files(base_dir, file_paths)
  # ensure files are absolute
  Array(file_paths).map! do |f|
    file = File.exist?(f) ? f : File.join(base_dir, f)
    file = File.expand_path file

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

  files = []

  # now expand dirs
  file_paths.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

  files
end

.load_settings(opts = {}) ⇒ hash Also known as: load_appium_txt

Load arbitrary text ([toml format](github.com/toml-lang/toml)) The toml is parsed by github.com/fbernier/tomlrb .

“`

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



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/appium_lib/appium.rb', line 45

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

  toml = opts[:file]
  raise 'Must pass a capability file which has [caps] and [appium_lib]' unless toml
  verbose = opts.fetch :verbose, false

  Appium::Logger.info "appium settings path: #{toml}" if verbose

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

  raise "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)
  if verbose
    Appium::Logger.info data unless data.empty?
  end

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

  if data && data[:appium_lib] && data[:appium_lib][:require]
    parent_dir = File.dirname toml
    data[:appium_lib][:require] = expand_required_files(parent_dir, data[:appium_lib][:require])
  end

  data
end

.promote_appium_methods(class_array, driver = $driver) ⇒ Object

Promote appium methods to class instance methods

To promote methods to all classes:

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

Examples:


Appium.promote_appium_methods Object

# promote on rspec
Appium.promote_appium_methods RSpec::Core::ExampleGroup

# promote on minispec
Appium.promote_appium_methods Minitest::Spec

Parameters:

  • class_array (Array<Class>)

    An array of classes

  • driver (Driver) (defaults to: $driver)

    A driver to extend for



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/appium_lib/appium.rb', line 181

def promote_appium_methods(class_array, driver = $driver)
  raise '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, driver = $driver) ⇒ 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.

Parameters:

  • modules (Array<Module>)

    An array of modules

  • driver (Driver) (defaults to: $driver)

    A driver to extend for



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/appium_lib/appium.rb', line 126

def promote_singleton_appium_methods(modules, driver = $driver)
  raise 'Global $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
    raise 'modules must be a module or an array' unless modules.is_a? Array
    target_modules = modules
  end

  target_modules.each do |const|
    # noinspection RubyResolve
    # rubocop:disable Style/MultilineIfModifier
    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
    # rubocop:enable Style/MultilineIfModifier
  end
end