Skip to content

Commit 92676b4

Browse files
authored
MOB-44726: Add possibility to. add customer reporters (#1962)
* MOB-44726: Fix playwright custom reporter * MOB-44726: Add possibility to. add customer reporters
1 parent 10fae44 commit 92676b4

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

bzt/modules/javascript.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,24 @@ def startup(self):
149149

150150
reporter = "@taurus/playwright-custom-reporter"
151151

152+
# Add custom reporters if specified in scenario config
153+
custom_reporters = self.get_scenario().get("reporters", [])
154+
has_additional_reporter = False
155+
if custom_reporters and isinstance(custom_reporters, list):
156+
# Sanitize reporter names for command line usage
157+
safe_reporters = [r.translate(str.maketrans("", "", " \t\r\n\v\f'\""))
158+
for r in custom_reporters if r and isinstance(r, str)]
159+
if safe_reporters:
160+
reporter = reporter + "," + ",".join(safe_reporters)
161+
has_additional_reporter = True
162+
152163
# self.env.set({"TAURUS_PWREPORT_VERBOSE": "true"})
153-
# TODO: set to false if we will add support for customer reporter
154-
# - keep stdout to customer reporter (or default)
155-
self.env.set({"TAURUS_PWREPORT_STDOUT": "true"})
164+
# Keep stdout for custom reporters if any
165+
self.env.set({"TAURUS_PWREPORT_STDOUT": "true" if not has_additional_reporter else "false"})
156166
self.env.set({"TAURUS_PWREPORT_DIR": self.engine.artifacts_dir})
157167
if max_duration:
158168
self.env.set({"TAURUS_PWREPORT_DURATION": str(int(max_duration * 1000))})
159-
options = ["--reporter " + reporter,
169+
options = ["--reporter \"" + reporter + "\"",
160170
"--output " + self.engine.artifacts_dir + "/test-output",
161171
"--workers " + str(concurrency),
162172
"--repeat-each " + str(repeat_each)]

bzt/resources/playwright-custom-reporter/playwright-custom-reporter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class TaurusReporter {
4040
}
4141

4242
if (fs.existsSync(this.options.outputFile)) {
43-
fs.rmSync(p, {
43+
fs.rmSync(this.options.outputFile, {
4444
force: true,
4545
maxRetries: 2
4646
});

tests/unit/modules/_selenium/test_javascript.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,35 @@ def test_command_line(self):
263263
self.assertIn("--repeat-each 30", self.CMD_LINE)
264264
self.assertIn("--workers 10", self.CMD_LINE)
265265
self.assertIn("-project=firefox", self.CMD_LINE)
266+
self.assertIn("-reporter \"@taurus/playwright-custom-reporter\"", self.CMD_LINE)
267+
self.assertIn("-g 'has title'", self.CMD_LINE)
268+
self.assertEqual('60000', self.ENV.get("TAURUS_PWREPORT_DURATION", "undefined"))
269+
270+
def test_command_line_additional_reporter(self):
271+
self.simple_run({
272+
'execution': {
273+
'iterations': 3,
274+
'concurrency': 10,
275+
'hold-for': '1m',
276+
'settings': {
277+
'env': {
278+
'BASE_URL': 'https://blazedemo.com/'
279+
}
280+
},
281+
'scenario': {
282+
"script": RESOURCES_DIR + "playwright",
283+
'browser': 'firefox',
284+
'test': 'has title',
285+
'reporters': ['"json" ']
286+
},
287+
'executor': 'playwright',
288+
},
289+
})
290+
self.assertIn("npx playwright test", self.CMD_LINE)
291+
self.assertIn("--repeat-each 30", self.CMD_LINE)
292+
self.assertIn("--workers 10", self.CMD_LINE)
293+
self.assertIn("-project=firefox", self.CMD_LINE)
294+
self.assertIn("-reporter \"@taurus/playwright-custom-reporter,json\"", self.CMD_LINE)
266295
self.assertIn("-g 'has title'", self.CMD_LINE)
267296
self.assertEqual('60000', self.ENV.get("TAURUS_PWREPORT_DURATION", "undefined"))
268297

0 commit comments

Comments
 (0)