pdschuller
pdschuller

Reputation: 584

how to grab a WPF TextBlock using teststack

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

Upvotes: 4

Views: 988

Answers (1)

Francesco B.
Francesco B.

Reputation: 3107

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>

Upvotes: 4

Related Questions