Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#Teststack.White:有时找不到按钮_C#_Wpf_Ui Testing_White Framework_Teststack - Fatal编程技术网

C#Teststack.White:有时找不到按钮

C#Teststack.White:有时找不到按钮,c#,wpf,ui-testing,white-framework,teststack,C#,Wpf,Ui Testing,White Framework,Teststack,我有一个WPF应用程序,只有一个窗口。在那个窗口中,我有几个堆叠面板和几个按钮。怀特可以完美地找到每个按钮,但对于完全相同的代码,只有一个按钮很少找到,而且常常找不到。我无法找出这种行为的原因。这就是我来找你们的原因 注意:在显示按钮之前,还有另一个视图(在同一窗口中)等待服务器响应。响应一出现,按钮就会显示出来 下面是我的测试代码: [TestMethod] public void ClickBarPayment_ViewExchanges() { DelayedStart(5);

我有一个WPF应用程序,只有一个窗口。在那个窗口中,我有几个堆叠面板和几个按钮。怀特可以完美地找到每个按钮,但对于完全相同的代码,只有一个按钮很少找到,而且常常找不到。我无法找出这种行为的原因。这就是我来找你们的原因

注意:在显示按钮之前,还有另一个视图(在同一窗口中)等待服务器响应。响应一出现,按钮就会显示出来

下面是我的测试代码:

[TestMethod]
public void ClickBarPayment_ViewExchanges()
{
    DelayedStart(5);
    Application app = null;
    try
    {
        app = Application.Launch(SutPath);
        try
        {
            var window = app.GetWindow("CfeMain");
            var button = (Button)window.Get(SearchCriteria.ByAutomationId("CashButton"), TimeSpan.FromSeconds(60));
            button.Click();
            Assert.AreEqual(false, button.Visible);
        }
        catch (Exception e)
        {
            Assert.Fail(e.Message);
        }
    }
    finally
    {
        app?.Close();
    }
}
您可以假设所有按钮都相等,并且都有一个标记“Name=”“”。这是XAML代码,我用“Blabla”a.s.o删除了不必要的名称


布拉
...
...
布拉
布拉

在不实际面对问题的情况下,我只能提出建议

潜在原因可能是窗口对象在实际应用程序窗口中启用所有按钮之前被初始化

您可以在初始化窗口之前添加等待时间

<StackPanel Name="PaymentContent"  Visibility="Visible" VerticalAlignment="Center"  Margin="0,0,0,0">
        <StackPanel Height="60"  VerticalAlignment="top" Margin="20,0,10,0">
            <TextBlock FontSize="24" Foreground="#0b0b0b" Name="info" HorizontalAlignment="Stretch">Bla</TextBlock>
        </StackPanel>

        <StackPanel Name="options" Orientation="Vertical" HorizontalAlignment="Center" Grid.RowSpan="2" Width="1004">

            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="5,15,5,0">
                ...
                ...
            </StackPanel>

            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="5,0,5,5">

                <Button Name="Blablabla" Click="Blablabl_OnClick" Style="{StaticResource MainButtonBottomLeft}" Background="#efefef" Margin="0,10,10,0" HorizontalAlignment="Center" Width="490" Height="200">
                    <StackPanel Orientation="Vertical" HorizontalAlignment="Left" Width="400" Height="200">
                        <TextBlock FontSize="28" Height="40" Margin="0,10,0,0" Name="BlablaText">Bla</TextBlock>
                        <TextBlock FontSize="18" Height="30" Name="BlablaInfo"/>
                        <Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" Background="#859fcd" Margin="0,10,0,0" Width="460" />
                        <StackPanel Name="BlablablIssuer" Height="100" Orientation="Horizontal">
                            <Image Source="/Images/Blasdsd.png" Width="95" Height="35" />
                        </StackPanel>
                    </StackPanel>
                </Button>

                <Button Name="CashButton" Click="Cash_OnClick" Style="{StaticResource MainButtonBottomRight}" Background="#efefef"  Margin="0,10,0,0" HorizontalAlignment="Center" Width="490" Height="200">
                    <StackPanel Orientation="Vertical" HorizontalAlignment="Left" Width="400" Height="200">
                        <TextBlock FontSize="28" Height="40" Margin="0,10,0,0" Name="NoteText">Bla</TextBlock>
                        <TextBlock FontSize="18" Height="30" Name="NoteInfo"><Run Text="Schweizer Franken Banknoten"/></TextBlock>
                        <Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" Background="#859fcd" Margin="0,10,0,0" Width="460" />
                        <StackPanel Name="noteIssuer" Height="100" Orientation="Horizontal">
                            <Image Source="/Images/100frank.jpg" Width="85" Height="55" Margin="0,0,5,0"/>
                            <Image Source="/Images/50frank.jpg" Width="80" Height="55" Margin="0,0,5,0" />
                            <Image Source="/Images/20frank.jpg" Width="80" Height="55" Margin="0,0,5,0" />
                            <Image Source="/Images/10frank.jpg" Width="75" Height="55" Margin="0,0,0,0" />
                            <Image Source="/Images/qrCode.png" Width="51" Height="45" Margin="0,28" />
                        </StackPanel>
                    </StackPanel>
                </Button>

            </StackPanel>

        </StackPanel>
    </StackPanel>