// retry count will be deprecating public static void ExpectMessageBoxWillPopUp(string title, string expContent, Action messageBoxTrigger, string buttonNameToClick = null, int retryCount = 5, int waitTime = 5000) { IntPtr msgBoxHandle = WindowWatcher.Push(title, messageBoxTrigger, waitTime); AssertMessageboxContent(msgBoxHandle, retryCount, expContent); CloseMessageBox(msgBoxHandle, buttonNameToClick); }
public static IMarshalWindow WaitAndPush <T>(this IWindowStackManager windowStackManager, Action action, string name, int timeout = 5000) where T : DispatcherObject { IntPtr handle = WindowWatcher.Push(name, action, timeout); IMarshalWindow window = windowStackManager.Push(handle); Assert.IsNotNull(window); Assert.IsTrue(window.IsType <T>()); Assert.IsTrue(name == null || name == window.Title); return(window); }
public static void ExpectMessageBoxWillNotPopUp(string title, string expContent, Action messageBoxTrigger, string buttonNameToClick = null, int retryCount = 5, int waitTime = 5000) { try { IntPtr msgBoxHandle = WindowWatcher.Push(title, messageBoxTrigger, waitTime); CloseMessageBox(msgBoxHandle, buttonNameToClick); } catch (AssertFailedException) { // discard error since it is reversed return; } Assert.Fail("Message box should not open."); }
private static void CloseMessageBox(IntPtr msgBoxHandle, string buttonName) { if (buttonName == null) { // Simple close message box NativeUtil.SetForegroundWindow(msgBoxHandle); NativeUtil.SendMessage(msgBoxHandle, 0x0112 /*WM_SYSCOMMAND*/, new IntPtr(0xF060 /*SC_CLOSE*/), IntPtr.Zero); } else { // This may be flaky.. if there're more than one windows pop up at the same time.. // it will affect clicking the button IntPtr btnHandle = NativeUtil.FindWindowEx(msgBoxHandle, IntPtr.Zero, "Button", buttonName); Assert.AreNotEqual(IntPtr.Zero, btnHandle, "Failed to find button in the messagebox."); NativeUtil.SetForegroundWindow(msgBoxHandle); NativeUtil.SendMessage(btnHandle, 0x0201 /*left button down*/, IntPtr.Zero, IntPtr.Zero); NativeUtil.SendMessage(btnHandle, 0x0202 /*left button up*/, IntPtr.Zero, IntPtr.Zero); } WindowWatcher.Pop(); }