public static void SwitchBackToParent(this IPopup popup, WaitForPopupToClose waitForClose = WaitForPopupToClose.No) { PopUpWindow.SwitchTo(ParentWindowTitles[popup]); if (waitForClose == WaitForPopupToClose.Yes) { Wait.Until(d => !popup.IsDisplayed()); } }
public static void SwitchTo(this IPopup popup, bool partialMatch = false) { ParentWindowTitles[popup] = Web.PortalDriver.Title; if (partialMatch) { PopUpWindow.SwitchTo(popup.Title, true); } else { PopUpWindow.SwitchTo(popup.Title); } }
// This method should be used whenever init is called or an interaction with an element is required. // It will focus on the top most window. public static void FocusTopWindow() { // get currentWindowHandles, put it in a temporary hashset var currentHandles = Web.PortalDriver.WindowHandles; try { foreach (string handle in currentHandles) { currentHandleSet.Add(handle); } if (currentHandleSet.Count == BaseHandleSet.Count) { // do nothing return; } // if (currentHandles > baseSet) (there is a new window or popup) // diff the two sets for one handle // if more than one handle is different, throw an exception? Not sure which to focus window on // add the handle to focus stack if (currentHandleSet.Count > BaseHandleSet.Count) { // BUG -- do not manipulate SETS after diffing currentHandleSet.ExceptWith(BaseHandleSet); if (currentHandleSet.Count > 1) { // THROW EXCEPTION -- SHOULD NOT be more than one handle difference } string diffHandle = currentHandleSet.FirstOrDefault(); PopUpWindow.SwitchToByHandle(diffHandle); WindowFocusStack.Push(diffHandle); GetLatestWindowHandles(); return; } // if (currentHandles < baseSet) (there are fewer windows or popup) // diff the two sets for one handle // if more than one handle is different, throw an exception? Not sure which to focus window on if (currentHandleSet.Count < BaseHandleSet.Count) { // BUG -- do not manipulate SETS after diffing BaseHandleSet.ExceptWith(currentHandleSet); string handleToRemove = WindowFocusStack.Pop(); //BaseHandleSet.Remove(handleToRemove); // verify that the window being removed, is the one that was different between two sets //string diffHandle = BaseHandleSet.FirstOrDefault(); if (!BaseHandleSet.Contains(handleToRemove)) { // THROW EXCEPTION } PopUpWindow.SwitchToByHandle(WindowFocusStack.Peek()); GetLatestWindowHandles(); //return; } } catch (Exception e) { Trace.WriteLine(e.Message); } // other notes: clear the currentWindowHandles and focusStack before starting up // determine if the size of the two sets are equal // if equal, do nothing and set the focus on the one window handle // if (currentHandles > baseSet) // diff the two sets for one handle // if more than one handle is different, throw an exception? Not sure which to focus window on // add the handle to focus stack // if (currentHandles < baseSet) // diff the two sets for one handle // if more than one handle is different, throw an exception? Not sure which to focus window on // Finally, set the basehandles }
public static Boolean IsDisplayed(this IPopup popup) { return(PopUpWindow.IsOpen(popup.Title)); }