citrusframework / citrusframework/citrus

Accessing variables in report from TestCase object

Open
#723 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
485
Forks
155
Avg merge
4d 22h
Merged PRs (30d)
6

Description

**Citrus Version**
2.8.0

**Question**
1) I noticed some differences in how two below methods work.
`variable("a", "val1");`
and
`createVariable("b", "val2");`

When I create variables with the use of the method `variable`. I can access these variables in the test report via the `TestCase` object. But when I create variables with the use of `createVariable`, these variables are not accessible via `TestCase` object in a report.
Is this is expected behavior?

2) Is it expected that variables created in test actions are not accessible from the `TestCase` object?

**What I've tried so far**
1) I wrote the following short test:
`@CitrusTest
public void testVariables() {
variable("a", "val1");
variable("b", "val2");
createVariable("c", "val3");
createVariable("d", "val4");
}`
and I've checked the values of variables in `TestCase`.
![image](https://user-images.githubusercontent.com/10964570/83766945-4b241480-a67d-11ea-92e9-21db0f0b7d6b.png)
Only two first variables were created.

2) Custom action
```
public class CustomTestAction extends AbstractTestAction {

public CustomTestAction() {
this.setName("custom-test-action");
}

@Override
public void doExecute(TestContext context) {
Map variables = someCustomTestActions();
this.createdLocalVariable(context, variables);
this.createGlobalVariable(context, variables);
}

private Map someCustomTestActions() {
return Collections.singletonMap("myCustomVar1", "myCustomVarValue1");
}

private void createdLocalVariable(TestContext context, Map variables) {
context.getVariables().putAll(variables);
}

private void createGlobalVariable(TestContext context, Map variables) {
context.getGlobalVariables().putAll(variables);
}

}
```

Test
```
@CitrusTest
public void testCustomTestAction() {
this.run(new CustomTestAction());
}
```

Variables were created:
![image](https://user-images.githubusercontent.com/10964570/83770261-2762cd80-a681-11ea-8175-770ee43f6866.png)

No variables to access in the test report:
![image](https://user-images.githubusercontent.com/10964570/83770338-3e092480-a681-11ea-99ef-e58e805a7c90.png)

**Additional information**

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the two tests shown in the issue: testVariables and testCustomTestAction, then trace how variable(), createVariable(), TestContext variables, and global variables are exposed through the TestCase used by the report. Done means the behavior is documented or corrected so variables created through these paths have a clear, consistent report visibility.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.