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

Date Verification

8 Answers 327 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Top Gun
Top achievements
Rank 1
Top Gun asked on 09 Jul 2012, 11:28 PM
I am recording automated tests on a Silverlight 4 application.  I am able to easily select a control and verify text on the control.  However, one of my textblocks has a date.  I need to verify that the date is current.  How would I do this?  The build verfication and Quick Tasks options on the recorder seem to only work on text values.  I tried to Re Code Test Studio's Build Verification step, but I am having no luck.  Please let me know if you have any ideas about how to verify a date in Silverlight.

8 Answers, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 10 Jul 2012, 01:23 PM
Hello Top Gun,

  1. Perform an Extraction on the TextBlock.
  2. Access the Extracted Variable in code.
  3. Access the current time from the computer via the DateTime.Now Property.
  4. 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
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Top Gun
Top achievements
Rank 1
answered on 12 Jul 2012, 09:36 PM
I was actually using a Silverlight label.  I highlight the contents on the label and choose Quick Task.  The only extraction methods available are:
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?


0
Anthony
Telerik team
answered on 13 Jul 2012, 02:07 PM
Hello Top Gun,

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.

Kind regards,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Top Gun
Top achievements
Rank 1
answered on 13 Jul 2012, 11:33 PM
I think I see what you are saying.

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?


0
Anthony
Telerik team
answered on 16 Jul 2012, 03:18 PM
Hello Top Gun,

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
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Top Gun
Top achievements
Rank 1
answered on 16 Jul 2012, 08:48 PM
I extracted the value from the "second blue TextBlock nub" like you said.  See Attached "Extract Value"  It is still not working.  Not sure what else to do.  Application Code attached as "DateTestIssue"  Maybe you have another idea.
0
Anthony
Telerik team
answered on 17 Jul 2012, 02:14 PM
Hello Top Gun,

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

  1. Edit the friendly name of the TextBlock (optional).
  2. Edit its Find Settings.
  3. 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
  4. Customize the DataBindVariableName for the Extract step.
  5. Log the extraction (optional) in a coded step:
    • Log.WriteLine(GetExtractedValue("var1").ToString());

Greetings,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Girl
Top achievements
Rank 1
Iron
answered on 29 Jun 2022, 07:48 AM

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.

Tags
General Discussions
Asked by
Top Gun
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Top Gun
Top achievements
Rank 1
Girl
Top achievements
Rank 1
Iron
Share this question
or