Skip to content

Instantly share code, notes, and snippets.

@rafaelanastacioalves
Last active October 29, 2017 19:46
Show Gist options
  • Save rafaelanastacioalves/41b6eb4643187db42faa151c2a6e1dd8 to your computer and use it in GitHub Desktop.
Save rafaelanastacioalves/41b6eb4643187db42faa151c2a6e1dd8 to your computer and use it in GitHub Desktop.
Helper methods that I created for Android automations with Calabash.
# @author Rafael Alves <rafaelanastacioalves@gmail.com>
def scrolla_procurando_id element_id, scroll_location_id, scroll_location_query = nil, options = {}
#depois ele volta para onde ele tinha iniciado a procura
if scroll_location_query.nil?
scroll_location_query="* id:'#{scroll_location_id}'"
end
if options[:timeout].nil?
options[:timeout]=15
end
numero_de_scrolladas = 0
wait_poll(:until_exists => "* id:'#{element_id}'", :timeout => 15) do
scroll(scroll_location_query, :down)
numero_de_scrolladas = numero_de_scrolladas +1
end
while(numero_de_scrolladas !=0) do
scroll(scroll_location_query, :up)
numero_de_scrolladas = numero_de_scrolladas -1
end
end
# @author Rafael Alves <rafaelanastacioalves@gmail.com>
def scrolla_procurando_texto text, scroll_location_id, scroll_location_query = nil, options = {}
#depois ele volta para onde ele tinha iniciado a procura
if scroll_location_query.nil?
scroll_location_query="* id:'#{scroll_location_id}'"
end
if options[:timeout].nil?
options[:timeout]=15
end
numero_de_scrolladas = 0
wait_poll(:until_exists => "* {text CONTAINS[c] '#{text}'}", :timeout => options[:timeout]) do
scroll(scroll_location_query, :down)
numero_de_scrolladas = numero_de_scrolladas +1
end
while(numero_de_scrolladas !=0) do
scroll(scroll_location_query, :up)
numero_de_scrolladas = numero_de_scrolladas -1
end
end
# @author Rafael Alves <rafaelanastacioalves@gmail.com>
def scrolla_ate_aparecer_id element_id, scroll_location_id, scroll_location_query = nil, direction=:down, options = {}
#depois ele permanece
if scroll_location_query.nil?
scroll_location_query="* id:'#{scroll_location_id}'"
end
if options[:timeout].nil?
options[:timeout]=15
end
wait_poll(:until_exists => "* id:'#{element_id}'", :timeout => options[:timeout]) do
scroll(scroll_location_query, direction)
end
end
# @author Rafael Alves <rafaelanastacioalves@gmail.com>
def scrolla_ate_aparecer_texto text, scroll_location_id, scroll_location_query = nil, direction= :down, options = {}
#depois ele permanece
if scroll_location_query.nil?
scroll_location_query="* id:'#{scroll_location_id}'"
end
if options[:timeout].nil?
options[:timeout]=15
end
wait_poll(:until_exists => "* {text CONTAINS[c] '#{text}'}", :timeout => options[:timeout]) do
scroll(scroll_location_query, direction)
end
end
# @param query [String] query que será buscada
# @param scroll_location_id [String]
# @param scroll_location_query [String, nil]
# @param direction [Symbol]
# @param options [Hash]
# @option options [String] :timeout
# @option options [String] :flick em caso de precisarmos de flick
# @todo #TODO Colocar opção de reset para poder retornar ao começo do scroll
# antes de realizar a busca
# @author Rafael Alves <rafaelanastacioalves@gmail.com>
def scrolla_ate_aparecer_query query, scroll_location_id, scroll_location_query = nil , direction= :down, options = {}
#depois ele permanece
if scroll_location_query.nil?
scroll_location_query="* id:'#{scroll_location_id}'"
end
if options[:timeout].nil?
options[:timeout]=15
end
if options[:flick].nil?
options[:flick]=false
end
wait_poll(:until_exists => query, :timeout => options[:timeout]) do
if options[:flick]
flick(scroll_location_query, direction)
else
scroll(scroll_location_query, direction)
end
end
end
# @param [String] id The view's id
# @param [String] The complete view query (optional)
# @return [Array] return an array[String] associated with the views
# @author Rafael Alves <rafaelanastacioalves@gmail.com>
def text_array_from(id, query = nil)
query = "* id:'#{id}'" if query.nil?
query(query, :text)
end
# @param [String] id The view's id
# @param [String] The complete view query (optional)
# @return [String] returns a string associated with a single view
# @author Rafael Alves <rafaelanastacioalves@gmail.com>
def text_from(id, query = nil)
text_array_from(id, query).first
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment