Skip to content

Commit

Permalink
Merge pull request #479 from radish-bdd/adding-start-and-end-time-in-…
Browse files Browse the repository at this point in the history
…cucumber-json

Adding the start time and end time of the step for cucumber json
  • Loading branch information
fliiiix authored Dec 19, 2024
2 parents 112e3d8 + de3b1b9 commit f989517
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- utcnow deprecation

### Changes
- Adding start and end time in cucumber json
- Drop Python 3.6 and Python 3.7
- Drop the `--profile` option, please use `--user-data`
- Change default marker from unix timestamp to UUIDv4
Expand Down
7 changes: 6 additions & 1 deletion radish/extensions/cucumber_json_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ def generate_ccjson(self, features, marker):
"keyword": step.sentence.split()[0],
"name": step.sentence,
"line": step.line,
"result": {"status": step.state, "duration": duration},
"result": {
"status": step.state,
"duration": duration,
"starttime": str(step.starttime if step.starttime else 0.0),
"endtime": str(step.endtime if step.endtime else 0.0),
},
}
if step.state is Step.State.FAILED:
step_json["result"]["error_message"] = step.failure.reason
Expand Down
12 changes: 12 additions & 0 deletions tests/output/cucumber-json.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"name": "Given I have the number 1",
"result": {
"duration": 343000.0,
"endtime": "2024-11-20 08:37:18.133736+00:00",
"starttime": "2024-11-20 08:37:17.255751+00:00",
"status": "passed"
}
},
Expand All @@ -24,6 +26,8 @@
"name": "And I have the number 2",
"result": {
"duration": 156000.0,
"endtime": "2024-11-20 08:37:18.133736+00:00",
"starttime": "2024-11-20 08:37:17.255751+00:00",
"status": "passed"
}
},
Expand All @@ -33,6 +37,8 @@
"name": "When I add them up with failure",
"result": {
"duration": 850000.0,
"endtime": "2024-11-20 08:37:18.133736+00:00",
"starttime": "2024-11-20 08:37:17.255751+00:00",
"error_message": "Unable to add numbers: [1, 2]",
"status": "failed"
}
Expand All @@ -43,6 +49,8 @@
"name": "Then I expect the sum to be 42",
"result": {
"duration": 73000.0,
"endtime": "2024-11-20 08:37:18.133736+00:00",
"starttime": "2024-11-20 08:37:17.255751+00:00",
"status": "skipped"
}
}
Expand All @@ -68,6 +76,8 @@
"name": "When generate cucumber report",
"result": {
"duration": 0.0,
"endtime": "2024-11-20 08:37:18.133736+00:00",
"starttime": "2024-11-20 08:37:17.255751+00:00",
"status": "skipped"
}
},
Expand All @@ -77,6 +87,8 @@
"name": "Then genreated cucumber json equals to \"cucumber-json.json\"",
"result": {
"duration": 0.0,
"endtime": "2024-11-20 08:37:18.133736+00:00",
"starttime": "2024-11-20 08:37:17.255751+00:00",
"status": "pending"
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/radish/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def generate_cucumber_report(step):
@then("genreated cucumber json equals to {expected_json_file:QuotedString}")
def proper_cucumber_json_is_generated(step, expected_json_file):
def remove_changing(d):
return {k: v for k, v in d.items() if k not in ["duration", "uri"]}
return {k: v for k, v in d.items() if k not in ["duration", "uri", "endtime", "starttime"]}

with open(world.config.cucumber_json, "r") as f_cucumber_json:
cucumber_json = json.load(f_cucumber_json, object_hook=remove_changing)
Expand Down

0 comments on commit f989517

Please sign in to comment.