Reputation: 7414
When building a Coded UI Map, I specify the application that needs to be launched as shown below.
When I run the following test, the Coded UI Test passes, having been able to locate the controls I'm specifying. In this case, it's a 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
. 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.
[TestInitialize]
public void Setup()
{
string appPath = ApplicationPath.GetApplicationPath();
var app = ApplicationUnderTest.Launch(appPath);
}
Does anyone know why this would be the case?
Upvotes: 0
Views: 811
Reputation: 2221
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. 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.
Upvotes: 1