Skip to content

Commit

Permalink
Do not cache top level menu, it needs to be rebuilt every time otherw…
Browse files Browse the repository at this point in the history
…ise an exception is thrown the next time you access the items
  • Loading branch information
Jake Ginnivan committed Jul 29, 2013
1 parent fe2a153 commit bf9144a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/TestStack.White.UITests/Scenarios/Win32Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using TestStack.White.UIItems.Finders;
using TestStack.White.UIItems.ListBoxItems;
using TestStack.White.UIItems.MenuItems;
using TestStack.White.UIItems.WindowStripControls;
using TestStack.White.WindowsAPI;
using Xunit;

Expand Down Expand Up @@ -64,6 +65,11 @@ public void CalculatorTests()
using (var application = Application.AttachOrLaunch(psi))
using (var mainWindow = application.GetWindow(SearchCriteria.ByText("Calculator"), InitializeOption.NoCache))
{
// Verify can click on menu twice
var menuBar = mainWindow.Get<MenuBar>(SearchCriteria.ByText("Application"));
menuBar.MenuItem("Edit", "Copy").Click();
menuBar.MenuItem("Edit", "Copy").Click();

mainWindow.Keyboard.HoldKey(KeyboardInput.SpecialKeys.CONTROL);
mainWindow.Keyboard.Enter("E");
mainWindow.Keyboard.LeaveKey(KeyboardInput.SpecialKeys.CONTROL);
Expand Down
2 changes: 0 additions & 2 deletions src/TestStack.White/UIItems/MenuItems/Menus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
using System.Threading;
using System.Windows.Automation;
using TestStack.White.AutomationElementSearch;
using TestStack.White.Configuration;
using TestStack.White.Factory;
using TestStack.White.UIItems.Actions;
using TestStack.White.UIItems.Finders;
using TestStack.White.Utility;

namespace TestStack.White.UIItems.MenuItems
{
Expand Down
8 changes: 3 additions & 5 deletions src/TestStack.White/UIItems/WindowStripControls/MenuBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,25 @@ namespace TestStack.White.UIItems.WindowStripControls
{
public class MenuBar : UIItem, MenuContainer
{
private readonly Menus topLevelMenu;
protected MenuBar() {}

public MenuBar(AutomationElement automationElement, ActionListener actionListener) : base(automationElement, actionListener)
{
topLevelMenu = new Menus(automationElement, actionListener);
}

public virtual Menu MenuItem(params string[] path)
{
return topLevelMenu.Find(path);
return TopLevelMenu.Find(path);
}

public virtual Menu MenuItemBy(params SearchCriteria[] path)
{
return topLevelMenu.Find(path);
return TopLevelMenu.Find(path);
}

public virtual Menus TopLevelMenu
{
get { return topLevelMenu; }
get { return new Menus(automationElement, actionListener); }
}
}
}

0 comments on commit bf9144a

Please sign in to comment.