【问题标题】:How can I verify text in ControlType.Text in C# + TestStack.White?如何在 C# + TestStack.White 中验证 ControlType.Text 中的文本?
【发布时间】:2016-09-20 10:22:54
【问题描述】:

如何使用 C# + TestStack.White 验证 ControlType.Text 中的文本? 我只是想验证错误消息是否正确并且包含正确的短语。

我尝试了不同的解决方案:

  1. 文本框错误TextBox = MainWindow.Get("txbError"); Assert.AreEqual("用户名或密码无效", errorTextBox.Text);

  2. TextBox errorTextBox = MainWindow.Get(SearchCriteria.ByText("用户名或密码无效")); Assert.AreEqual(errorTextBox.Text, "用户名或密码无效");

还有其他...

VS中总是出现错误:

TestStack.White.AutomationException: 获取 ControlType=edit 失败,Name=用户名或密码无效

Screenshot

【问题讨论】:

    标签: c# testing automation white-framework


    【解决方案1】:
    //Your login logic
    ...
    var textBoxes = mainWindow.GetMultiple(SearchCriteria.ByControlType(ControlType.Text));
    foreach(Label textBox in textBoxes)
    {
     if(textBox.Id.Contains("txbError"))
     {
      var actualError = textBox.Name.ToString();
      Assert.AreEqual(actualError, "Expected Error message");
     }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-20
      • 1970-01-01
      • 2015-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-08
      相关资源
      最近更新 更多