How to write a text in red color

Hi All,

I am directing my script output to the file by executing the script
through DOS prompt like test.rb > results.txt. My question is how do I
write test case failed puts statement in red color? is there any
WATIR/ruby method available?

ex: script

My aim is write this text in red color in the following method

puts “Test Failed! Could not find: #{val}”

def Set(ie,id,val)
writeln 'SET - ’ + id + ’ ’ + val
$ie.text_field(:id, id).set(val)

if id == 'username'
  puts "Test Passed. Found the test string: #{id}. "

elsif id == 'password'
  puts "Test Passed. Found the test string: #{id}. "

 elsif $ie.contains_text(val)
  puts "Test Passed. Found the test string: #{val}. "
else
  puts "Test Failed! Could not find: #{val}"
end

end

On Fri, Sep 30, 2011 at 1:25 PM, Sat nosur [email protected] wrote:

Hi All,

I am directing my script output to the file by executing the script
through DOS prompt like test.rb > results.txt. My question is how do I
write test case failed puts statement in red color? is there any
WATIR/ruby method available?

Try searching:
PS C:> gem search -r color

If you want to output ANSI escape sequences and get color output, use
GitHub - adoxa/ansicon: Process ANSI escape sequences for Windows console programs. (Ruby gems that you installed might
implicitly assume ANSI escape sequences).


Phillip G.

gplus.to/phgaw | twitter.com/phgaw

A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
– Leibniz

try this on ruby under msdos under windows xp - it works fine
require ‘rubygems’
require ‘Win32console’
matchknt=1
mismatchknt=3
puts “#{matchknt} \e[32mmatch\e[0m and #{mismatchknt}
\e[31mmismatch\e[0m”

Reference

Hope that helps

Joe

how does that work?

Joe

I prefer to use the rainbow gem.