locked
console.writeline color RRS feed

  • Question

  • Hello,

    I am doing coded UI test on a .net app and writing the output to the standard output by using a try catch, using the Console.Writeline method for displaying the error messages, I want the messages to be displayed in color red is that possible?.
    Sample Code:
    try
                {
                    string expectedresult = "Text to compare ";
                    string actualresult = Actual Text;
                    Assert.AreEqual(expectedresult, actualresult, " Text is not equal.");
                    Console.WriteLine(" Text is equal.");
                }
                catch (AssertFailedException e)
                {
                    Console.WriteLine(" Text is not equal.");
                    isTestFailed = true;
                    errorMessage = errorMessage + "\n" + e.Message;
                }  

    Thanks


    BK

    Friday, June 27, 2014 4:18 PM

Answers

  • @Dominic, thank you for your help, I tried the code in your link, but no success. Console.ForegroundColor and BackgroundColor is for a console, but the Test Result Standard Output is a WPF Text control.

    Hi BK,

    We can adjust the color of the message in Output window through the link provided by Dominic, but there is no built-in method to display the error message with a color in Visual Studio Test Result Standard Output.

    You could submit this feature request:

    http://visualstudio.uservoice.com/forums/121579-visual-studio

    The Visual Studio product team is listening to user voice there. You can send your ideas/suggestions there and people can vote.

    Thanks for your understanding.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Amanda Zhu Monday, June 30, 2014 7:04 AM edit
    • Marked as answer by Amanda Zhu Monday, July 7, 2014 4:40 AM
    Monday, June 30, 2014 7:04 AM

All replies

  • Absolutely http://www.dotnetperls.com/console-color Enjoy :)
    Saturday, June 28, 2014 12:13 AM
  • @Dominic, thank you for your help, I tried the code in your link, but no success. Console.ForegroundColor and BackgroundColor is for a console, but the Test Result Standard Output is a WPF Text control.

    Hi BK,

    We can adjust the color of the message in Output window through the link provided by Dominic, but there is no built-in method to display the error message with a color in Visual Studio Test Result Standard Output.

    You could submit this feature request:

    http://visualstudio.uservoice.com/forums/121579-visual-studio

    The Visual Studio product team is listening to user voice there. You can send your ideas/suggestions there and people can vote.

    Thanks for your understanding.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Amanda Zhu Monday, June 30, 2014 7:04 AM edit
    • Marked as answer by Amanda Zhu Monday, July 7, 2014 4:40 AM
    Monday, June 30, 2014 7:04 AM
  • Thanks, I will submit the request.

    BK

    Monday, June 30, 2014 12:52 PM