As suggested in the post from Arkane I created a handle to the process from which i can determine the state
namespace codedui_test
{
public enum ShowWindowCommands : int
{
Hide = 0,
Normal = 1,
Minimized = 2,
Maximized = 3,
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public struct WINDOWPLACEMENT
{
public int length;
public int flags;
public ShowWindowCommands showCmd;
public System.Drawing.Point ptMinPosition;
public System.Drawing.Point ptMaxPosition;
public System.Drawing.Rectangle rcNormalPosition;
}
public class ProcessManager
{
protected Process process;
public ProcessManager(string processToWatch)
{
//get Handle of window to extract it's position and styles
Process[] processes = Process.GetProcesses();
foreach (Process proc in processes)
{
if (proc.ProcessName == processToWatch)
{
process = proc;
break;
}
}
}
public WINDOWPLACEMENT GetPlacement()
{
IntPtr hwnd = process.MainWindowHandle;
WINDOWPLACEMENT placement = new WINDOWPLACEMENT();
placement.length = Marshal.SizeOf(placement);
GetWindowPlacement(hwnd, ref placement);
return placement;
}
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
}
}
In my Testclass I am now able to create a processobject from which i can get the placement:
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium.Windows;
namespace codedui_test
{
[TestClass]
public class MainWindowTest
{
protected static ProcessManager dSProcess;
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
//Setup Handle to Window to be able to determine it's size
dSProcess = new ProcessManager("ProgramName");
}
[TestMethod]
public void TestWindowControl()
{
session.FindElementByAccessibilityId("MaximizeButton").Click();
var placement = dSProcess.GetPlacement();
Assert.AreEqual("Maximized", placement.showCmd.ToString());
session.FindElementByAccessibilityId("RestoreButton").Click();
placement = dSProcess.GetPlacement();
Assert.AreEqual("Normal", placement.showCmd.ToString());
session.FindElementByAccessibilityId("MinimizeButton").Click();
placement = dSProcess.GetPlacement();
Assert.AreEqual("Minimized", placement.showCmd.ToString());
}
....further methods
}
}
Draft for this solution comes from the source Arkane posted