4

I made a WPF app, and have made some automated tests using teststack.white. They have documentation on how they map controls in Windows to their framework but I don't see TextBlock there anywhere.

Their docs are here and here.

Thanks

pdschuller
  • 584
  • 6
  • 26

1 Answers1

4

Yes you are not mistaken, there's no mention of TextBlock there.

The thing is the TextBlock is just a longer Label in WPF, as you can read here:

A common understanding is that a Label is for short, one-line texts (but may include e.g. an image), while the TextBlock works very well for multiline strings as well, but can only contain text (strings).

So you can just get it as you would do with a Label:

Application application = Application.Launch(applicationPath);
Window window = application.GetWindows().First();

var MyTextBlock = window.Get<Label>("MyTextBlock");

This is the XAML markup I used to test it:

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        mc:Ignorable="d"
        Title="MainWindow" Height="103.966" Width="191.724">
    <Grid>
        <TextBlock x:Name="MyTextBlock" Text="Hello!" Background="CornflowerBlue" Foreground="White" VerticalAlignment="Top"/>

    </Grid>
</Window>
Francesco B.
  • 2,729
  • 4
  • 25
  • 37
  • 1
    Could you have a look at my question? https://stackoverflow.com/questions/53500604/teststack-how-to-find-custom-controls-and-invoke-methods-fire-events thanks – Dominic Jonas Nov 28 '18 at 12:33