Foreground colors - server error on other thread.

2 posts, 0 answers
  1. Travis Acton
    Travis Acton avatar
    13 posts
    Member since:
    Jan 2010

    Posted 23 Jun 2010 Link to this post

    To get a bit more targetted on what I am asking you.....

    If I have a TextBlock, for example:





    c = Pages.MMSPlugins_0.SilverlightApp.RadTileView1Radtileview.Find.ByText("Blarg!");




    and I want to be able to check the foreground color of the text in said TextBlock.
    How can I access that property?

    Your previous response:

    Hello Travis Acton,

    Using the Developer Edition you can craft and record a verification step that verifies the computed color matches a particular value. Follow these steps:

    Navigate to the page containing the text you want to verify the color of.
    Turn on highlighting.
    Hover over the text to be verified and wait for the blue nub to appear.
    Click on the blue nub to open the Element Menu.
    Click the Build Verification button. The Sentence Verification Builder will open.
    Create a verification like the one shown in the verifycolor.png screenshot. This screenshot is for verifying the foreground color is Blue. Your color will probably be different.
    Click OK to save the verification as a step to your test.
    Now you also mention about using a coded test. If you convert this verification step to code it will come out something like this:
    [CodedStep(@"Verify 'ColorAndBackground:Color' style 'Exact' '#0000FF' on 'Text2Span'")]
    public void IpsumLoremDolor_CodedStep()
        //Verify 'ColorAndBackground:Color' style 'Exact' '#0000FF' on 'Text2Span'
        Pages.LoremIpsumDolorSitAmet.Text2Span.AssertStyle().ColorAndBackground(ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts.HtmlStyleColorAndBackground.Color, "#0000FF", ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts.HtmlStyleType.Computed, ArtOfTest.Common.StringCompareType.Exact);
    the Telerik team

  2. Cody
    Cody avatar
    3354 posts

    Posted 24 Jun 2010 Link to this post

    Hello Travis Acton,

    Oh, this is for a Silverlight application. I apologize I did not know that. I (incorrectly) assumed you were working with a straight HTML page.

    Detecting the color of text in a Silverlight app is much more complicated because Silverlight supports the use of brush objects for painting text in simple or complex brush and color gradients. The text is drawn using a brush which is set via the "Foreground" property. Verifying color still can be done but requires resorting to custom code. If we assume the brush is a solid color brush we can get the brush and verify the color of the brush being used to paint the text block. Here is sample code to do this:

    [CodedStep(@"Verify textblock color is 255, 105, 72, 40", RequiresSilverlight = true)]
    public void SilverlightForegroundColor_CodedStep()
        Brush textblockBrush = (Brush)Pages.TelerikTreeViewFor.SilverlightApp.InstallerTextblock.GetProperty(new AutomationProperty("Foreground", typeof(Brush)));
        if (textblockBrush is SolidColorBrush)
            Color actualColor = ((SolidColorBrush)textblockBrush).Color;
            Assert.AreEqual<Byte>(255, actualColor.A, "Error: alpha color does not match expected.");
            Assert.AreEqual<Byte>(105, actualColor.B, "Error: red color does not match expected.");
            Assert.AreEqual<Byte>(72, actualColor.G, "Error: green color does not match expected.");
            Assert.AreEqual<Byte>(40, actualColor.R, "Error: blue color does not match expected.");
            // If it's not a SolidColorBrush what is it? How do we handle it?

    I've attached a complete sample test that runs against our Silverlight demo page to demonstrate this more completely.

    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top