Skip to content

Instantly share code, notes, and snippets.

@rafaelanastacioalves
Last active April 11, 2017 13:37
Show Gist options
  • Save rafaelanastacioalves/fa42ca439e0341270343e13da54f9280 to your computer and use it in GitHub Desktop.
Save rafaelanastacioalves/fa42ca439e0341270343e13da54f9280 to your computer and use it in GitHub Desktop.
Helper methods that I created for iOS automations with Calabash.
# @param [String] marked The view's 'marked' attribute
# @param [String] query 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(marked, query = nil)
query = "* marked:'#{marked}'" if query.nil?
query(query, :text)
end
# @param [String] marked The view's 'marked' attribute
# @param [String] query The complete view query (optional)
# @return [String] returns a string associated with a single view
# @author Rafael Alves <rafaelanastacioalves@gmail.com>
def text_from(marked, query = nil)
text_array_from(marked, query).first
end
# @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="* marked:'#{scroll_location_id}'"
end
numero_de_scrolladas = 0
wait_poll(:until_exists => "* marked:'#{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="* marked:'#{scroll_location_id}'"
end
numero_de_scrolladas = 0
wait_poll(:until_exists => "* {text CONTAINS[c] '#{text}'}", :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_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="* marked:'#{scroll_location_id}'"
end
if options[:timeout].nil?
options[:timeout]=15
end
wait_poll(:until_exists => "* marked:'#{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="* marked:'#{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
# @author Rafael Alves <rafaelanastacioalves@gmail.com>
#não tem para Android, criar! (ainda não achei necessario)
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="* marked:'#{scroll_location_id}'"
end
if options[:timeout].nil?
options[:timeout]=15
end
wait_poll(:until_exists => query, :timeout => options[:timeout]) do
scroll(scroll_location_query, direction)
end
end
# @author Rafael Alves <rafaelanastacioalves@gmail.com>
def scrolla_number_picker_ate_aparecer_texto text, scroll_location_query=nil
numero_de_scrolladas = 0
wait_for(:timeout=>15) do # somente quando 3 UIView são contabilizados, é sinal de que o valor scrollado está em evidencia
while query("* {text CONTAINS[c] '#{text}'}").size<3 do
scroll_to_row(scroll_location_query, numero_de_scrolladas)
numero_de_scrolladas = numero_de_scrolladas + 1
sleep 1
end
true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment