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

Verify Data in A Label/Textbox

12 Answers 401 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 30 Nov 2012, 10:08 PM

I have a Silverlight application the outputs “Hello, World!!” when run.  I successfully wrote a test and used the “Quick verification” to verify the text “Hello, World!!” Success.  It worked.

 

The problem is, let’s say the application is recompiled to display “Hello, Telerik!!”  In Test Studio, I go to my test step and modify the value expected to be “Hello, Telerik!!”  I run the test.   The Silverlight application opens up with “Hello, Telerik!!”.  The problem is the test fails.

 

This is a simple example.  Throughout my application at work, I need to verify data in textboxes or labels where the values are dynamic.  Based on the environment/scenario that the application is run, the textbox will have a different value.  Therefore, I convert the verification step into a coded step.  In this case, Test Studio recognizes the label as
Pages.PracticeTextBox.SilverlightApp.HelloWorldTextblock.Text

 

The problem is that this label should not be called a HelloWorldTextBlock.  Since, it may not have the value Hello World all the time.  I need to be able to verify text and data dynamically.  Please help! Code Attached.

12 Answers, 1 is accepted

Sort by
0
Top Gun
Top achievements
Rank 1
answered on 30 Nov 2012, 11:36 PM
One more thing.  Here is the exception message that I am getting.

InnerException:ArtOfTest.Common.Exceptions.FindElementException: Element Not found!

Failure Information: ~~~~~~~~~~~~~~~Exception thrown executing coded step: '[WebTest4_CodedStep] : Verify 'HelloWorldTextblock' text Same 'Hello, Telerik!!', RequiresSilverlight=True'.InnerException:ArtOfTest.Common.Exceptions.FindElementException: Element Not found!FindExpression used: [TextContent 'Exact' Hello, World!!] AND [XamlTag 'Exact' textblock] at ArtOfTest.Common.WaitSync.CheckResult(WaitSync wait, String extraExceptionInfo, Object target) at ArtOfTest.Common.WaitSync.For[T](Predicate`1 predicate, T target, Boolean invertCondition, Int32 timeout, WaitResultType errorResultType) at ArtOfTest.WebAii.Silverlight.VisualWait.ForExistsInternal(Int32 timeout, Boolean invertCondition) at ArtOfTest.WebAii.Silverlight.VisualWait.ForVisible(Int32 timeout) at ArtOfTest.WebAii.TestTemplates.XamlElementContainer.Get(XamlFindExpression expr, Boolean waitOnElement, Int32 timeout) at ArtOfTest.WebAii.TestTemplates.XamlElementContainer.Get(XamlFindExpression expr) at ArtOfTest.WebAii.TestTemplates.XamlElementContainer.Get[TControl](XamlFindExpression expr) at ArtOfTest.WebAii.TestTemplates.XamlElementContainer.Get[TControl](String[] clauses) at TestProject1.Pages.PracticeTextBoxPage.SilverlightAppElement.get_HelloWorldTextblock() in c:\Test Studio Automation\Text1\TestProject1\Pages.g.cs:line 611 at TestProject1.WebTest4.WebTest4_CodedStep() in c:\Test Studio Automation\Text1\TestProject1\WebTest4.tstest.cs:line 79



0
Top Gun
Top achievements
Rank 1
answered on 03 Dec 2012, 07:56 PM

Based on the exception above, I believe Test Studio could not find the control.  So I edited the control, and configured Test Studio to find the control by its Name tag "lblResultEntered."  Then I ran my test.  The problem was that Test Studio gave an error message stating the Text is not a property on a label.  How do I get Test Studio to correctly recognize the control as a label and not a textblock? 

0
Plamen
Telerik team
answered on 04 Dec 2012, 09:27 PM
Hello Top Gun,

The Friendly Name of the element is not used when actually finding the element. It is just a label to keep the Elements Explorer organized. An element is truly defined by its Find Settings. In order to make this to work you need to remove the TextContent from the Find Settings for that element and use other properties that are static(they will not change next time you're changing the app). Please see this video on how to resolve this and let me know if I can assist you further.

Regards,
Plamen
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 Dec 2012, 07:13 PM
I am still having trouble.  I update the xaml view.  See below.
<Grid x:Name="LayoutRoot" HorizontalAlignment="Center" Height="100" Width="185">
      <StackPanel Orientation="Vertical">
          <Border Style="{StaticResource GridCellDataStyle}">
              <dataInput:Label Name="FirstName" Content="John" HorizontalAlignment="Stretch" FontSize="15" />
          </Border>
          <Border Style="{StaticResource GridCellDataStyle}">
              <dataInput:Label Name="LastName" Content="Doe" HorizontalAlignment="Stretch" FontSize="15" />
          </Border>
          <Border Style="{StaticResource GridCellDataStyle}">
              <dataInput:Label Name="lblResultEntered" Content="{Binding Path=UserName}" HorizontalAlignment="Stretch" FontSize="15" />
          </Border>
      </StackPanel>       
  </Grid>

1.  Record Test.
2. Navigate to http://localhost:17879/PracticeTextBoxTestPage.aspx
3. Ran Quick Verification.  Text matches "Hello, World!"
4. Edit Element.
5. Find Without Connection.
6. In Find Settings, I deleted to criteria "Text Content is exactly Hello, World!!"
7. The only criteria was "XamlTag is exactly textblock"

Ran my test.  Step 2 failed.  See log file below.
'12/12/2012 1:02:13 PM' - 'Fail' : 2. Verify 'HelloWorldTextblock' text Same 'Hello, World!!'
------------------------------------------------------------
Failure Information: 
~~~~~~~~~~~~~~~
Property did not satisfy constraint (John Same Hello, World!!)

I do not understand why criteria "XamlTag is exactly textblock" is used.  The control is a label.

Attached is the test used.
0
Plamen
Telerik team
answered on 14 Dec 2012, 12:14 AM
Hello Top Gun,

The problem is that the Label control in Silverlight has a build-in TextBlock and looking the code you are using, you have three separate TextBlock controls now. To verify that you can open the DOM explorer. The first one contains text "John", the second one "Doe" and the text you are trying to verify("Hello, World!!") is contained in the third TextBlock.

When you are using only the "XamlTag is exactly textblock" criteria, Test Studio will find the first text block available in the Visual Tree(the one with text "John"). In order to find the third TextBlock you need to add a second criteria that is specific for the TextBlock you are looking for. For example you can use TagIndex or XamlPath.

All the best,
Plamen
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 14 Jan 2013, 11:31 PM

First, the pop up where you specify how Test Studio will locate a control, I will refer to as the "Find Element Window."

On this pop up, “Find Element Window”,  you said the following:

When you are using only the "XamlTag is exactly textblock" criteria, Test Studio will find the first text block available in the Visual Tree(the one with text "John"). In order to find the third TextBlock you need to add a second criteria that is specific for the TextBlock you are looking for. For example you can use TagIndex or XamlPath.

On the left side of the “Find Element Window”, there is a suggestions tab.  This tab has the properties you are referring too: TagIndex and XamlPath.  Thus, the properties have values to look for.  However, the suggested values are for a different textbox.  How would the user/ tester know what values the correct control should have?

Note the XamlPath is based on an automationId.  Again, the test user would probably need to look at the xaml of the Silverlight application to know the automationId, or name property of the control.

On the left side of the “Find Element Window”, is also a DOM tab.  This tab allows the test user to find the control.  However, with a complex page, it will be difficult unless you can search for the control based on the automationId or name property.  But, in order to do this, the tester would need access to the Silverlight xaml.  Once you find the control in the DOM, you can right click and select replace element and the find criteria seems to be correctly set.

Are you recommending that the person writing the Test Studio automation script also have access to the Silverlight xaml?  (It seems like the only way to know the name of the controls.)  Our application is complex with many views and it may be difficult for a tester to read and navigate throughout the solution.

Using the “Find Element Window” so far has been extremely frustrating and troublesome.  My find criteria that works looks like the following:

AutomationId is exactly lblResultEntered

XamlTag is exactly label


Then I save the find criteria, and customize the test step in code.
Assert.IsTrue(Pages.PracticeTextBox.SilverlightApp.HelloAmritTextblock0.Text == "Hello, Telerik!!");


One effective way to do the validation, is to just create a coded step or customize the step in code and write something like the following:

FrameworkElement myElement  = Pages.PracticeTextBox.SilverlightApp.Find.ByExpression(new XamlFindExpression("Name=lblResultEntered"));
Assert.IsTrue(myElement.Text == "Hello, Telerik!!");

The only problem with Find.ByName or Find.ByExpression is that the tester would need to know the Name property or the AutomationId of the control.  What is the best approach for doing this?  Should the entire Silverlight solution be given to the tester in order to determine the name properties?  Is there a better way?


0
Plamen
Telerik team
answered on 16 Jan 2013, 04:49 PM
Hello Top Gun,

It is not necessary to give the Silverlight solution to your testers. All attributes including the AutomationId and the Name of the element are available in the Silverlight Visual Tree. All you need to do is to find the correct element in the Test Studio's DOM explorer. You can do that during recording by enabling the Hover Over Highlighting from the Recording Toolbar, pointing the mouse to that element and pressing the blue nub. This will open the Elements Menu and from there you can click on the "Locate In DOM" button. Test Studio will navigate to the DOM Explorer and select the corresponding element. Now in the DOM Explorer you should be able to see all attributes for the selected element. Here's a short video demonstrating the process.

If the suggested values in the “Find Element Window” are for different element, this means that the current Find Settings are incorrect or you need to add one more rule in the find logic that is unique for the element you are looking for. For example, here is a short video demonstrating how to replace two GridViewCells by changing the AutomationId. 

Regards,
Plamen
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 Jan 2013, 07:46 PM
Hi Plamen,

Thanks for the reply.  Unfortunetly I can not view your video at  work.  It gets blocked.  I will watch when I get home.  I found the control like you said in the DOM explorer.  The Name property is not there.  It is specified in the xaml for the Silverlight code.  However, the DOM explorer does not show it.  Maybe I am missing something.  So I will watch your video later to be sure. I have attached pictures so you can see what I am describing. Thanks for the reply.

Amrit
0
Plamen
Telerik team
answered on 17 Jan 2013, 02:25 PM
Hi Top Gun,

In your case, these properties are attached to the Label control, not to the build-in TextBlock control(see screenshot). The code you are using:
 
FrameworkElement myElement  = Pages.PracticeTextBox.SilverlightApp.Find.ByExpression(new XamlFindExpression("Name=lblResultEntered"));
 
Assert.IsTrue(myElement.Text == "Hello, Telerik!!");
returns the Label control as a Framework element and than you are checking the text of that Label, which is actually the text contained in the build-in TextBlock.

All the best,
Plamen
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 17 Jan 2013, 10:36 PM
I watched the video.  I located the element in the Dom Explorer like you did in the video.  However, in my case there is not an AutomationId or Name property available.  In your video, it works.  But not for my label/TextBlock.  Please view attached picture.   Is this a bug?  I do not think I did anything wrong.  Please let me know if you have any other ideas.
0
Plamen
Telerik team
answered on 18 Jan 2013, 11:47 AM
Hello Top Gun,

It seems you didn't read my previous response. Please read it, see the provided screenshot and let me know if you have further questions. 

Regards,
Plamen
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 18 Jan 2013, 07:31 PM

My apologies.  I looked at your attachment and I see what you are saying.  I appreciate all your help.  Thank you.


Amrit
Tags
General Discussions
Asked by
Top Gun
Top achievements
Rank 1
Answers by
Top Gun
Top achievements
Rank 1
Plamen
Telerik team
Share this question
or