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

如何获取JSystem测试场景的启动时间?

Hey there! I’ve dealt with exactly this need in JSystem before, so let’s break down how to grab your scenario’s start time easily.

方法1:通过JSystem核心Scenario API获取

JSystem’s built-in Scenario class provides a direct way to get the start time. You just need to fetch the current running scenario instance first, then call its getStartTime() method. Here’s a code example you can drop into your test script or case:

import jsystem.framework.system.SystemImpl;
import jsystem.framework.scenario.Scenario;
import java.util.Date;
import java.text.SimpleDateFormat;

// Get the current active scenario instance
Scenario currentScenario = SystemImpl.getInstance().getScenario();
// Retrieve the scenario's start time as a Date object
Date scenarioStartTime = currentScenario.getStartTime();

// Optional: Format the date for readable output
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
String formattedStartTime = dateFormatter.format(scenarioStartTime);
System.out.println("Scenario started at: " + formattedStartTime);
方法2:通过测试上下文属性获取

JSystem automatically stores the scenario start time as a context property, so you can also pull it from the TestProperties instance. This is useful if you want a more lightweight approach:

import jsystem.framework.TestProperties;
import java.util.Date;

// Fetch the start time directly from test properties
Date scenarioStartTime = (Date) TestProperties.getInstance().getProperty("scenario.start.time");

Quick Note: Make sure you call these methods after the scenario has started. If you run this code during the initial setup phase before the scenario launches, you’ll get a null value. The safest place is in your test steps or in the test() method of your test case.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 06:51:41