对于我的E2E测试,我想获得当前日期和时间,并在有效负载主体中使用此DateTime字符串,例如:
### Precondition: Create a contract with current time stamp in ISO format
# currentDateTimeStringInISO = some JavaScript code
POST http://localhost:8080/api/rest/v1/contracts/12345678
Authorization: Basic user user
Content-Type: application/json
{
"valid_until": currentDateTimeStringInISO,
...
}
> {%
client.test("Status code is 201", function() {
client.assert(response.status === 201, "Expected status code 201 for contract creation");
});
client.test("Contract status is VALID", function() {
client.assert(response.body.contractStatus === "VALID", "Expected status to be VALID");
});
%}
正确的HTTPYAC语法是什么?我阅读了官方文档,但没有得到这项工作。 thanks, 妮可
i从另一个线程中找到了解决方案:
{{
let now = new Date();
// Add 1 second
let cetTime = new Date(now.getTime() + 1000);
// Adjust to CET winter time (CET, UTC+1)
let cetDate = new Date(cetTime.getTime() + (1 * 60 * 60 * 1000));
// Export as full ISO string with explicit CET offset
exports.currentTime = berlinDate.toISOString().replace('Z', '+01:00');
}}
POST http://localhost:8080/api/rest/v1/contracts
Authorization: Basic user user
Content-Type: application/json
{
"expiryDate": "{{currentTime}}",
...
}
@response
{{
console.info('Generated currentTime was: ' + currentTime);
}}
...assertions