Google+ Followers

Thursday, 23 January 2014

How to share calabash commands between IOS and Android

This example suits well for calabash x platform example (where code is shared between IOS and android)

set OS=ios in command line from where your cucumber tests are run (ex: OS=android calabash-android run <apkfile> )
value of @g_query_txt  is set based on env variable

@g_query_txt="view " if ENV['OS']=="ios"
@g_query_txt="* " if ENV['OS']=="android"


Add the below method wait_for_similar_text_to_appear in a class that is accessible to both IOS and android code
or
  Create a common module (between ios & android) and then include that into ios or android classes

 
## Specify text to check and time to wait for
# This will return true even if text matches part of the sentence
@g_query_txt="view " if ENV['OS']=="ios"
@g_query_txt="* " if ENV['OS']=="android"

def wait_for_similar_text_to_appear(text, time_out=5)
  query_text=@g_query_txt+"{text LIKE '*#{text}'}"
  begin
    wait_poll({:until_exists => query_text, :timeout => time_out.to_i}) do
      puts text
    end
  rescue
    fail("Failed to find text"+text)
  end
end

Arguments:
  text: This is part of the text which we want to match
  time_out: Optional argument, default timeout value is 5 seconds

3 comments: