简体   繁体   English

以编程方式启动时,编码的UI测试无法找到WPF控件

[英]Coded UI Test can not find WPF Controls when launched programatically

When building a Coded UI Map, I specify the application that needs to be launched as shown below. 构建编码的UI映射时,我指定需要启动的应用程序,如下所示。

编码的UI测试图

When I run the following test, the Coded UI Test passes, having been able to locate the controls I'm specifying. 当我运行以下测试时,编码UI测试通过,并且能够找到我指定的控件。 In this case, it's a ListViewItem . 在这种情况下,它是ListViewItem

[TestMethod]
public void UserOpensAnExistingDiary()
{
    this.UIMap.OpenExistingDiary();
}

public void OpenExistingDiary()
{
    #region Variable Declarations
    WpfListItem uIPenAppsLogicModelsDiListItem = this.UIPENWindow.UIDiariesGroup.UIItemList.UIDiaryGroup.UIPenAppsLogicModelsDiListItem;
    WpfWindow uIDiaryEditorWindow = this.UIDiaryEditorWindow;
    #endregion

    // Launch '%LOCALAPPDATA%\Pen\app-5.0.6018.18517\Pen.Apps.Desktop.exe'
    ApplicationUnderTest penAppsDesktopApplication = ApplicationUnderTest.Launch(this.OpenExistingDiaryParams.ExePath, this.OpenExistingDiaryParams.AlternateExePath);

    // Double-Click 'Pen.Apps.Logic.Models.DiaryModels.Diary' list item
    Mouse.DoubleClick(uIPenAppsLogicModelsDiListItem, new Point(76, 72));

    // Wait for 1 seconds for user delay between actions; Click 'Diary' window
    Playback.Wait(1000);
    Mouse.Click(uIDiaryEditorWindow, new Point(590, 25));
}

If I delete the Launch UI Action, and programmatically launch the app the test is unable to locate the ListViewItem . 如果我删除Launch UI操作,并以编程方式启动应用程序,则测试无法找到ListViewItem The only difference is my removing the Launch action, and adding the following code to my tests, so they're initialized with the window launched. 唯一的区别是我删除了Launch动作,并向我的测试中添加了以下代码,因此它们在启动窗口时进行了初始化。

[TestInitialize]
public void Setup()
{
    string appPath = ApplicationPath.GetApplicationPath();
    var app = ApplicationUnderTest.Launch(appPath);
}

Does anyone know why this would be the case? 有谁知道为什么会这样?

The examples you provided are confusing as to what works and what doesn't. 您提供的示例令人困惑,哪些有效,哪些无效。 Also, using the UI maps makes it extremely difficult to see what is going on. 而且,使用UI映射使查看正在发生的事情极其困难。 Please add one of the test methods that is failing and include the UI Map code for 请添加失败的一种测试方法,并包括用于

this.UIPENWindow.UIDiariesGroup.UIItemList.UIDiaryGroup.UIPenAppsLogicModelsDiListItem

My hunch would be that the application under test is not being used as a search limiting container in the failing case. 我的直觉是在失败的情况下,被测试的应用程序不会被用作搜索限制容器。

What I would do, is change to something like: 我要做的就是更改为:

[CodedUITest]
public class TestingClass
{
    WpfWindow containingWindow;
    [TestInitialize]
    public void Initialize()
    {
        this.containingWindow = ApplicationUnderTest.Launch(appPath);
    }

    [TestMethod]
    public void Test1()
    {
        WpfListItem toClick = new WpfListItem(this.containingWindow);
        // look in the UI map to see what it is doing for search properties
        // and take the simplest sub-set that makes sense
        toClick.SearchProperties.Add("AutomationId", "SomeId");

        Mouse.Click(toClick); // do not need point, typically

       /*

       //You may need to include more levels of searching,
       //but you can see what you need from the UI Map

       WpfTable table = new WpfTable(this.containingWindow);
       table.SearchProperties.Add("AutomationId", "myTableId");

       WpfListViewItem itemToClick = new WpfListViewItem(table);
       itemToClick.SearchProperties.Add("Name", "Some name");
       */
    }
}

The point here is that the list item is getting the launched window as it's container which seems to not be happening in your current case. 这里的要点是列表项正在作为容器启动,这在您当前的情况下似乎没有发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM