我如何以如下所示的特定格式获取空手道json报告
我试图以下面提到的特定格式获取示例功能文件的空手道JSON报告。
[
{
"line": 3,
"elements": [
{
"start_timestamp": "2022-04-05T17:17:20.811Z",
"before": [
{
"result": {
"duration": 19702884258,
"status": "passed"
},
"match": {
"location": "Hooks.before(Scenario)"
}
}
],
"line": 7,
"name": "Guided Member Welcome Login - SCAL_ACTIVE_NEW_SMOKE_EN",
"description": "",
"id": "smoke-feature;guided-member-welcome-login---scal-active-new-smoke-en",
"after": [
{
"result": {
"duration": 1245339916,
"status": "passed"
},
"match": {
"location": "Hooks.after(Scenario)"
}
}
],
"type": "scenario",
"keyword": "Scenario",
"steps": [
{
"result": {
"duration": 150247948961,
"status": "passed"
},
"line": 8,
"name": "Iamloggedintokp.orgas\"SCAL_ACTIVE_NEW_SMOKE\"\"English\"",
"match": {
"arguments": [
{
"val": "\"SCAL_ACTIVE_NEW_SMOKE\"",
"offset": 28
},
{
"val": "\"English\"",
"offset": 51
}
],
"location": "GMWHub.iAmLoggedInToKpOrgAs(String,String)"
},
"keyword": "Given "
},
{
"result": {
"duration": 15987954340,
"status": "passed"
},
"line": 9,
"name": "IamnavigatedtoGuidedMemberWelcomehubpage",
"match": {
"location": "GMWHub.iNavigateToGuidedMemberWelcomeHubPage()"
},
"keyword": "When"
}
],
"tags": [
{
"name": "@smoke"
},
{
"name": "@regression"
}
]
}
],
"name": "Smoke Feature",
"description": "",
"id": "smoke-feature",
"keyword": "Feature",
"uri": "file:target/parallel/features/Smoke_scenario001_run001_IT.feature",
"tags": []
}
]
但是,如下所示,我在之前没有和的报告。
[
{
"line": 1,
"elements": [
{
"start_timestamp": "2022-05-23T07:27:32.501Z",
"line": 3,
"name": "GET Request",
"description": "",
"id": "get-request",
"type": "scenario",
"keyword": "Scenario",
"steps": [
{
"name": "url 'https://reqres.in/api/users/2'",
"result": {
"duration": 1949100,
"status": "passed"
},
"match": {
"location": "karate",
"arguments": []
},
"keyword": "Given",
"line": 4
},
{
"name": "method GET",
"result": {
"duration": 1208456200,
"status": "passed"
},
"match": {
"location": "karate",
"arguments": []
},
"keyword": "When",
"line": 5
},
{
"name": "status 200",
"result": {
"duration": 16100,
"status": "passed"
},
"match": {
"location": "karate",
"arguments": []
},
"keyword": "Then",
"line": 6
}
],
"tags": []
}
],
"name": "feature/main.feature",
"description": "Testing GET API",
"id": "testing-get-api",
"keyword": "Feature",
"uri": "feature/main.feature"
}
]
TestRunner类:
public class TestRunner {
@Test
void testParallel() {
ArrayList list = new ArrayList();
Results results = Runner.path("classpath:features/sample.feature").parallel(5);
Stream<FeatureResult> res = results.getFeatureResults();
res.forEach(action -> {
JSONObject jsonObj = new JSONObject(action.toCucumberJson());
System.out.println(jsonObj);
}
}
}
示例功能文件:
Feature: Testing GET API
Scenario: GET Request
Given url 'https://reqres.in/api/users/2'
When method GET
Then status 200
有没有办法将JSON报告按照关键字之前和之后获得预期?
I am trying to get the Karate json report for the sample feature file in the specific format mentioned below.
[
{
"line": 3,
"elements": [
{
"start_timestamp": "2022-04-05T17:17:20.811Z",
"before": [
{
"result": {
"duration": 19702884258,
"status": "passed"
},
"match": {
"location": "Hooks.before(Scenario)"
}
}
],
"line": 7,
"name": "Guided Member Welcome Login - SCAL_ACTIVE_NEW_SMOKE_EN",
"description": "",
"id": "smoke-feature;guided-member-welcome-login---scal-active-new-smoke-en",
"after": [
{
"result": {
"duration": 1245339916,
"status": "passed"
},
"match": {
"location": "Hooks.after(Scenario)"
}
}
],
"type": "scenario",
"keyword": "Scenario",
"steps": [
{
"result": {
"duration": 150247948961,
"status": "passed"
},
"line": 8,
"name": "Iamloggedintokp.orgas\"SCAL_ACTIVE_NEW_SMOKE\"\"English\"",
"match": {
"arguments": [
{
"val": "\"SCAL_ACTIVE_NEW_SMOKE\"",
"offset": 28
},
{
"val": "\"English\"",
"offset": 51
}
],
"location": "GMWHub.iAmLoggedInToKpOrgAs(String,String)"
},
"keyword": "Given "
},
{
"result": {
"duration": 15987954340,
"status": "passed"
},
"line": 9,
"name": "IamnavigatedtoGuidedMemberWelcomehubpage",
"match": {
"location": "GMWHub.iNavigateToGuidedMemberWelcomeHubPage()"
},
"keyword": "When"
}
],
"tags": [
{
"name": "@smoke"
},
{
"name": "@regression"
}
]
}
],
"name": "Smoke Feature",
"description": "",
"id": "smoke-feature",
"keyword": "Feature",
"uri": "file:target/parallel/features/Smoke_scenario001_run001_IT.feature",
"tags": []
}
]
However I am getting the report without the before and after keys as shown below.
[
{
"line": 1,
"elements": [
{
"start_timestamp": "2022-05-23T07:27:32.501Z",
"line": 3,
"name": "GET Request",
"description": "",
"id": "get-request",
"type": "scenario",
"keyword": "Scenario",
"steps": [
{
"name": "url 'https://reqres.in/api/users/2'",
"result": {
"duration": 1949100,
"status": "passed"
},
"match": {
"location": "karate",
"arguments": []
},
"keyword": "Given",
"line": 4
},
{
"name": "method GET",
"result": {
"duration": 1208456200,
"status": "passed"
},
"match": {
"location": "karate",
"arguments": []
},
"keyword": "When",
"line": 5
},
{
"name": "status 200",
"result": {
"duration": 16100,
"status": "passed"
},
"match": {
"location": "karate",
"arguments": []
},
"keyword": "Then",
"line": 6
}
],
"tags": []
}
],
"name": "feature/main.feature",
"description": "Testing GET API",
"id": "testing-get-api",
"keyword": "Feature",
"uri": "feature/main.feature"
}
]
The TestRunner Class:
public class TestRunner {
@Test
void testParallel() {
ArrayList list = new ArrayList();
Results results = Runner.path("classpath:features/sample.feature").parallel(5);
Stream<FeatureResult> res = results.getFeatureResults();
res.forEach(action -> {
JSONObject jsonObj = new JSONObject(action.toCucumberJson());
System.out.println(jsonObj);
}
}
}
Sample Feature file:
Feature: Testing GET API
Scenario: GET Request
Given url 'https://reqres.in/api/users/2'
When method GET
Then status 200
Is there a way to get the json report as expected with the before and after keywords?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设这是空手道不支持的。欢迎您提出问题并提交PR(贡献代码)。
有关类似的讨论,请参阅以下线程: https://github.com/karatelabs/karatelabs/karate/karate/sissues/sissues/issues /1980
Assume this is not supported by Karate. You are welcome to file an issue and make a case for and submit a PR (contribute code).
For a similar discussion, refer this thread: https://github.com/karatelabs/karate/issues/1980