如何通过TestComplete中的快捷方式验证应用程序是否启动成功?

发布于 2024-11-03 14:49:07 字数 497 浏览 3 评论 0原文

我正在尝试通过 TestComplete 中的桌面快捷方式启动应用程序。我需要验证应用程序是否启动成功,如果没有,我想知道失败的原因。

Testcomplete 有助于使用 Win32API 库调用某些 Windows API。因此,为了通过 exe 启动应用程序,我使用 Win32API.WinExec() 方法。基于 WinExec 的返回值如果有什么问题我会知道。但 WinExec 不能与 .lnk 文件/快捷方式一起使用。一种替代方法是不将 .lnk 文件作为 WinExec 的第一个参数,我可以给出 cmd /c xyz.lnk ,它始终返回 true,即使 .lnk 文件不存在,因为它在 cmd.exe 上验证已成功或不是。但有没有更好的解决方案来验证这种情况呢?

顺便说一句,我在 Testcomplete 中使用 JScript。

I am trying to launch an application thru its desktop shortcut in TestComplete. I need to verify whether the application launched successfully, if not I would like to know the failure reason.

Testcomplete facilitates calling of some of the Windows APIs using Win32API library. So, for launching an application thru exe I am using Win32API.WinExec() method. Based on the return value of WinExec I would know if anything went wrong. But WinExec cannot be used with .lnk files/shortcuts. one alternative is instead of giving the .lnk file as 1st argument of WinExec, I can give cmd /c xyz.lnk which returns true all the time even the .lnk file doesn't exist because it validates on cmd.exe has succeeded or not. But is there a better solution for verifying this scenaio?

By the way, I am using JScript in Testcomplete.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我只土不豪 2024-11-10 14:49:07

我根据此“操作方法”条目创建了以下脚本:
http://www.smartbear.com/support/viewarticle/8967/

这里是例子:

// One possible approach
function Test()
{
  var strShortcut = "D:\\Notepad.lnk";

  // Run the shortcut
  Sys.OleObject("WScript.Shell").Run(strShortcut);

  // Get the executable file name
  var targetFileName = GetShortcutTaget(strShortcut);
  if ("" == targetFileName)
  {
    Runner.Halt("The target file does not exist");
  }

  // Try to find a process with the executable name used in the shortcut
  var foundProc = Sys.FindChild("Path", targetFileName)

  // Process the result
  if (foundProc.Exists)
    Log.Message("The applicated started successfully: " + targetFileName);
  else
    Log.Warning("The applicated did not start: " + targetFileName);
}

function GetShortcutTaget(shortcutFileName)
{
  var WshShell = new ActiveXObject("WScript.Shell");
  var fso = new ActiveXObject("Scripting.FileSystemObject");

  if (fso.FileExists(shortcutFileName)) {
    var shortcut = WshShell.CreateShortcut(shortcutFileName);
    return shortcut.TargetPath;
  }

  return "";
}

I have created the below script based on this How To entry:
http://www.smartbear.com/support/viewarticle/8967/

Here is the example:

// One possible approach
function Test()
{
  var strShortcut = "D:\\Notepad.lnk";

  // Run the shortcut
  Sys.OleObject("WScript.Shell").Run(strShortcut);

  // Get the executable file name
  var targetFileName = GetShortcutTaget(strShortcut);
  if ("" == targetFileName)
  {
    Runner.Halt("The target file does not exist");
  }

  // Try to find a process with the executable name used in the shortcut
  var foundProc = Sys.FindChild("Path", targetFileName)

  // Process the result
  if (foundProc.Exists)
    Log.Message("The applicated started successfully: " + targetFileName);
  else
    Log.Warning("The applicated did not start: " + targetFileName);
}

function GetShortcutTaget(shortcutFileName)
{
  var WshShell = new ActiveXObject("WScript.Shell");
  var fso = new ActiveXObject("Scripting.FileSystemObject");

  if (fso.FileExists(shortcutFileName)) {
    var shortcut = WshShell.CreateShortcut(shortcutFileName);
    return shortcut.TargetPath;
  }

  return "";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文