如何在TestStack.White中获取文本框背景色

时间:2019-02-22 06:01:53

标签: c# .net wpf window white

我正在使用TestStack.White对WPF代码进行自动化测试。我正在尝试获取文本框之一的背景色。我尝试使用NativeWindow来获取背景颜色,但它没有给我正确的颜色代码。我的代码有什么问题吗?还是有其他方法可以做到这一点?

Application application = null;             Window window = null;             应用=                 应用程序启动(                     @“ C:\ New文件夹\ WPFTRaining \ Automation.TimelineUI \ Automation.TimelineUI \ bin \ Debug \ Automation.TimelineUI.exe”);

        var windows = application.GetWindows();
        window = windows.Find(x => x.Id == "Form1");


        TextBox age = window.Get<TextBox>(SearchCriteria.ByAutomationId("TextBoxAGE"));
        age.Enter("90");

        Button saveButton = window.Get<Button>("SaveButton");
        saveButton.Click();
        Thread.Sleep(5000);

        var nativeWindow = new NativeWindow(new IntPtr(window.Get<TextBox>("TextBoxAGE").AutomationElement.Current.NativeWindowHandle));
        Assert.AreEqual(nativeWindow.BackgroundColor,"#FF0000");                 

0 个答案:

没有答案