8 Answers, 1 is accepted
- Perform an Extraction on the TextBlock.
- Access the Extracted Variable in code.
- Access the current time from the computer via the DateTime.Now Property.
- Convert them to strings and compare the two values.
You may need to trim one or both of the strings before comparing them using the String.Substring Method.
Alternatively you can navigate to a site that displays the current date, perform an extraction, and data bind that extraction variable to the verification on your site's TextBlock. The stipulation here is that they are in the same format, as the comparison is string-based.
Kind regards,
Anthony
the Telerik team
Test Studio Trainings
Extract - Verify text content matches '6/3/2005 12:00:00 AM'
Extract - element visibility is Collapsed
Extract - left side position is 215
Extract - top side position is 217
I decided to go with the option Extract - Verify text content matches '6/3/2005 12:00:00 AM'
I was able to convert the extracted value into a date.
The problem is that this test step fails when the date is not '6/3/2005 12:00:00 AM'. Likewise, the date does not get extracted.
From the log file:
'7/12/2012 4:30:12 PM' - 'Fail' : 1. Extract 'x632005Textblock' text into DataBindVariable $(x632005Textblock1)------------------------------------------------------------Failure Information: ~~~~~~~~~~~~~~~Unable to locate element. Details: Attempting to find [Silverlight] element using Find logic (Html): [tagname 'Exact' object] AND [type 'Contains' application/x-silverlight] (Silverlight): [TextContent 'StartsWith' 6/3/2005 12:00:] AND [XamlTag 'Exact' textblock]Unable to locate element. Search failed!
Do you have any suggestions?
Because the TextBlock has no unique attributes, like Automation ID, Test Studio chose to identify it by its TextContent. This will obviously fail when the TextContent changes.
You should edit the TextBlock's Find Settings so it is found using different logic. That way it will be located and the extraction can be performed no matter what its TextContent is.
If you choose not to implement an Automation ID and use that to locate the element, select an alternative from the Suggestions tab, like XamlPath or TagIndex. The drawback for those methods is that if the element changes position on the page, the Find Settings will need to be updated again.
Anthony
the Telerik team
Test Studio Trainings
This how my control looks in xaml.
<
sdk:Label
AutomationProperties.AutomationId
=
"lblTestDate"
Name
=
"txtTestDate"
Grid.Row
=
"2"
Margin
=
"5"
/>
In the Find Settings, I have the criteria "Name is exactly txtTestDate" (See Attached) This looks right. My suggestions tab is grayed out. Test Studio is giving a weard error in the log:
'7/13/2012 6:15:52 PM' - 'Fail' : 1. Extract 'x672005Textblock' text into DataBindVariable $(extractedDate)------------------------------------------------------------Failure Information: ~~~~~~~~~~~~~~~[Silverlight Extension Error] Details: ArtOfTest.WebAii.Silverlight.NoSuchPropertyException: Property 'Text' does not exist on the element at Telerik.TestingFramework.XamlExtension.ClientServices.GetRealProperty(AutomationReference reference, AutomationProperty property) at Telerik.TestingFramework.XamlExtension.ClientProcessor.ProcessCommand(String command)InnerException:ArtOfTest.WebAii.Silverlight.ExecuteSilverlightCommandException: [Silverlight Extension Error] Details: ArtOfTest.WebAii.Silverlight.NoSuchPropertyException: Property 'Text' does not exist on the element at Telerik.TestingFramework.XamlExtension.ClientServices.GetRealProperty(AutomationReference reference, AutomationProperty property)
Not sure what is wrong?
It seems you're now targeting the Label directly, instead of the child TextBlock (which actually contains the text to be extracted).
I suggest re-recording the step and targeting the second blue TextBlock nub (like in your ExtractOptions.png screen shot) to perform the Extraction on. Test Studio should add a new element to the Elements Explorer which targets the Label by Automation ID, and then the child TextBlock as a chained find expression.
Kind regards,
Anthony
the Telerik team
Test Studio Trainings
Thank you for the sample project. It was extremely helpful.
It seems the TextBlock is still being identified by its TextContent. See the following screen recording for instructions on how to change this:
http://screencast.com/t/ZZcy7iYrz
- Edit the friendly name of the TextBlock (optional).
- Edit its Find Settings.
- Now we have a chained find expression where the Label is found first by its AutomationID, then its underlying TextBlock. Here's how the expression should read when clicking the Advanced button:
- XamlTag=Label,AutomationId=lblTestDate,|,XamlTag=TextBlock
- Customize the DataBindVariableName for the Extract step.
- Log the extraction (optional) in a coded step:
- Log.WriteLine(GetExtractedValue("var1").ToString());
Greetings,
Anthony
the Telerik team
Test Studio Trainings
Hi Top Gun,
I solved the same problem after linking this site that reports today's date with various formats that we can use to perform an extract and link data from that extract variable to the check in TextBlock of any site.
Hope this helps, have a great week.