需要帮助识别和关闭随机出现的警告

Need help identifying and closing a warning that appears at random

我的 windows 应用程序上随机出现一个警告弹出窗口(此警告是必需的),它需要关联的硬件来修复与警告相关的问题。这不会让应用程序在关闭之前工作。

无论如何,我的问题是当我在 运行 另一个脚本中验证应用程序上的某些内容时,我需要一种方法来查找此对话框并在脚本为 运行 时关闭它。有没有 ways/methods/keywords 可以做到这一点?

就像我说的,这个警告是随机发生的,所以我不能把它的逻辑放在脚本的一个地方并期望它起作用,我也不能把它放在每一行。关于如何处理这个的任何想法? TIA

在 UFT 中探索 'Recovery Scenarios'。 他们正是出于这个原因——异常处理。

请参考VBScript to detect an open messagebox and close it

另一个解决方案

using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Diagnostics;
using System.Linq;

namespace HandleDynamicDialog
{
    public class Program
    {
        [DllImport("user32.dll")]
        private static extern int FindWindow(string lpClassName, string lpWindowName);

        [DllImport("user32.dll")]
        private static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);

        private const int WM_SYSCOMMAND = 0x0112;

        private const int SC_CLOSE = 0xF060;

        static void Main(string[] args)
        {
            if (args.Length == 2)
            {
                //Pass your dialog class and title as command line arguments from uft script.
                string targetDialogClass = args[0];
                string targetDialogTitle = args[1];
                //Verify UFT is launched 
                bool uftVisible = IsUftVisible();
                while (uftVisible)
                {
                    //Close the warning dialog
                    CloseDialog(targetDialogClass, targetDialogTitle);
                }
            }
        }

        /// <summary>
        /// Close dialog using API
        /// </summary>
        /// <param name="dialogClass"></param>
        /// <param name="dialogTitle"></param>
        public static void CloseDialog(string dialogClass, string dialogTitle)
        {
            try
            {
                int winHandle = FindWindow(dialogClass, dialogTitle);
                if (winHandle > 0)
                {
                    SendMessage(winHandle, WM_SYSCOMMAND, SC_CLOSE, 0);
                }
                Thread.Sleep(5000);
            }
            catch (Exception exception)
            {
                //Exception
            }
        }

        /// <summary>
        /// Verify UFT is visible or not
        /// </summary>
        /// <returns></returns>
        public static bool IsUftVisible()
        {
            return Process.GetProcesses().Any(p => p.MainWindowTitle.Contains("HP Unified Functional Testing"));
        }
    }
}

来自 UFT

Call HandleDynamicDialog("CalcFrame","Calculator")
Public Sub HandleDynamicDialog(ByVal dialogClass,ByVal dialogTitle)
    Dim objShell
    Dim strCommandLineString
    Set objShell = CreateObject("Wscript.Shell")    
    strCommandLineString = "C:\HandleWarningDialog.exe " & dialogClass & " " & dialogTitle
    SystemUtil.CloseProcessByName "HandleWarningDialog.exe"
    objShell.Exec(strCommandLineString)
    Set objShell = Nothing  
End Sub