如何在编码 UI 中检查有效页面

How to check ValidPage in CodedUI

我正在使用代码优先方法而不是记录方法。我有登录页面,我正从该页面转到下一页,即主页。

 public HomePage SubmitClick(string userName, string Password)
        {
                HtmlEdit txtUsername = new HtmlEdit(_browserWindow);
                txtUsername.SearchProperties.Add(HtmlEdit.PropertyNames.Id, "txt_empid");
                txtUsername.Text = userName;


                HtmlEdit txtPassword = new HtmlEdit(_browserWindow);
                txtPassword.SearchProperties.Add(HtmlEdit.PropertyNames.Id, "txt_password");
                txtPassword.Text = Password;


            HtmlInputButton btnSubmit = new HtmlInputButton(_browserWindow);
            btnSubmit.SearchProperties.Add(HtmlInputButton.PropertyNames.Id, "btn_submit");
            Mouse.Click(btnSubmit);
            return new HomePage(_browserWindow);
        }

重定向工作正常。我的问题是如何识别打开的页面是否有效。 我计划检查一些控件,如 buttonhyperlinks,如果它们存在,则页面有效。有什么好的方法吗

比较下一个 Page.If 的 URL 是测试用例通过所需的 URL。

Uri url = BrowserwindowObj.Uri;

这给出了当前浏览器页面的URL。

首先给 _browserwindow.WaitForControlReady() 它会等到 browserwindow 完全加载页面。 页面加载后,使用 Assert 检查页面标题是否与预期相同。

_browserwindow.WaitForControlReady();
WinTabPage nextPage = new WinTabPage(_browserwindow);
Assert.AreEqual("Home Page", nextPage.Name);