C# 在编码UI中,如何获取属性并正确地使用它进行断言?

C# 在编码UI中,如何获取属性并正确地使用它进行断言?,c#,visual-studio,coded-ui-tests,C#,Visual Studio,Coded Ui Tests,在编码的Ui测试中,我希望使用以下代码验证应用程序中的消息: public void AssinarNewsletter() { //BrowserWindow.CurrentBrowser = "chrome"; BrowserWindow chrome = BrowserWindow.Launch("http://pp.psafe.com/"); chrome.Maximized = true; UITestContr

在编码的Ui测试中,我希望使用以下代码验证应用程序中的消息:

public void AssinarNewsletter()
    {
        //BrowserWindow.CurrentBrowser = "chrome";
        BrowserWindow chrome = BrowserWindow.Launch("http://pp.psafe.com/");
        chrome.Maximized = true;

        UITestControl uIEmail = new UITestControl(chrome);
        uIEmail.TechnologyName = "Web";
        uIEmail.SearchProperties.Add("ControlType", "Edit");
        uIEmail.SearchProperties.Add("Id", "mce-EMAIL");
        Keyboard.SendKeys(uIEmail, "andre.mendes@peseife.com.br");

        UITestControl uICadastrar = new UITestControl(chrome);
        uICadastrar.TechnologyName = "Web";
        uICadastrar.SearchProperties.Add("ControlType", "Button");
        uICadastrar.SearchProperties.Add("Id", "mc-embedded-subscribe");
        Mouse.Click(uICadastrar);

        UITestControl uICadastrado = new UITestControl(chrome);
        uICadastrado.TechnologyName = "Web";
        uICadastrado.SearchProperties.Add("ControlType", "Pane");
        uICadastrado.SearchProperties.Add("Id", "mce-success-response");

        string displayed = (string)uICadastrado.GetProperty("InnerText");
        string expected = "Quase no final... Precisaamos confirmar o seu endereço de e-mail. Para concluir o processo de assinatura, clique no link existente no e-mail que acabamos de enviar para você.";

        if (displayed != expected)
        {
            Assert.Fail("A mensagem está incorreta");
        }
但不知怎么的,我的测试在不应该通过的时候通过了

以下是应用程序中的消息:

添加延迟,例如

UITestControl uICadastrado = new UITestControl(chrome);
uICadastrado.WaitForControlReady(1000);//wait one second
输入断点,然后通过打开测试资源管理器在调试中运行测试,右键单击测试用例,然后单击在调试中运行

改变

if( displayed != expected )


比较时显示的
值是多少?此外,您是否确定故障条件是显示的<代码>和预期的<代码>具有相同的值?显示的值是“没有最终…没有电子邮件确认。没有辅助过程的结论,没有链接,没有电子邮件。”。我很确定他们不是,这就是为什么我想知道为什么考试通过了。我想我们两个中的一个很困惑。。。如果(显示==期望值)
,则您的情况为
;现在您的意思是显示的
和预期的
具有不同的值。由于它们具有不同的值,因此不满足该条件。也许你想做的是
if(display!=expected)
?我的目的是让测试失败,然后修复它使其通过。我从谷歌上的一个例子中得到了这个断言。也许我很困惑,因为我没有完全理解它。@Josh你是对的,我更新了我的帖子。但我的考试还是通过了。
if ( String.Equals(displayed , expected ) == false )
if ( ! String.Equals(displayed , expected ) )