Skip to content

Commit e78d166

Browse files
author
David Haeffner
committed
Fixed a bug in control flow that prevented commands at the end of a loop from linking back to the start of the loop. Fixes #559.
1 parent d018624 commit e78d166

File tree

2 files changed

+54
-14
lines changed

2 files changed

+54
-14
lines changed

packages/selenium-ide/src/neo/__test__/playback/playback-tree/playback-tree.spec.js

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,27 @@ describe('Control Flow', () => {
116116
expect(stack[2].right).toBeUndefined()
117117
expect(stack[2].left).toBeUndefined()
118118
})
119+
test('while-command-command-end', () => {
120+
let input = [
121+
createCommand(ControlFlowCommandNames.while),
122+
createCommand('command'),
123+
createCommand('command'),
124+
createCommand(ControlFlowCommandNames.end),
125+
]
126+
let stack = createCommandNodesFromCommandStack(input)
127+
expect(stack[0].next).toBeUndefined()
128+
expect(stack[0].right).toEqual(stack[1])
129+
expect(stack[0].left).toEqual(stack[3])
130+
expect(stack[1].next).toEqual(stack[2])
131+
expect(stack[1].right).toBeUndefined()
132+
expect(stack[1].left).toBeUndefined()
133+
expect(stack[2].next).toEqual(stack[0])
134+
expect(stack[2].right).toBeUndefined()
135+
expect(stack[2].left).toBeUndefined()
136+
expect(stack[3].next).toBeUndefined()
137+
expect(stack[3].right).toBeUndefined()
138+
expect(stack[3].left).toBeUndefined()
139+
})
119140
test('while-if-end-end', () => {
120141
let input = [
121142
createCommand(ControlFlowCommandNames.while), // 0
@@ -141,26 +162,34 @@ describe('Control Flow', () => {
141162
expect(stack[4].right).toBeUndefined()
142163
expect(stack[4].left).toBeUndefined()
143164
})
144-
test('while-command-command-end', () => {
165+
test('while-if-end-command-end', () => {
145166
let input = [
146-
createCommand(ControlFlowCommandNames.while),
147-
createCommand('command'),
148-
createCommand('command'),
149-
createCommand(ControlFlowCommandNames.end),
167+
createCommand(ControlFlowCommandNames.while), // 0
168+
createCommand(ControlFlowCommandNames.if), // 1
169+
createCommand('command'), // 2
170+
createCommand(ControlFlowCommandNames.end), // 3
171+
createCommand('command'), // 4
172+
createCommand(ControlFlowCommandNames.end), // 5
150173
]
151174
let stack = createCommandNodesFromCommandStack(input)
152175
expect(stack[0].next).toBeUndefined()
153176
expect(stack[0].right).toEqual(stack[1])
154-
expect(stack[0].left).toEqual(stack[3])
155-
expect(stack[1].next).toEqual(stack[2])
156-
expect(stack[1].right).toBeUndefined()
157-
expect(stack[1].left).toBeUndefined()
158-
expect(stack[2].next).toEqual(stack[0])
177+
expect(stack[0].left).toEqual(stack[5])
178+
expect(stack[1].next).toBeUndefined()
179+
expect(stack[1].right).toEqual(stack[2])
180+
expect(stack[1].left).toEqual(stack[3])
181+
expect(stack[2].next).toEqual(stack[3])
159182
expect(stack[2].right).toBeUndefined()
160183
expect(stack[2].left).toBeUndefined()
161-
expect(stack[3].next).toBeUndefined()
184+
expect(stack[3].next).toEqual(stack[4])
162185
expect(stack[3].right).toBeUndefined()
163186
expect(stack[3].left).toBeUndefined()
187+
expect(stack[4].next).toEqual(stack[0])
188+
expect(stack[4].right).toBeUndefined()
189+
expect(stack[4].left).toBeUndefined()
190+
expect(stack[5].next).toBeUndefined()
191+
expect(stack[5].right).toBeUndefined()
192+
expect(stack[5].left).toBeUndefined()
164193
})
165194
test('if-command-while-command-end-end', () => {
166195
let input = [

packages/selenium-ide/src/neo/playback/playback-tree/index.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,22 @@ function trackBranchOpen(commandNode, nextCommandNode, stack, state) {
126126
}
127127

128128
function trackBranchClose(commandNode, nextCommandNode, stack, state) {
129-
let _nextNode = nextCommandNode
130129
state.pop()
131130
const top = state.top()
132-
if (top && ControlFlowCommandChecks.isLoop(top)) _nextNode = stack[top.index]
133-
connectNext(commandNode, _nextNode, stack, state)
131+
let nextCommandNodeOverride
132+
if (
133+
top &&
134+
ControlFlowCommandChecks.isLoop(top) &&
135+
nextCommandNode &&
136+
ControlFlowCommandChecks.isEnd(nextCommandNode.command)
137+
)
138+
nextCommandNodeOverride = stack[top.index]
139+
connectNext(
140+
commandNode,
141+
nextCommandNodeOverride ? nextCommandNodeOverride : nextCommandNode,
142+
stack,
143+
state
144+
)
134145
}
135146

136147
function connectConditionalForBranchOpen(

0 commit comments

Comments
 (0)