Possible solution for Global variables (#1289)

fix for #1164

This takes enviroments called "Global" or "global" and appends them
after the current scripts.

Seems to work, but proabbly a cleaner way to acheive

Co-authored-by: Liyas Thomas <liyascthomas@gmail.com>
This commit is contained in:
Scott Dutton
2020-10-19 03:11:01 +01:00
committed by GitHub
parent da92fd705b
commit 37f914d1cc
2 changed files with 20 additions and 4 deletions

View File

@@ -34,7 +34,9 @@
:environmentIndex="index"
:environment="environment"
@edit-environment="editEnvironment(environment, index)"
@select-environment="$emit('use-environment', environment)"
@select-environment="
$emit('use-environment', { environment: environment, environments: environments })
"
/>
</li>
</ul>

View File

@@ -1829,14 +1829,28 @@ export default {
},
},
methods: {
useSelectedEnvironment(environment) {
useSelectedEnvironment(args) {
let environment = args.environment
let environments = args.environments
let preRequestScriptString = ""
for (let variable of environment.variables) {
preRequestScriptString =
preRequestScriptString + `pw.env.set('${variable.key}', '${variable.value}');\n`
preRequestScriptString += `pw.env.set('${variable.key}', '${variable.value}');\n`
}
for (let env of environments) {
if (env.name === environment.name) {
continue
}
if (env.name === "Globals" || env.name === "globals") {
preRequestScriptString += this.useSelectedEnvironment({
environment: env,
environments: environments,
})
}
}
this.preRequestScript = preRequestScriptString
this.showPreRequestScript = true
return preRequestScriptString
},
checkCollections() {
const checkCollectionAvailability =