You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ranorex中如何按条件退出录制模块并执行后续模块

Solution: Early Module Exit When Element Exists (No Test Failure)

Got it, let's adjust your code so you can exit the current module early without marking the test as failed when the Deconnexion element is detected. Here's the breakdown:

How It Works

  1. Check existence without failure: Instead of using Validate.Exists() (which throws an error if the element isn't found), we use the Exists() property of the element info object. This returns a simple boolean (true/false) so we can conditionally act without triggering a test failure.
  2. Conditional exit: If Deconnexion exists, we log the result and exit the module immediately—skipping all remaining steps and moving to the next module cleanly.
  3. Proceed normally: If the element doesn't exist, we run your original module steps as intended.

Modified Code Implementation

// Check if Deconnexion element exists (no test failure if it doesn't)
bool deconnexionIsPresent = repo.Internet.abc.Connexion.DeconnexionInfo.Exists();

Report.Log(ReportLevel.Info, "Validation", $"Validating existence of 'Internet.abc.Connexion.Deconnexion': {deconnexionIsPresent}", repo.Internet.abc.Connexion.DeconnexionInfo, new RecordItemIndex(0));

if (deconnexionIsPresent)
{
    Report.Log(ReportLevel.Info, "Module Exit", "Deconnexion element detected—exiting current module early to proceed to next module.");
    // Exit the current module (use 'return;' if this is a method/module function)
    return;
}

// These steps only execute if Deconnexion does NOT exist
Delay.Milliseconds(0);
Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'Internet.abc.Connexion.Httpsxyz' at Center.", repo.Internet.abc.Connexion.Httpsxyz, new RecordItemIndex(1));
repo.Internet.abc.Connexion.Httpsxyz.Click();
Delay.Milliseconds(200);

Key Notes

  • Why replace Validate.Exists?: Validate.Exists() is built to fail the test when the target element isn't found. Using the Exists() property lets us check presence without triggering a failure, which aligns with your requirement.
  • Exiting the module: The return; statement works if this code lives inside a method (common in frameworks like Ranorex). If your setup uses a different structure, replace this with your framework's specific way to skip remaining steps (e.g., setting a skip flag or calling a framework-provided skip method).
  • Logging clarity: The extra log entry explicitly states why the module exited early, making test reports easier to debug later.

内容的提问来源于stack exchange,提问作者ae2019

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 18:42:40