Search code examples
calabashcalabash-android

How do I output calabash query results to a textFile


ok, I've read all the calabsh query docs on xamarin for android and iOS and the Ruby file class and still can't find the answer, so if anyone can help then that would be great.

What I trying to do is run querys in the calabash-android console window and write those results to a file on the fly.

so for instance : query("this is my query", :type (class etc..)
I can also do query("*") - I will then take the text output and collate the information I require to build up an elements 'dictionary'

Ive tried query("*") f.write("C:\myFileName.txt",'w') and the console complains.. I've also tried multiple operators on the query (f.write, f.open).

thanks guys in advance.


Solution

  • The calabash console is just ruby's irb console with the calabash modules loaded. As such you can use any ruby commands to get things done. This answer should cover you - How to write to file in Ruby?

    e.g.

    open('out.txt', 'a') { |f| f.puts query('*')}
    

    will append the query results to out.txt.

    or

    outputs = []
    outputs << query('*')
    outputs << query("* text:'OK'")
    open('out.txt', 'a') { |f| f.puts output}