class Appium::Capybara::Appium::Capybara::Appium::Capybara::Driver

methods in this class either override selenium driver methods or they’re new and specific to appium.

Public Instance Methods

accept_modal(type, options = {}, &blk) click to toggle source

override type and options are passed but can be ignored.

# File lib/appium_capybara/driver/appium/driver.rb, line 66
def accept_modal(type, options = {}, &blk)
  appium_driver.alert_accept
end
appium_driver() click to toggle source

new

starts new driver

# File lib/appium_capybara/driver/appium/driver.rb, line 9
def appium_driver
  # must use self to reference the 'browser' method
  browser unless @appium_driver

  @appium_driver
end
browser() click to toggle source

override

Creates and starts a new appium driver. To access the browser without creating one use @browser

# File lib/appium_capybara/driver/appium/driver.rb, line 20
def browser
  return @browser if @browser

  @appium_driver = Appium::Driver.new @options, false
  # browser is the standard selenium driver without any appium methods
  @browser = @appium_driver.start_driver

  main = Process.pid
  at_exit do
    # Store the exit status of the test run since it goes away after calling the at_exit proc...
    @exit_status = $ERROR_INFO.status if $ERROR_INFO.is_a?(SystemExit)
    quit if Process.pid == main
    exit @exit_status if @exit_status # Force exit with stored status
  end
  @browser
end
browser_initialized?() click to toggle source

@deprecated This method is being removed

# File lib/appium_capybara/driver/appium/driver.rb, line 54
def browser_initialized?
  !!@browser
end
dismiss_modal(type, options = {}, &blk) click to toggle source

override type and options are passed but can be ignored.

# File lib/appium_capybara/driver/appium/driver.rb, line 60
def dismiss_modal(type, options = {}, &blk)
  appium_driver.alert_dismiss
end
find_css(selector) click to toggle source

override

# File lib/appium_capybara/driver/appium/driver.rb, line 43
def find_css(selector)
  appium_driver.find_elements(:css, selector).map { |node| Appium::Capybara::Node.new(self, node) }
end
find_custom(finder, locator) click to toggle source

new

# File lib/appium_capybara/driver/appium/driver.rb, line 113
def find_custom(finder, locator)
  appium_driver.find_elements(finder, locator).map { |node| Appium::Capybara::Node.new(self, node) }
end
find_xpath(selector) click to toggle source

override

# File lib/appium_capybara/driver/appium/driver.rb, line 38
def find_xpath(selector)
  appium_driver.find_elements(:xpath, selector).map { |node| Appium::Capybara::Node.new(self, node) }
end
quit() click to toggle source

override

# File lib/appium_capybara/driver/appium/driver.rb, line 118
def quit
  @appium_driver.driver_quit if @browser || @appium_driver
rescue Errno::ECONNREFUSED
  # Browser must have already gone
ensure
  @browser = nil
  @appium_driver = nil
end
reset!() click to toggle source

override

# File lib/appium_capybara/driver/appium/driver.rb, line 48
def reset!
  # Re-create a new session.
  @appium_driver&.restart
end
rotate(opts) click to toggle source

new Use :landscape or :portrait

# File lib/appium_capybara/driver/appium/driver.rb, line 102
def rotate(opts)
  browser.rotate opts
end
save_screenshot(path, options = {}) click to toggle source

override Capybara always passes an options param but appium_lib can’t do anything with it.

# File lib/appium_capybara/driver/appium/driver.rb, line 108
def save_screenshot(path, options = {})
  appium_driver.screenshot path if @appium_driver
end
scroll_down() click to toggle source

new

# File lib/appium_capybara/driver/appium/driver.rb, line 76
def scroll_down
  browser.execute_script('mobile: scroll', direction: 'down')
end
scroll_up() click to toggle source

new

# File lib/appium_capybara/driver/appium/driver.rb, line 71
def scroll_up
  browser.execute_script('mobile: scroll', direction: 'up')
end
swipe(opts) click to toggle source

new

# File lib/appium_capybara/driver/appium/driver.rb, line 81
def swipe(opts)
  start_x = opts.fetch :start_x, 0
  start_y = opts.fetch :start_y, 0
  end_x   = opts.fetch :end_x, 0
  end_y   = opts.fetch :end_y, 0
  duration = opts.fetch :duration, 200

  action_builder = browser.action
  input = action_builder.pointer_inputs[0]
  action_builder
    .move_to_location(start_x, start_y)
    .pointer_down(:left)
    .pause(device: input, duration: duration / 1000)
    .move_to_location(end_x, end_y)
    .pause(device: input, duration: 1)
    .release
    .perform
end