public void CustomCommandsAdded() { using (var app = new VisualStudioApp()) { PythonProjectNode node; EnvDTE.Project proj; OpenProject(app, "Commands1.sln", out node, out proj); AssertUtil.ContainsExactly( node._customCommands.Select(cc => cc.DisplayLabel), "Test Command 1", "Test Command 2" ); app.OpenSolutionExplorer().FindItem("Solution 'Commands1' (1 project)", "Commands1").Select(); var menuBar = app.FindByAutomationId("MenuBar").AsWrapper(); Assert.IsNotNull(menuBar, "Unable to find menu bar"); var projectMenu = menuBar.FindByName("Project").AsWrapper(); Assert.IsNotNull(projectMenu, "Unable to find Project menu"); projectMenu.Element.EnsureExpanded(); try { foreach (var name in node._customCommands.Select(cc => cc.DisplayLabelWithoutAccessKeys)) { Assert.IsNotNull(projectMenu.FindByName(name), name + " not found"); } } finally { try { // Try really really hard to collapse and deselect the // Project menu, since VS will keep it selected and it // may not come back for some reason... projectMenu.Element.Collapse(); Keyboard.PressAndRelease(System.Windows.Input.Key.Escape); Keyboard.PressAndRelease(System.Windows.Input.Key.Escape); } catch { // ...but don't try so hard that we fail if we can't // simulate keypresses. } } } }