2

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.

Graeme Phillips
  • 131
  • 1
  • 1
  • 10

1 Answers1

2

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}
Community
  • 1
  • 1
alannichols
  • 1,496
  • 1
  • 10
  • 20
  • hi Alan, I am trying to query, get result, write result to file. Perhaps I should be writing to file syntax and within the syntax construct the query? – Graeme Phillips May 01 '15 at 10:03
  • Either should work really, it's just a matter of preference. I'd lean towards using the second approach I just added to my answer, as you'll be abel to trim down what you're writing to the file, i.e. you'll be able to run select/map on the query results and only write the bits you want to the file. – alannichols May 01 '15 at 10:08
  • thanks Alan, hopefully soon will come the time I won't have to ask all these stupid questions, all the best. – Graeme Phillips May 01 '15 at 10:32
  • No problem at all! Very happy to help. Calabash is a great tool, the more people using it the better :) – alannichols May 01 '15 at 10:35
  • outstanding Alan! output to csv - this has saved me two weeks legwork! – Graeme Phillips May 01 '15 at 11:48