-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functionality to show and hide windows basing on their process +s…
…emver: feature * Add functionality to show and hide windows basing on their process: - Implemented ShowWindow process extension - Added Process property to IForm - Added localized logging and a test for this functionality - Hide WinAppDriver window if it was started programmatically
- Loading branch information
Showing
10 changed files
with
161 additions
and
20 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
Aquality.WinAppDriver/src/Aquality.WinAppDriver/Extensions/ProcessExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Aquality.WinAppDriver.Applications; | ||
using System; | ||
using System.Diagnostics; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Aquality.WinAppDriver.Extensions | ||
{ | ||
public static class ProcessExtensions | ||
{ | ||
/// <summary> | ||
/// Sends ShowCommand to the window associated with the specified proccess. | ||
/// </summary> | ||
/// <param name="process">Proccess to send the command.</param> | ||
/// <param name="showCommand">A command that controls how the window is to be shown.</param> | ||
public static void ShowWindow(this Process process, ShowCommand showCommand) | ||
{ | ||
AqualityServices.LocalizedLogger.Info("loc.process.runcommand", process.ProcessName, $"{nameof(ShowWindow)}: {showCommand}"); | ||
var intPtr = process.MainWindowHandle.ToInt32(); | ||
ShowWindow(intPtr, Convert.ToInt32(showCommand)); | ||
} | ||
|
||
[DllImport("User32")] | ||
private static extern int ShowWindow(int hwnd, int nCmdShow); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
Aquality.WinAppDriver/src/Aquality.WinAppDriver/Extensions/ShowCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
namespace Aquality.WinAppDriver.Extensions | ||
{ | ||
/// <summary> | ||
/// Controls how the window is to be shown. | ||
/// This parameter is ignored the first time an application calls ShowWindow, | ||
/// if the program that launched the application provides a STARTUPINFO structure. | ||
/// Otherwise, the first time ShowWindow is called, | ||
/// the value should be the value obtained by the WinMain function in its nCmdShow parameter. | ||
/// For more information, please visit https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow. | ||
/// </summary> | ||
public enum ShowCommand | ||
{ | ||
/// <summary> | ||
/// Hides the window and activates another window. | ||
/// </summary> | ||
Hide = 0, | ||
/// <summary> | ||
/// Activates and displays a window. | ||
/// If the window is minimized or maximized, the system restores it to its original size and position. | ||
/// An application should specify this flag when displaying the window for the first time. | ||
/// </summary> | ||
ShowNormal = 1, | ||
/// <summary> | ||
/// Activates the window and displays it as a minimized window. | ||
/// </summary> | ||
ShowMinimized = 2, | ||
/// <summary> | ||
/// Activates the window and displays it as a maximized window. | ||
/// </summary> | ||
ShowMaximized = 3, | ||
/// <summary> | ||
/// Displays a window in its most recent size and position. | ||
/// This value is similar to <see cref="ShowNormal"/>, except that the window is not activated. | ||
/// </summary> | ||
ShowNoActivate = 4, | ||
/// <summary> | ||
/// Activates the window and displays it in its current size and position. | ||
/// </summary> | ||
Show = 5, | ||
/// <summary> | ||
/// Minimizes the specified window and activates the next top-level window in the Z order. | ||
/// </summary> | ||
Minimize = 6, | ||
/// <summary> | ||
/// Displays the window as a minimized window. | ||
/// This value is similar to <see cref="ShowMinimized"/>, except the window is not activated. | ||
/// </summary> | ||
ShowMinimizedNoActive = 7, | ||
/// <summary> | ||
/// Displays the window in its current size and position. | ||
/// This value is similar to <see cref="Show"/>, except that the window is not activated. | ||
/// </summary> | ||
ShowNoActive = 8, | ||
/// <summary> | ||
/// Activates and displays the window. | ||
/// If the window is minimized or maximized, the system restores it to its original size and position. | ||
/// An application should specify this flag when restoring a minimized window. | ||
/// </summary> | ||
Restore = 9, | ||
/// <summary> | ||
/// Sets the show state based on the SW_ value specified in the STARTUPINFO structure | ||
/// passed to the CreateProcess function by the program that started the application. | ||
/// </summary> | ||
ShowDefault = 10, | ||
/// <summary> | ||
/// Minimizes a window, even if the thread that owns the window is not responding. | ||
/// This flag should only be used when minimizing windows from a different thread. | ||
/// </summary> | ||
ForceMinimize = 11 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 41 additions & 13 deletions
54
Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Forms/Chrome/MultipleWindowsTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters