public void ClickJSDialogOnBeforeUnloadRecoverFromCommunicationLossTest(JScriptDialogButtonType jsBtnType, string expectedWebPage)
 {
     try
     {
         _browser.NavigateBrowser(getTestPage("OnBeforeUnload.htm"));
         _browser.NavigateBrowser(getTestPage("TestPage.htm"));
         _browser.ClickJSDialog(jsBtnType);
         _browser.NavigateBrowser(getTestPage("OnBeforeUnload.htm"));
         //_browser.NavigateBrowser(getTestPage("TestPage.htm"));
         _browser.ClickJSDialog(jsBtnType);
         _browser.AssertBrowserExists(expectedWebPage);
     }
     finally
     {
         // Clean up
         _browser.KillAllOpenBrowsers();
         OpenSwatTestPage();
     }
 }
 private void RecoverFromDialog(JScriptDialogButtonType buttonType)
 {
     if (buttonType == JScriptDialogButtonType.Ok)
     {
         WaitForBrowserWindow();
     }
     else
     {
         lastBrowserWindowAction = LastBrowserWindowAction.InUse;
     }
 }
        private bool InteractWithJSDialog(JScriptDialogButtonType buttonType, IntPtr dialogHandle)
        {
            IntPtr buttonHandle = IntPtr.Zero;
            DateTime timeout = DateTime.Now.AddSeconds(10);
            bool clicked = false;
            string buttonText = (buttonType == JScriptDialogButtonType.Ok) ? "OK" : "Cancel";

            while (DateTime.Now < timeout)
            {
                buttonHandle = NativeMethods.FindWindowEx(dialogHandle, IntPtr.Zero, "Button", buttonText);

                if (buttonHandle == IntPtr.Zero)
                {
                    buttonText = (buttonType == JScriptDialogButtonType.Ok) ? "&Leave this Page" : "&Stay on this Page";
                    buttonHandle = NativeMethods.FindWindowEx(dialogHandle, IntPtr.Zero, "DirectUIHWND", "");
                    List<IntPtr> childWindows = NativeMethods.GetWindowChildren(buttonHandle);

                    foreach (IntPtr childHandle in childWindows)
                    {
                        buttonHandle = NativeMethods.FindWindowEx(childHandle, IntPtr.Zero, "Button", buttonText);

                        if (buttonHandle != IntPtr.Zero)
                            break;
                    }
                }

                if (!clicked && buttonHandle != IntPtr.Zero)
                {
                    clicked = ClickDialogButton(buttonHandle);
                }
                else if (clicked && buttonHandle == IntPtr.Zero)
                {
                    return true;
                }
            }

            return false;
        }
        public void ClickJSDialog(JScriptDialogButtonType buttonType)
        {
            bool dialogClicked = false;

            isBrowserDocumentHTML();

            IntPtr dialogHwnd = GetJSDialogHandle(15);

            if (dialogHwnd != IntPtr.Zero)
            {
                dialogClicked = InteractWithJSDialog(buttonType, dialogHwnd);
            }

            RecoverFromDialog(buttonType);

            if (!dialogClicked)
                throw new ClickJSDialogException();
        }
        public void ClickJSDialog(JScriptDialogButtonType buttonType)
        {
            bool dialogClicked = false;

            DateTime timeout = DateTime.Now.AddSeconds(15);
            IntPtr dialogHandle = FindDialog(timeout);

            if (dialogHandle != IntPtr.Zero)
            {
                dialogClicked = InteractWithJSDialog(buttonType, dialogHandle, timeout);
            }

            if (DialogInterrupted)
            {
                chromeHttpServer.HandleResponse(new ChromeCommand("ClickJSDialog"));
            }

            RecoverFromDialog(buttonType);

            if (!dialogClicked)
            {
                throw new ClickJSDialogException();
            }

            PreviousRequest = "ClickJSDialog";
            WaitForDialogToClose(dialogHandle);
            if (FindDialog(DateTime.Now.AddMilliseconds(100)) == IntPtr.Zero)
                HandleSWATTabs();
        }
 public void ClickJSDialog(JScriptDialogButtonType button)
 {
     _browser.ClickJSDialog(button);
 }
        public void ClickJSDialog(JScriptDialogButtonType buttonType)
        {
            bool dialogClicked = false;

            DateTime timeout = DateTime.Now.AddSeconds(30);
            IntPtr dialogHandle = FindDialog(timeout);
            IntPtr buttonHandle = FindButton(dialogHandle, timeout);

            if (dialogHandle != IntPtr.Zero)
            {
                while (!dialogClicked && DateTime.Now < timeout)
                {
                    InteractWithJSDialog(buttonType, dialogHandle, buttonHandle);
                    Thread.Sleep(5);
                    dialogClicked = !IsJSDialogOpen(dialogHandle);
                }
            }
            _lastWasConfirmDialog = false;

            RecoverFromDialog(buttonType);

            if (!dialogClicked)
                throw new ClickJSDialogException();
        }
        private static bool InteractWithJSDialog(JScriptDialogButtonType buttonType, IntPtr dialogHandle, DateTime timeout)
        {
            bool clicked = false;
            string buttonText = (buttonType == JScriptDialogButtonType.Ok) ? "OK" : "Cancel";

            while (DateTime.Now < timeout)
            {
                IntPtr buttonHandle = NativeMethods.FindWindowEx(dialogHandle, IntPtr.Zero, "Button", buttonText);

                if (buttonHandle == IntPtr.Zero)
                {
                    buttonText = (buttonType == JScriptDialogButtonType.Ok) ? "Leave this Page" : "Stay on this Page";
                    buttonHandle = NativeMethods.FindWindowEx(dialogHandle, IntPtr.Zero, "Button", buttonText);
                }

                // this logic is for new version of Chrome where JS Dialogs buttons dont have a handle
                if (buttonHandle == IntPtr.Zero)
                {
                    buttonText = (buttonType == JScriptDialogButtonType.Ok) ? "OK" : "Cancel";

                    if (buttonText == "OK")
                    {
                        ClickOkButton(dialogHandle);
                        return true;
                    }

                    CloseDialogWindow(dialogHandle);
                    return true;
                }

                if (!clicked && buttonHandle != IntPtr.Zero)
                {
                    clicked = ClickDialogButton(buttonHandle);
                }
                else if (clicked && buttonHandle == IntPtr.Zero)
                {
                    return true;
                }
            }

            return false;
        }
        private void InteractWithJSDialog(JScriptDialogButtonType buttonType, IntPtr dialogHandle, IntPtr buttonHandle)
        {
            if (dialogHandle != curWindowHandle)
                ShowDialog(dialogHandle);

            if (buttonType == JScriptDialogButtonType.Ok)
            {
                if (_firefoxVersion[0] == '3')
                {
                    _lastWasConfirmDialog = false;
                    ClickOkButton(buttonHandle);
                }
                else
                {
                    ClickOkAlternateDialog();
                }
            }
            else
            {
                if (_firefoxVersion[0] == '3')
                    CloseDialog(dialogHandle);
                else
                    CloseAlternateDialog();
            }
        }
 public void ClickJSDialogOnBeforeUnloadStimulateElementTest(JScriptDialogButtonType jsBtnType, string expectedWebPage)
 {
     try
     {
         _browser.NavigateBrowser(getTestPage("OnBeforeUnload.htm"));
         _browser.StimulateElement(IdentifierType.InnerHtml, "Google", "onclick", "a");
         _browser.ClickJSDialog(jsBtnType);
         _browser.AssertBrowserExists(expectedWebPage);
     }
     finally
     {
         // Clean up
         _browser.KillAllOpenBrowsers();
         this.OpenSwatTestPage();
     }
 }
 public void ClickJSDialogOnBeforeUnloadRefreshBrowserTest(JScriptDialogButtonType jsBtnType)
 {
     try
     {
         _browser.NavigateBrowser(getTestPage("OnBeforeUnload.htm"));
         _browser.RefreshBrowser();
         _browser.ClickJSDialog(jsBtnType);
         _browser.AssertBrowserExists("Dialog Test");  // Should end up on this page regardless of OK or Cancel
     }
     finally
     {
         // Clean up
         _browser.KillAllOpenBrowsers();
         this.OpenSwatTestPage();
     }
 }
        public void ClickJSDialog(JScriptDialogButtonType buttonType)
        {
            connectToSafariPlugin();
            //setCurrentURI();
            string result = string.Empty;
            DateTime timeout = DateTime.Now.AddSeconds(15);

            while (!result.Contains("OK") && DateTime.Now < timeout)
            {
                result = sendMessage(_socket, buttonType == JScriptDialogButtonType.Cancel ? "ClickJSDialogCancel^-~" : "ClickJSDialogOk^-~");
            }
            //disconnectSafariPlugin();
            if (!result.Contains("OK"))
                throw new ClickJSDialogException();
        }
		public void ClickJSDialog(JScriptDialogButtonType buttonType)
		{

			startSWATFixtureIfNotInOne();
			if (buttonType == JScriptDialogButtonType.Ok)
				writeCommand("|ClickJSDialog|Ok|");
			else
				writeCommand("|ClickJSDialog|Cancel|");
		}