class AppPrism::Elements::Element

Attributes

locator[R]
platform[R]

Public Class Methods

new(identifiers, driver) click to toggle source
# File lib/app_prism/elements/element.rb, line 7
def initialize(identifiers, driver)
  if identifiers.is_a?(Selenium::WebDriver::Element)
    @element = identifiers
  else
    if identifiers.keys.include?(:android) || identifiers.keys.include?(:ios)
      @locator = identifiers[:android] if android?
      @locator = identifiers[:ios] if ios?
    else
      @locator = identifiers
    end
  end
  @platform = driver
end

Public Instance Methods

clear() click to toggle source
# File lib/app_prism/elements/element.rb, line 108
def clear
  element.send_keys ''
end
click() click to toggle source
# File lib/app_prism/elements/element.rb, line 116
def click
  element.click
end
default_wait_time() click to toggle source
# File lib/app_prism/elements/element.rb, line 90
def default_wait_time
  AppPrism::DEFAULT_WAIT_TIME || 30
end
element() click to toggle source
# File lib/app_prism/elements/element.rb, line 21
def element
  @element || @platform.find_element(@locator)
rescue RuntimeError
  nil
end
nested_element(identifiers) click to toggle source

def swipe_up

@platform.swipe_up(@locator)

end

# File lib/app_prism/elements/element.rb, line 71
def nested_element(identifiers)
  nested_elt = element.find_element(identifiers[:android]) if android?
  nested_elt = element.find_element(identifiers[:ios]) if ios?
  self.class.new(nested_elt, @platform)
end
parent() click to toggle source

def value

get_parameter 'value'

end

# File lib/app_prism/elements/element.rb, line 133
def parent
  loc = if @locator.has_key? :xpath
          @locator[:xpath] + '/..'
        elsif @locator.has_key? :id
          "//*[@id=\"#{@locator[:id]}\"]/.."
        else
          raise 'Something wrong happened'
        end
  @platform.find_element(loc)
end
send_keys(text) click to toggle source
# File lib/app_prism/elements/element.rb, line 104
def send_keys(text)
  element.send_keys text
end
size() click to toggle source

def scroll_into_view

raise 'Does not work yet'

end

# File lib/app_prism/elements/element.rb, line 157
def size
  element.size
  # rect = get_element['rect']
  # height = rect['height']
  # width = rect['width']
  # {height: height, width: width}
end
text() click to toggle source

def long_press

when_visible
@platform.long_touch(@locator)

end

# File lib/app_prism/elements/element.rb, line 125
def text
  element.text
end
touch() click to toggle source
# File lib/app_prism/elements/element.rb, line 112
def touch
  when_visible.click
end
visible?() click to toggle source
# File lib/app_prism/elements/element.rb, line 144
def visible?
  element.nil? ? false : element.displayed?
  # element ? element.displayed? : false
end
wait_for(wait_time: default_wait_time) { || ... } click to toggle source
# File lib/app_prism/elements/element.rb, line 94
def wait_for(wait_time: default_wait_time)
  start_time = Time.now
  loop do
    return true if yield
    break unless (Time.now - start_time) < wait_time
    sleep 0.5
  end
  raise Timeout::Error, "Timed out while waiting for locator:\"#{@locator}\""
end
when_not_visible(wait_time = default_wait_time) click to toggle source
# File lib/app_prism/elements/element.rb, line 84
def when_not_visible(wait_time = default_wait_time)
  wait_for(wait_time: wait_time) { !visible? }
rescue Selenium::WebDriver::Error::NoSuchElementError,Timeout::Error,RuntimeError
  return
end
when_visible(wait_time = default_wait_time) click to toggle source
# File lib/app_prism/elements/element.rb, line 77
def when_visible(wait_time = default_wait_time)
  wait_for(wait_time: wait_time) { visible? }
  self
rescue Timeout::Error
  false
end