Example #1
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 #2
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 #3
0
 private static void VerifyExpectation(Task taskToVerify, int retryCount, int waitTime)
 {
     // wait for task to finish
     while (taskToVerify.Status == TaskStatus.Running && retryCount > 0)
     {
         ThreadUtil.WaitFor(waitTime);
         retryCount--;
     }
     // assert no exception during task's execution
     if (taskToVerify.Exception != null)
     {
         Assert.AreEqual(null, taskToVerify.Exception, "Failed to verify expectation. Exception: {0}",
                         taskToVerify.Exception.Message);
     }
     // don't end so fast..
     ThreadUtil.WaitFor(500);
 }
Example #4
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 #5
0
 public static void SendMouseDown(int x, int y)
 {
     Cursor.Position = GetDpiSafeLocation(x, y);
     NativeUtil.mouse_event(NativeUtil.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, UIntPtr.Zero);
     ThreadUtil.WaitFor(1000);
 }