Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions qase-robotframework/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# qase-robotframework 3.4.6

## What's new

- Added support for parameters in user keywords.
- Added support for fields in user keywords.

# qase-robotframework 3.4.5

## What's new
Expand Down
18 changes: 0 additions & 18 deletions qase-robotframework/changelog_new.md

This file was deleted.

22 changes: 22 additions & 0 deletions qase-robotframework/docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ Browser Test
Close browser
```

### Adding Parameters and Fields to a User Keyword

The `qase.params` tag can also be used in user keywords to specify which Robot Framework variables should be reported as parameters.

```robotframework
*** Settings ***
Test Template Check Status

*** Keywords ***
Check Status
[Arguments] ${module}
[Tags] qase.params:[module] qase.fields:{ "severity": "critical" }
Log Checking status of module: ${module}

*** Test Cases ***
Check Status of BMS
[Tags] Q-20 qase.fields:{ "preconditions": "Module BMS is connected", "description": "Flash firmware to BMS module and check status" }
[Template] Check Status
BMS

```

---

## Ignoring a Test in Qase
Expand Down
2 changes: 1 addition & 1 deletion qase-robotframework/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "qase-robotframework"
version = "3.4.5"
version = "3.4.6"
description = "Qase Robot Framework Plugin"
readme = "README.md"
authors = [{name = "Qase Team", email = "support@qase.io"}]
Expand Down
28 changes: 24 additions & 4 deletions qase-robotframework/src/qase/robotframework/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,25 @@ def start_test(self, test, result):
self.runtime.result = Result(title=test.name, signature=test.name)
self.runtime.steps = {}

def end_user_keyword(self, data, implementation, result):
logger.debug("Ending user keyword '%s'", data.name)

test_metadata = TagParser.parse_tags(result.tags)

if test_metadata.params:
# Get argument names from the implementation
args_names = implementation.args.argument_names if hasattr(implementation.args, 'argument_names') else []
args_values = result.args if hasattr(result, 'args') else []
params: dict = {}
for param in test_metadata.params:
if param in args_names:
params[param] = args_values[args_names.index(param)]
self.runtime.result.params = params

if test_metadata.fields:
for key, value in test_metadata.fields.items():
self.runtime.result.add_field(Field(key, value))

def end_test(self, test, result):
logger.debug("Finishing test '%s'", test.name)

Expand Down Expand Up @@ -114,11 +133,12 @@ def end_test(self, test, result):
steps = self.__parse_steps(result)
self.runtime.result.add_steps(steps)

if len(test_metadata.params) > 0:
params: dict = {}
# Process parameters if they exist
if test_metadata.params:
for param in test_metadata.params:
params[param] = BuiltIn().get_variable_value(f"${{{param}}}")
self.runtime.result.params = params
param_value = BuiltIn().get_variable_value(f"${{{param}}}")
if param_value is not None:
self.runtime.result.add_param(param, param_value)

if hasattr(test, "doc"):
self.runtime.result.add_field(Field("description", test.doc))
Expand Down
10 changes: 8 additions & 2 deletions qase-robotframework/src/qase/robotframework/tag_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ def __extract_fields(tag: str) -> dict:
def __extract_params(tag: str) -> list[str]:
value = tag.split(':', 1)[-1].strip()
try:
return [item.strip() for item in value[1:-1].split(",")]
except ValueError as e:
# Remove square brackets and split by comma
if value.startswith('[') and value.endswith(']'):
params_str = value[1:-1]
return [item.strip() for item in params_str.split(",") if item.strip()]
else:
# Handle case without brackets
return [item.strip() for item in value.split(",") if item.strip()]
except (ValueError, IndexError) as e:
TagParser.__logger.error(f"Error parsing params from tag '{tag}': {e}")
return []