예제 #1
0
        public override bool HandleDialog(Window window)
        {
            if (IsPromptDialog(window))
            {
                window.ToFront();
                window.SetActivate();

                Window inputBox = new
                Window(NativeMethods.GetChildWindowHwnd(window.Hwnd, "Edit"));

                if (inputBox.Hwnd != IntPtr.Zero)
                {
                    if (_cancel)
                    {
                        window.ForceClose();
                    }
                    else
                    {
                        NativeMethods.SetActiveWindow(inputBox.Hwnd);

                        System.Windows.Forms.SendKeys.SendWait(_input);
                        System.Windows.Forms.SendKeys.SendWait("{ENTER}");
                    }
                    return true;
                }
            }
            return false;
        }
예제 #2
0
		public override bool HandleDialog(Window window)
		{
			if (dialogHandler.CanHandleDialog(window))
			{
				dialogHandler.window = window;

				message = dialogHandler.Message;

				ConfirmDialogHandler confirmDialogHandler = dialogHandler as ConfirmDialogHandler;

				// hasHandledDialog must be set before the Click and not
				// after because this code executes on a different Thread
				// and could lead to property HasHandledDialog returning false
				// while hasHandledDialog set had to be set.
				hasHandledDialog = true;

				if (confirmDialogHandler != null && clickCancelButton)
				{
					confirmDialogHandler.CancelButton.Click();
				}
				else
				{
					dialogHandler.OKButton.Click();
				}
			}

			return hasHandledDialog;
		}
예제 #3
0
		public void Close()
		{
			Window dialog = new Window(hwnd);
			if (dialog.Visible)
			{
				dialog.ForceClose();
			}
			base.Dispose(true);
		}
		public override bool HandleDialog(Window window)
		{
			if (IsVBScriptAlert(window))
			{
				ButtonToPush(window).Click();

				hasHandledDialog = true;
				return true;
			}

			return false;
		}
		/// <summary>
		/// When OK is the only button on the msgbox (buttons value = 1)
		/// then the button Id = 2. In all other situations the button Id
		/// for OK is 1.
		/// </summary>
		/// <param name="window"></param>
		/// <param name="button"></param>
		/// <returns></returns>
		private Button IfOKButtonThenGetTheRightButtonId(Window window, Button button) 
		{
			if (button == Button.OK)
			{
				if (!GetButton(window, Button.OK).Exists())
				{
					return Button.Cancel;
				}
			}

			return button;
		}
예제 #6
0
		public override bool HandleDialog(Window window)
		{
			if (CanHandleDialog(window))
			{
				this.window = window;

				while (window.Exists())
				{
					Thread.Sleep(200);
				}
				return true;
			}
			return false;
		}
예제 #7
0
		public override bool HandleDialog(Window window)
		{
			if (IsFileUploadDialog(window))
			{
				IntPtr usernameControlHandle = NativeMethods.GetChildWindowHwnd(window.Hwnd, "Edit");

				NativeMethods.SetForegroundWindow(usernameControlHandle);
				NativeMethods.SetActiveWindow(usernameControlHandle);


				System.Windows.Forms.SendKeys.SendWait(fileName + "{ENTER}");
				return true;
			}

			return false;
		}
		public override bool HandleDialog(Window window)
		{
			// See if the dialog has a static control with a controlID 
			// of 0xFFFF. This is unique for alert and confirm dialogboxes.
			IntPtr handle = NativeMethods.GetDlgItem(window.Hwnd, 0xFFFF);

			if (handle != IntPtr.Zero)
			{
				alertQueue.Enqueue(NativeMethods.GetWindowText(handle));

				window.ForceClose();

				return true;
			}

			return false;
		}
예제 #9
0
		public override bool HandleDialog(Window window)
		{
			if (IsLogonDialog(window))
			{
				// Find Handle of the "Frame" and then the combo username entry box inside the frame
				IntPtr inputFrameHandle = NativeMethods.GetChildWindowHwnd(window.Hwnd, "SysCredential");
				IntPtr usernameControlHandle = NativeMethods.GetChildWindowHwnd(inputFrameHandle, "ComboBoxEx32");

				NativeMethods.SetActiveWindow(usernameControlHandle);
				Thread.Sleep(50);

				NativeMethods.SetForegroundWindow(usernameControlHandle);
				Thread.Sleep(50);

				System.Windows.Forms.SendKeys.SendWait(userName + "{TAB}");
				Thread.Sleep(500);

				System.Windows.Forms.SendKeys.SendWait(password + "{ENTER}");

				return true;
			}

			return false;
		}
예제 #10
0
 /// <summary>
 /// Determines whether the window is a prompt dialog.
 /// </summary>
 /// <param name="window">The window.</param>
 /// <returns>
 /// 	<c>true</c> if window is a prompt dialog; otherwise, <c>false</c>.
 /// </returns>
 public bool IsPromptDialog(Window window)
 {
     return (window.StyleInHex == "94C800C4");
 }
 private WinButton GetButton(Window window, Button button)
 {
     return(new WinButton((int)button, window.Hwnd));
 }
예제 #12
0
		private WinButton GetButton(Window window, Button button) 
		{
			return new WinButton((int)button, window.Hwnd);
		}
예제 #13
0
		private WinButton ButtonToPush(Window window)
		{
			Button button = IfOKButtonThenGetTheRightButtonId(window, _button);

			return GetButton(window, button);
		}
예제 #14
0
		private WinButton GetButtonToPress(Window window)
		{
			WinButton btn = null;

			switch (_optionEnum)
			{
				case FileDownloadOptionEnum.Run:
					btn = new WinButton(4426, window.Hwnd);
					break;

				case FileDownloadOptionEnum.Open:
					btn = new WinButton(4426, window.Hwnd);
					break;

				case FileDownloadOptionEnum.Save:
					btn = new WinButton(4427, window.Hwnd);
					if (!btn.Exists())
					{
						btn = new WinButton(4424, window.Hwnd);
					}
					break;

				case FileDownloadOptionEnum.Cancel:
					btn = new WinButton(2, window.Hwnd);
					break;
			}

			return btn;
		}
예제 #15
0
		private bool IsVBScriptAlert(Window window)
		{
			return window.StyleInHex == "94C803C5";
		}
예제 #16
0
		private void HandleFileSaveDialog(Window window)
		{
			IntPtr usernameControlHandle = NativeMethods.GetChildWindowHwnd(window.Hwnd, "Edit");

			NativeMethods.SetForegroundWindow(usernameControlHandle);
			NativeMethods.SetActiveWindow(usernameControlHandle);

			System.Windows.Forms.SendKeys.SendWait(saveAsFilename + "{ENTER}");
		}
예제 #17
0
		/// <summary>
		/// Handles the dialogs to download (and save) a file
		/// Mainly used internally by WatiN.
		/// </summary>
		/// <param name="window">The window.</param>
		/// <returns></returns>
		public override bool HandleDialog(Window window)
		{
			// This if handles the File download dialog
			if (!HasHandledFileDownloadDialog && IsFileDownloadDialog(window))
			{
				window.ToFront();
				window.SetActivate();

				DownloadProgressDialog = new Window(window.ParentHwnd);

				WinButton btn = GetButtonToPress(window);
				btn.Click();

				hasHandledFileDownloadDialog = !Exists(window);

				if (HasHandledFileDownloadDialog)
				{
					Logger.LogAction("Download started at " + DateTime.Now.ToLongTimeString());
					Logger.LogAction("Clicked " + _optionEnum.ToString());
				}

				return true;
			}

			// This if handles the download progress dialog
			if (IsDownloadProgressDialog(window))
			{
				DownloadProgressDialog = window;

                WinButton openOrRun= new WinButton(4377, new Hwnd(window.Hwnd));

                if (openOrRun.Enabled)
                {
                    WinButton close = new WinButton(2, new Hwnd(window.Hwnd));

                    close.Click();
                    
                    SimpleTimer timer = new SimpleTimer(5);
                    while (!timer.Elapsed && window.Exists())
                    {
                        Thread.Sleep(200);
                    }
                }

				return true;
			}

			// This if handles the File save as dialog
			if (IsFileSaveDialog(window))
			{
				Logger.LogAction("Saving Download file as " + saveAsFilename);

				DownloadProgressDialog = new Window(window.ParentHwnd);

				HandleFileSaveDialog(window);

				return true;
			}

			// Window is not a dialog this handler can handle.
			return false;
		}
예제 #18
0
		/// <summary>
		/// If the window is a dialog and visible, it will be passed to
		/// the registered dialog handlers. I none if these can handle
		/// it, it will be closed if <see cref="CloseUnhandledDialogs"/>
		/// is <c>true</c>.
		/// </summary>
		/// <param name="window">The window.</param>
		public void HandleWindow(Window window)
		{
			if (window.IsDialog())
			{
				WaitUntilVisibleOrTimeOut(window);

				// Lock the thread and see if a handler will handle
				// this dialog window
				lock (this)
				{
					foreach (IDialogHandler dialogHandler in handlers)
					{
						try
						{
							if (dialogHandler.HandleDialog(window)) return;
						}
						catch (Exception e)
						{
							lastException = e;

							Logger.LogAction("Exception was thrown while DialogWatcher called HandleDialog:");
							Logger.LogAction(e.ToString());
						}
					}

					// If no handler handled the dialog, see if the dialog
					// should be closed automatically.
					if (CloseUnhandledDialogs)
					{
						Logger.LogAction("Auto closing dialog with title '{0}'.", window.Title);
						window.ForceClose();
					}
				}
			}
		}
 private bool IsVBScriptAlert(Window window)
 {
     return(window.StyleInHex == "94C803C5");
 }
예제 #20
0
		/// <summary>
		/// Determines whether the specified window is a file save as dialog by
		/// checking the style property of the window. It should match
		/// <c>(window.StyleInHex == "96CC20C4") || (window.StyleInHex == "96CC02C4")</c>
		/// </summary>
		/// <param name="window">The window.</param>
		/// <returns>
		/// 	<c>true</c> if the specified window is a file save as dialog; otherwise, <c>false</c>.
		/// </returns>
		public bool IsFileSaveDialog(Window window)
		{
			// "96CC20C4" is valid for Windows XP, Win 2000 and Win 2003
			// "96CC02C4" is valid for Windows Vista
			return (window.StyleInHex == "96CC20C4") || (window.StyleInHex == "96CC02C4");
		}
예제 #21
0
		/// <summary>
		/// Determines whether the specified window is a download progress dialog by
		/// checking the style property of the window. It should match
		/// <c>(window.StyleInHex == "9CCA0BC4") || (window.StyleInHex == "94CA0BC4")</c>
		/// </summary>
		/// <param name="window">The window.</param>
		/// <returns>
		/// 	<c>true</c> if the specified window is a download progress dialog; otherwise, <c>false</c>.
		/// </returns>
		public bool IsDownloadProgressDialog(Window window)
		{
			// "9CCA0BC4" is valid before downloading the file has started
			// "94CA0BC4" is valid during and after the download
			return (window.StyleInHex == "9CCA0BC4") || (window.StyleInHex == "94CA0BC4");
		}
예제 #22
0
		/// <summary>
		/// Determines whether the specified window is a file download dialog by
		/// checking the style property of the window. It should match
		/// <c>window.StyleInHex == "94C80AC4"</c>
		/// </summary>
		/// <param name="window">The window.</param>
		/// <returns>
		/// 	<c>true</c> if the specified window is a file download dialog; otherwise, <c>false</c>.
		/// </returns>
		public bool IsFileDownloadDialog(Window window)
		{
			return (window.StyleInHex == "94C80AC4");
		}
        private WinButton ButtonToPush(Window window)
        {
            Button button = IfOKButtonThenGetTheRightButtonId(window, _button);

            return(GetButton(window, button));
        }
예제 #24
0
		/// <summary>
		/// Determines whether the specified window is a logon dialog.
		/// </summary>
		/// <param name="window">The window.</param>
		/// <returns>
		/// 	<c>true</c> if the specified window is a logon dialog; otherwise, <c>false</c>.
		/// </returns>
		public virtual bool IsLogonDialog(Window window)
		{
			// If a logon dialog window is found hWnd will be set.
			return NativeMethods.GetChildWindowHwnd(window.Hwnd, "SysCredential") != IntPtr.Zero;
		}
예제 #25
0
		/// <summary>
		/// Determines if a dialog still exists by checking the the existance of the 
		/// window.Hwnd and checking if the window is visible.
		/// </summary>
		/// <param name="dialog">The dialog.</param>
		/// <returns><c>true</c> if exists and visible, otherwise <c>false</c></returns>
		public bool Exists(Window dialog)
		{
			return dialog.Exists() && dialog.Visible;

//	    bool exists = dialog.Exists();
//      Logger.LogAction("Exists: exists == " + exists.ToString());
//
//	    bool visible = dialog.Visible;
//      Logger.LogAction("Exists: visible == " + visible.ToString());
//      
//      return exists && visible;
		}
예제 #26
0
		private static void WaitUntilVisibleOrTimeOut(Window window)
		{
			// Wait untill window is visible so all properties
			// of the window class (like Style and StyleInHex)
			// will return valid values.
			SimpleTimer timer = new SimpleTimer(Settings.WaitForCompleteTimeOut);

			do
			{
				if (window.Visible) return;

				Thread.Sleep(50);
			} while (!timer.Elapsed);

			Logger.LogAction("Dialog with title '{0}' not visible after {1} seconds.", window.Title, Settings.WaitForCompleteTimeOut);
		}
예제 #27
0
		public abstract bool CanHandleDialog(Window window);
예제 #28
0
		/// <summary>
		/// Checks if window is null or <see cref="Exists"/>.
		/// </summary>
		/// <param name="dialog">The dialog.</param>
		/// <returns><c>true</c> if null or exists, otherwise <c>false</c></returns>
		public bool ExistsOrNull(Window dialog)
		{
			if (dialog == null)
			{
//	      Logger.LogAction("ExistsOrNull: dialog == null");
				return true;
			}

			return Exists(dialog);
		}