This is a migrated thread and some comments may be shown as answers.

How do I verify that a text block is underlined?

4 Answers 71 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Shashi
Top achievements
Rank 1
Shashi asked on 07 Apr 2014, 09:31 PM
Is there a way to verify that a Silverlight text block is underlined? 

I have looked at the Quick Commands menu as well as the Build Verification dialog - the latter has several commands for Fonts but not one for underline.

I also looked at the solution for verifying text color in the following thread (that uses AutomationProperty to get color).  I thought I could use a similar technique for underline.   However, I wasn't sure if there was another Automation property for underline.

http://www.telerik.com/forums/foreground-colors-server-error-on-other-thread

Any help would be much appreciated.  Please note the version of Test Studio I am using in my signature.  Also, please note that I need a solution that will work on text that appears on a Telerik RichTextBox control.

Thanks,
Shashi
Test Studio 2012.2.1420.0 (Visual Studio add-in)

4 Answers, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 10 Apr 2014, 08:22 PM
Hello Shashi,

Underlining is done using a TextBlock.TextDecorations Property. Maybe we can get that as an automation property, but I'm not sure (I haven't tried it yet).

Before we venture down that path, may i ask why do you want to do this? Generally this type of testing is what we call "look and feel" testing of the application, something we admit is usually better done by hand and with the human eye i.e. our normal recommendation is to avoid testing things like color, underlining and so forth.

Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Shashi
Top achievements
Rank 1
answered on 11 Apr 2014, 10:10 PM
Hi Cody,

To answer your question:  while I would normally agree with you, there are certain special requirements of the test that I am writing for which this functionality is needed (if it is possible).

I researched the TextDecorations property that you referred to and tried to write code to get to it - I made some progress but haven't been successful in getting what I need.  Here is where I am right now:

a) From MSDN documentation, it looks like the TextDecorations class has properties to get/set underline, overline, etc. 
b) However, TextBlock.TextDecorations does not return an instance of that class - instead it returns a TextDecorationsCollection object which contains a collection of TextDecorations objects.  Does this mean that there is one TextDecorations object per decoration - i.e. one for underline (if text is underlined), one for overline (if text is overlined), etc?

c) I wrote code in my test to try and get the TextDecorationsCollection object from the TextDecorations property - but was unsuccessful (an exception was thrown during the call).  Code and exception are shown below.
TextDecorationCollection TBTextDecorations = (TextDecorationCollection)Pages.xxxxx.SilverlightApp.Textblock.GetProperty(new AutomationProperty("TextDecorations", typeof(TextDecorationCollection)));


InnerException:System.InvalidCastException: Invalid cast from 'System.String' to 'System.Windows.TextDecorationCollection'. at System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider) at System.String.System.IConvertible.ToType(Type type, IFormatProvider provider) at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) at System.Convert.ChangeType(Object value, Type conversionType) at ArtOfTest.WebAii.Silverlight.SilverlightProxy.ObjectFromString(String objAsString, Boolean isAutomationPeer, Type objType) at ArtOfTest.WebAii.Silverlight.SilverlightProxy.GetProperty(AutomationProperty property, IAutomationPeer peer) at ArtOfTest.WebAii.Silverlight.AutomationObject`1.GetProperty(AutomationProperty property)

d) The above statement did work if I saved the result into a string (instead of TextDecorationsCollection).  Value of the string was "System.Windows.TextDecorationCollection".
e) I was also able to list the contents of the Textblock's Properties collection (using the GetProperties method) - it did contain a key  for TextDecorations with value same as above ("System.Windows.TextDecorationCollection").
Dictionary<string, string> TBProperties = Pages.xxx.SilverlightApp.Textblock.GetProperties();
string value;
foreach (string key in TBProperties.Keys)
{
    TBProperties.TryGetValue(key, out value);
    Log.WriteLine(String.Format("{0} -> {1}", key, value));
}


f) I also noticed that the ArtOfTest version of Textblock does not have a property or method to get TextDecorations (at least in the version I am using) - whereas it is listed as a property in the Silverlight TextBlock class.  I am wondering if this is the cause of all the issues above.  If it is, is there a way to get to the Silverlight Textblock object from the ArtofTest Silverlight object? 

I will continue to research this for a little while longer - but I would appreciate any help you can provide regarding the above. 

To reiterate, I will need a solution that works in my version of TestStudio (which is a few releases behind the latest version - see my signature). 

Thanks,
Shashi 
Test Studio 2012.2.1420.0 (using the VS addin in VS2012).
0
Cody
Telerik team
answered on 16 Apr 2014, 08:18 PM
Hi Shashi,

I am sorry to say we have concluded that currently it's impossible. I've added a feature request to add this ability.

Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Shashi
Top achievements
Rank 1
answered on 16 Apr 2014, 09:07 PM
Hi Cody,

Thanks for looking into it and logging the feature request.  I have voted for it and added a comment.

Shashi
Tags
General Discussions
Asked by
Shashi
Top achievements
Rank 1
Answers by
Cody
Telerik team
Shashi
Top achievements
Rank 1
Share this question
or