Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] - add variables property to insert keyword, passing variables to insert script #126

Merged
merged 1 commit into from
Feb 12, 2024
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
5 changes: 5 additions & 0 deletions examples/structure/fragments/group.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fragment {
group loops: var_inner_loops, users: var_inner_users, {
http 'GET /api/books'
}
}
2 changes: 2 additions & 0 deletions examples/structure/script.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ start {
insert 'fragments/loop.groovy'
}

insert 'fragments/group.groovy', variables: ["var_inner_users": 10, "var_inner_loops": 10]

summary(file: 'script.jtl', enabled: true)

// insert common configuration for backed listener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,22 @@ abstract class AbstractTestElementFragmentFactory extends AbstractFactory implem
URL url = this.class.classLoader.getResource(file)

// pass the current builder to script evaluation so we have same validation rule applied and automatically add children to current parent element
if (config.variables) {
config.variables.each { String variableName, Object variableValue ->
builder.setVariable(variableName, variableValue)
}
}

groovyShell.context.setProperty("builder", builder)
Object instance = groovyShell.evaluate(url.toURI())

// remove to keep scope of variables
if (config.variables) {
config.variables.each { String variableName, Object variableValue ->
builder.removeVariable(variableName)
}
}

// clear groovyShell context
groovyShell.context.setProperty("builder", null)
return instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ final class DslDefinition {
// common
static final KeywordDefinition INSERT = keyword('insert', KeywordCategory.OTHER) {
property(name: 'file', type: String, required: false, defaultValue: null)
property(name: 'variables', type: Map, required: false, defaultValue: [:])
leaf()
valueIsProperty()
}
Expand Down
Loading