Example #1
0
        // This method must be called before PplFeatures,
        // otherwise, PplFeatures will block the test.
        private static Task ExpectMessageBoxWillNotPopUp(string title, string expContent,
                                                         string buttonNameToClick, int retryCount, int waitTime)
        {
            // MessageBox in pptlabs will block the whole thread,
            // so multi-thread is needed here.
            Task taskToVerify = new Task(() =>
            {
                // try to find messagebox window
                IntPtr msgBoxHandle = IntPtr.Zero;
                while (msgBoxHandle == IntPtr.Zero && retryCount > 0)
                {
                    msgBoxHandle = NativeUtil.FindWindow(MessageBoxIdentifier, title);
                    if (msgBoxHandle == IntPtr.Zero)
                    {
                        ThreadUtil.WaitFor(waitTime);
                        retryCount--;
                    }
                    else
                    {
                        break;
                    }
                }
                if (msgBoxHandle != IntPtr.Zero)
                {
                    Assert.Fail("Message Box should not be open.");
                }
            });

            taskToVerify.Start();
            return(taskToVerify);
        }
Example #2
0
 public static void SendMouseUp(int x, int y)
 {
     Cursor.Position = GetDpiSafeLocation(x, y);
     ThreadUtil.WaitFor(1000);
     NativeUtil.mouse_event(NativeUtil.MOUSEEVENTF_LEFTUP, 0, 0, 0, UIntPtr.Zero);
     ThreadUtil.WaitFor(150);
 }
        private static void AssertMessageboxContent(IntPtr msgBoxHandle, int retryCount, string expContent)
        {
            IntPtr dlgHandle = IntPtr.Zero;

            for (int i = 0; i < 5; i++)
            {
                // this API is a bit iffy, not sure why unable to find sometimes
                dlgHandle = NativeUtil.GetDlgItem(msgBoxHandle, 0xFFFF);
                if (dlgHandle != IntPtr.Zero)
                {
                    break;
                }
                ThreadUtil.WaitFor(1000);
            }
            Assert.AreNotEqual(IntPtr.Zero, dlgHandle, "Failed to find label in the messagebox.");

            const int     nchars = 1024;
            StringBuilder actualContentBuilder = new StringBuilder(nchars);
            int           isGetTextSuccessful  = NativeUtil.GetWindowText(dlgHandle, actualContentBuilder, nchars);

            if (expContent != "{*}")
            {
                Assert.IsTrue(isGetTextSuccessful > 0, "Failed to get text in the label of messagebox.");
                Assert.AreEqual(expContent, actualContentBuilder.ToString(), true, "Different MessageBox content.");
            }
        }
Example #4
0
 public static void Copy()
 {
     ThreadUtil.WaitFor(250);
     NativeUtil.SetForegroundWindow(NativeUtil.FindWindow("PPTFrameClass", null));
     SendKeys.SendWait("^c");
     ThreadUtil.WaitFor(250);
 }
Example #5
0
        public static void CloseDialogBox(IntPtr dialogBoxHandle, string buttonName)
        {
            IntPtr btnHandle = NativeUtil.FindWindowEx(dialogBoxHandle, IntPtr.Zero, null, buttonName);

            Assert.AreNotEqual(IntPtr.Zero, btnHandle, "Failed to find button in the dialog box.");
            NativeUtil.SetForegroundWindow(dialogBoxHandle);
            NativeUtil.SendMessage(btnHandle, 0x0201 /*left button down*/, IntPtr.Zero, IntPtr.Zero);
            NativeUtil.SendMessage(btnHandle, 0x0202 /*left button up*/, IntPtr.Zero, IntPtr.Zero);
        }
Example #6
0
        private static float GetScalingFactor()
        {
            Graphics g                    = Graphics.FromHwnd(IntPtr.Zero);
            IntPtr   desktop              = g.GetHdc();
            int      LogicalScreenHeight  = NativeUtil.GetDeviceCaps(desktop, (int)NativeUtil.DeviceCap.VERTRES);
            int      PhysicalScreenHeight = NativeUtil.GetDeviceCaps(desktop, (int)NativeUtil.DeviceCap.DESKTOPVERTRES);

            float ScreenScalingFactor = (float)PhysicalScreenHeight / (float)LogicalScreenHeight;

            return(ScreenScalingFactor); // 1.25 = 125%
        }
Example #7
0
        public static void SendMouseRightDoubleClick(int x, int y)
        {
            Cursor.Position = GetDpiSafeLocation(x, y);
            NativeUtil.mouse_event(
                NativeUtil.MOUSEEVENTF_RIGHTDOWN | NativeUtil.MOUSEEVENTF_RIGHTUP, 0, 0, 0, UIntPtr.Zero);

            ThreadUtil.WaitFor(150);

            NativeUtil.mouse_event(
                NativeUtil.MOUSEEVENTF_RIGHTDOWN | NativeUtil.MOUSEEVENTF_RIGHTUP, 0, 0, 0, UIntPtr.Zero);
        }
Example #8
0
        // This method must be called before PplFeatures,
        // otherwise, PplFeatures will block the test.
        private static Task ExpectMessageBoxWillPopUp(string title, string expContent,
                                                      string buttonNameToClick, int retryCount, int waitTime)
        {
            // MessageBox in pptlabs will block the whole thread,
            // so multi-thread is needed here.
            Task taskToVerify = new Task(() =>
            {
                // try to find messagebox window
                IntPtr msgBoxHandle = IntPtr.Zero;
                while (msgBoxHandle == IntPtr.Zero && retryCount > 0)
                {
                    msgBoxHandle = NativeUtil.FindWindow(MessageBoxIdentifier, title);
                    if (msgBoxHandle == IntPtr.Zero)
                    {
                        ThreadUtil.WaitFor(waitTime);
                        retryCount--;
                    }
                    else
                    {
                        break;
                    }
                }
                if (msgBoxHandle == IntPtr.Zero)
                {
                    Assert.Fail("Failed to find message box.");
                }

                // try to find text label in the message box
                IntPtr dlgHandle = NativeUtil.GetDlgItem(msgBoxHandle, 0xFFFF);
                Assert.AreNotEqual(IntPtr.Zero, dlgHandle, "Failed to find label in the messagebox.");

                const int nchars = 1024;
                StringBuilder actualContentBuilder = new StringBuilder(nchars);
                int isGetTextSuccessful            = NativeUtil.GetWindowText(dlgHandle, actualContentBuilder, nchars);

                // close the message box, otherwise it will block the test
                CloseMessageBox(msgBoxHandle, buttonNameToClick);

                if (expContent != "{*}")
                {
                    Assert.IsTrue(isGetTextSuccessful > 0, "Failed to get text in the label of messagebox.");
                    Assert.AreEqual(expContent, actualContentBuilder.ToString(), true, "Different MessageBox content.");
                }
            });

            taskToVerify.Start();
            return(taskToVerify);
        }
Example #9
0
 private static void CloseMessageBox(IntPtr msgBoxHandle, string buttonName)
 {
     if (buttonName == null)
     {
         // Simple close message box
         NativeUtil.SetForegroundWindow(msgBoxHandle);
         NativeUtil.SendMessage(msgBoxHandle, 0x0112 /*WM_SYSCOMMAND*/, new IntPtr(0xF060 /*SC_CLOSE*/), IntPtr.Zero);
     }
     else
     {
         // This may be flaky.. if there're more than one windows pop up at the same time..
         // it will affect clicking the button
         IntPtr btnHandle = NativeUtil.FindWindowEx(msgBoxHandle, IntPtr.Zero, "Button", buttonName);
         Assert.AreNotEqual(IntPtr.Zero, btnHandle, "Failed to find button in the messagebox.");
         NativeUtil.SetForegroundWindow(msgBoxHandle);
         NativeUtil.SendMessage(btnHandle, 0x0201 /*left button down*/, IntPtr.Zero, IntPtr.Zero);
         NativeUtil.SendMessage(btnHandle, 0x0202 /*left button up*/, IntPtr.Zero, IntPtr.Zero);
     }
 }
Example #10
0
        public static void WaitForDialogBox(Action openDialogAction, string lpClassName, string lpWindowName, int timeLimit = 5000)
        {
            Task task = new Task(() => openDialogAction());

            task.Start();

            int pollCount     = 10;
            int retryInterval = timeLimit / pollCount;

            for (int i = 0; i <= pollCount; ++i)
            {
                IntPtr spotlightDialog = NativeUtil.FindWindow(null, lpWindowName);
                if (spotlightDialog != IntPtr.Zero)
                {
                    return;
                }
                ThreadUtil.WaitFor(retryInterval);
            }
            Assert.Fail("Wait for dialog box timed out");
        }
Example #11
0
 public static void SendMouseLeftClick(int x, int y)
 {
     Cursor.Position = GetDpiSafeLocation(x, y);
     NativeUtil.mouse_event(
         NativeUtil.MOUSEEVENTF_LEFTDOWN | NativeUtil.MOUSEEVENTF_LEFTUP, 0, 0, 0, UIntPtr.Zero);
 }
Example #12
0
 public static extern IntPtr WindowFromPoint(NativeUtil.POINT Point);