0

我正在为应用程序进行手动编码的编码 UI 测试。

该应用程序具有在 2 个窗口中运行的特定功能。单击按钮时,会出现一个新窗口,然后用户选择关闭该窗口,然后用户继续在主窗口上执行操作。

使用 Selenium,我将通过遍历所有窗口句柄并通过使用“ driver.SwitchTo().Window(handle) ”方法将我想要的页面的 URL 传递给它来进行切换。但是,对于 Coded UI,我还没有找到类似的解决方案。使用 Process 类,我可以做类似的事情:

Process[] myList = Process.GetProcessesByName("iexplore");
foreach (Process item in myList)
if (item.MainWindowTitle.Contains("Window Title"))
{
item.Kill();
}

问题是我正在测试的应用程序设计不佳,并且整个应用程序的所有窗口都具有相同的名称,因此它将无法工作。

有没有一种方法可以用来切换到编码 UI 上的不同窗口?或者最好的方法是什么?

4

2 回答 2

2

看看这个问题,它可能会有所帮助:Interacting with multiple instances of an application in Coded UI

您无需在 CUIT 中进行“切换”,每个窗口和控件都通过 UITestControl 对象访问。如果你想在另一个窗口上做一些事情,你可以为它创建一个新对象。如果您无法通过搜索属性区分两个窗口,您可以使用Instance属性或FindMatchingControls方法。

要捕获窗口创建事件,您可以使用 winhook。它为您提供创建的每个窗口的窗口句柄。使用它,您可以确定创建的窗口是否是您正在等待的窗口,然后使用UITestControlFactory.FromWindowHandle创建 UITestControl 以供 CUIT 交互。如果您为该窗口生成了一个类,您可以创建该类的一个实例并调用其CopyFrom方法将您从窗口句柄创建的控件传递给它。

于 2014-05-20T08:53:11.483 回答
1

我在用:

public static HtmlDocument WaitForPopup(string popupName, string text)
{
    BrowserWindow browser = new BrowserWindow();
    browser.SearchProperties.Add(BrowserWindow.PropertyNames.Name, popupName,
    PropertyExpressionOperator.Contains);

    browser.WindowTitles.Add(popupName);
    browser.WaitForControlExist();
    browser.WaitForControlReady();
    browser.SetFocus();

    HtmlDocument html = new HtmlDocument(browser);
    html.SearchProperties.Add(HtmlDocument.PropertyNames.InnerText, text,
    PropertyExpressionOperator.Contains);
    html.WaitForControlExist();
    html.WaitForControlReady();
    Playback.Wait(1000);

    return html;
}

只需调用 WaitForPopup("your window name", "some constant text in window") 并继续在那里进行测试。请注意,此方法将返回新窗口的 html,您可以进一步使用它。

于 2014-05-18T09:18:45.697 回答