Forum Discussion

Nimeshika's avatar
Nimeshika
Contributor
11 years ago

How to validate the color of single line in text object

Hello,         I have  a TextBlockClass , System.Windows.Controls.TextBlock where only the heading line is in Bold Red. Rest of the text is in normal black font. I want to validate that the header ...
  • HKosova's avatar
    11 years ago

    Hi Nimeshika,

    There should be separate objects for TextBlock text lines even if they're not spyable. Check TextBlock's child objects in the Object Browser - you should see something like this:



    Once you find the needed object, you can check its FontWeight and Foreground.Color properties to verify the style. Here's an example:

    // JScript
    function Test()
    {
      var header = ...; // "Path" to your header object

      // Check the font weight
      var strFontWeigth = header.FontWeight.ToString().OleValue;
      if (strFontWeigth == "Bold")
      {
        Log.Checkpoint("The header is in Bold.");
      }
      else
      {
        Log.Error("The header is not in Bold; it's " + strFontWeigth);
      }

      // Check the font color
      var strColor = header.Foreground.Color.ToString().OleValue;
      if (strColor == "#FFFF0000")
      {
        Log.Checkpoint("The header is red.");
      }
      else
      {
        Log.Error("The header is not red (#FFFF0000); it's " + strColor);
      }
    }