Skip to content

Commit c809d49

Browse files
committed
adding var handling and env escape hatch
1 parent dd0c2be commit c809d49

File tree

9 files changed

+56
-29
lines changed

9 files changed

+56
-29
lines changed

packages/side-api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@seleniumhq/side-api",
3-
"version": "4.0.0-alpha.27",
3+
"version": "4.0.0-alpha.28",
44
"private": false,
55
"description": "Selenium IDE API command shapes and such",
66
"author": "Todd Tarsi <[email protected]>",
@@ -20,7 +20,7 @@
2020
"@seleniumhq/browser-info": "^4.0.0-alpha.1",
2121
"@seleniumhq/get-driver": "^4.0.0-alpha.2",
2222
"@seleniumhq/side-model": "^4.0.0-alpha.4",
23-
"@seleniumhq/side-runtime": "^4.0.0-alpha.27",
23+
"@seleniumhq/side-runtime": "^4.0.0-alpha.28",
2424
"lodash": "^4.17.21"
2525
},
2626
"devDependencies": {

packages/side-example-suite/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
"@seleniumhq/code-export-python-pytest": "4.0.0-alpha.2"
2222
},
2323
"devDependencies": {
24-
"@seleniumhq/side-api": "^4.0.0-alpha.26",
25-
"@seleniumhq/side-runtime": "^4.0.0-alpha.26"
24+
"@seleniumhq/side-api": "^4.0.0-alpha.28"
2625
},
2726
"repository": {
2827
"type": "git",

packages/side-example-suite/tsconfig.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
{
1818
"path": "../side-api"
1919
},
20-
{
21-
"path": "../side-runtime"
22-
}
2320
]
2421
}
2522

packages/side-runner/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "selenium-side-runner",
3-
"version": "4.0.0-alpha.56",
3+
"version": "4.0.0-alpha.57",
44
"private": false,
55
"description": "Run Selenium IDE projects in cli",
66
"repository": "https://github.com/SeleniumHQ/selenium-ide",
@@ -24,7 +24,7 @@
2424
"license": "Apache-2.0",
2525
"dependencies": {
2626
"@seleniumhq/side-model": "^4.0.0-alpha.4",
27-
"@seleniumhq/side-runtime": "^4.0.0-alpha.27",
27+
"@seleniumhq/side-runtime": "^4.0.0-alpha.28",
2828
"commander": "^11.0.0",
2929
"glob": "^10.3.1",
3030
"jest": "^29.6.0",

packages/side-runtime/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@seleniumhq/side-runtime",
3-
"version": "4.0.0-alpha.27",
3+
"version": "4.0.0-alpha.28",
44
"private": false,
55
"description": "Selenium IDE playback and execution",
66
"author": "Tomer <[email protected]>",

packages/side-runtime/src/playback-tree/command-node.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import { Fn } from '@seleniumhq/side-commons'
1919
import { CommandShape } from '@seleniumhq/side-model'
2020
import { WebDriverExecutor } from '..'
21-
import { interpolateScript } from '../preprocessors'
21+
import { interpolateScript, interpolateString } from '../preprocessors'
2222
import { CommandNodeOptions } from '../types'
2323
import Variables from '../variables'
2424
import { WebDriverExecutorCondEvalResult } from '../webdriver'
@@ -224,17 +224,20 @@ export class CommandNode {
224224
}
225225

226226
_evaluate(commandExecutor: WebDriverExecutor) {
227-
let expression = interpolateScript(
228-
this.command.target as string,
229-
commandExecutor.variables
230-
)
231227
if (ControlFlowCommandChecks.isTimes(this.command)) {
232-
const number = Math.floor(+expression)
228+
const number = Math.floor(
229+
+interpolateString(`${this.command.target}`, commandExecutor.variables)
230+
)
233231
if (isNaN(number)) {
234232
return Promise.reject(new Error('Invalid number provided as a target.'))
235233
}
236234
return this._evaluationResult({ value: this.timesVisited < number })
237-
} else if (ControlFlowCommandChecks.isForEach(this.command)) {
235+
}
236+
let expression = interpolateScript(
237+
this.command.target as string,
238+
commandExecutor.variables
239+
)
240+
if (ControlFlowCommandChecks.isForEach(this.command)) {
238241
const result = this.evaluateForEach(commandExecutor.variables)
239242
if (!result) {
240243
this.emitControlFlowChange({

packages/side-runtime/src/variables.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export default class Variables {
2222
storedVars: Map<string, any>
2323

2424
get(key: string) {
25+
if (key.startsWith('env:')) {
26+
return process.env[key.slice(4)]
27+
}
2528
return this.storedVars.get(key)
2629
}
2730

packages/side-runtime/src/webdriver.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,13 @@ WebDriverExecutor.prototype.doAssertPrompt = composePreprocessors(
16241624
WebDriverExecutor.prototype.doAssertPrompt
16251625
)
16261626

1627+
WebDriverExecutor.prototype.doAssertSelectedLabel = composePreprocessors(
1628+
interpolateString,
1629+
interpolateString,
1630+
{ targetFallback: preprocessArray(interpolateString) },
1631+
WebDriverExecutor.prototype.doAssertSelectedLabel
1632+
)
1633+
16271634
WebDriverExecutor.prototype.doAssertText = composePreprocessors(
16281635
interpolateString,
16291636
interpolateString,

tests/examples/variable-in-conditional.side

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"parallel": false,
1515
"persistSession": false,
1616
"tests": [
17+
"a1f2325b-f579-445f-97a2-a24d45816e04",
1718
"2e05c87f-fd47-43e1-bd89-7197f52e3cda"
1819
],
1920
"timeout": 30000
@@ -24,12 +25,6 @@
2425
"id": "2e05c87f-fd47-43e1-bd89-7197f52e3cda",
2526
"name": "If variable",
2627
"commands": [
27-
{
28-
"id": "73e3061e-5904-4ee7-9923-a0bb014349dd",
29-
"command": "open",
30-
"target": "/",
31-
"value": ""
32-
},
3328
{
3429
"command": "store",
3530
"target": "1",
@@ -38,16 +33,15 @@
3833
},
3934
{
4035
"command": "if",
41-
"target": "${asdf} == 1",
36+
"target": "${asdf} !== \"1\"",
4237
"value": "",
4338
"id": "67c95cc0-68ce-4019-a2eb-8f32fd6c722c"
4439
},
4540
{
46-
"command": "click",
47-
"target": "css=#gbqfbb",
48-
"value": "",
49-
"id": "6541336a-a114-42da-9443-53e1ad0027a4",
50-
"isBreakpoint": false
41+
"command": "assert",
42+
"target": "asdf",
43+
"value": "If clause succeeded without merit",
44+
"id": "4cbdebb0-f650-4919-a489-1946359d976c"
5145
},
5246
{
5347
"command": "end",
@@ -56,6 +50,30 @@
5650
"id": "52a7461f-a944-471b-bfbc-66cecfa001a8"
5751
}
5852
]
53+
},
54+
{
55+
"id": "a1f2325b-f579-445f-97a2-a24d45816e04",
56+
"name": "Times variable",
57+
"commands": [
58+
{
59+
"command": "store",
60+
"target": "1",
61+
"value": "ONE",
62+
"id": "8d34b903-0b7b-4d1e-b363-ca19bed870ce"
63+
},
64+
{
65+
"id": "ca848518-2f34-4c92-b57c-4ce37c11e1cf",
66+
"command": "times",
67+
"target": "${ONE}",
68+
"value": "3"
69+
},
70+
{
71+
"command": "end",
72+
"target": "",
73+
"value": "",
74+
"id": "bc6bffd6-0fec-4272-8aaa-7633ffb7266a"
75+
}
76+
]
5977
}
6078
],
6179
"snapshot": {

0 commit comments

Comments
 (0)