예제 #1
0
        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.");
            }
        }
예제 #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);
        }