Skip to content

Commit 2f8e336

Browse files
committed
little stabilizations around recorder
1 parent 24a2030 commit 2f8e336

File tree

3 files changed

+54
-39
lines changed

3 files changed

+54
-39
lines changed

packages/selenium-ide/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@seleniumhq/selenium-ide",
3-
"version": "4.0.0-alpha.51",
3+
"version": "4.0.0-alpha.52",
44
"private": true,
55
"description": "Selenium IDE electron app",
66
"author": "Todd <[email protected]>",

packages/selenium-ide/src/main/session/controllers/Recorder/index.ts

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { CommandShape } from '@seleniumhq/side-model'
2-
import { getActiveCommand, getActiveTest, getActiveCommandIndex } from '@seleniumhq/side-api/dist/helpers/getActiveData'
3-
import { LocatorFields, CoreSessionData, RecordNewCommandInput } from '@seleniumhq/side-api'
2+
import {
3+
getActiveCommand,
4+
getActiveTest,
5+
getActiveCommandIndex,
6+
} from '@seleniumhq/side-api/dist/helpers/getActiveData'
7+
import {
8+
LocatorFields,
9+
CoreSessionData,
10+
RecordNewCommandInput,
11+
} from '@seleniumhq/side-api'
412
import { randomInt, randomUUID } from 'crypto'
513
import { relative } from 'node:path'
614
import BaseController from '../Base'
@@ -46,16 +54,17 @@ const getFrameTraversalCommands = (
4654
const getLastActiveWindowHandleId = (session: CoreSessionData): string => {
4755
const activeTest = getActiveTest(session)
4856
const activeIndex = getActiveCommandIndex(session)
49-
console.log(activeTest, activeIndex)
50-
const commands = activeTest.commands
51-
for (let i = activeIndex; i >= 0; i--) {
52-
let item = commands[i]
53-
if (item.command == 'selectWindow') {
54-
let target = item.target as string
55-
return target.substring('handle=${'.length, target.length - 1)
56-
}
57-
if (item.command == 'storeWindowHandle') {
58-
return item.target as string
57+
if (activeIndex > -1) {
58+
const commands = activeTest.commands
59+
for (let i = activeIndex; i >= 0; i--) {
60+
let item = commands[i]
61+
if (item.command == 'selectWindow') {
62+
let target = item.target as string
63+
return target.substring('handle=${'.length, target.length - 1)
64+
}
65+
if (item.command == 'storeWindowHandle') {
66+
return item.target as string
67+
}
5968
}
6069
}
6170

@@ -72,14 +81,12 @@ export default class RecorderController extends BaseController {
7281
return null
7382
}
7483
const commands = []
75-
if (
76-
getLastActiveWindowHandleId(session) != cmd.winHandleId
77-
) {
84+
if (getLastActiveWindowHandleId(session) != cmd.winHandleId) {
7885
const selectWindowCommand: CommandShape = {
7986
id: randomUUID(),
8087
command: 'selectWindow',
81-
target: 'handle=${'+cmd.winHandleId+'}',
82-
value: ''
88+
target: 'handle=${' + cmd.winHandleId + '}',
89+
value: '',
8390
}
8491
commands.push(selectWindowCommand)
8592
}
@@ -90,19 +97,21 @@ export default class RecorderController extends BaseController {
9097
targets: Array.isArray(cmd.target) ? cmd.target : [[cmd.target, '']],
9198
value: Array.isArray(cmd.value) ? cmd.value[0][0] : cmd.value,
9299
}
93-
const windows = BrowserWindow.getAllWindows();
94-
const newWindowIDs = windows.map((window) => window.id);
95-
const opensWindow = this.windowIDs.length < newWindowIDs.length;
100+
const windows = BrowserWindow.getAllWindows()
101+
const newWindowIDs = windows.map((window) => window.id)
102+
const opensWindow = this.windowIDs.length < newWindowIDs.length
96103
if (opensWindow) {
97104
mainCommand.opensWindow = true
98105
mainCommand.windowHandleName = `win${randomInt(1, 9999)}`
99106
}
100-
this.windowIDs = windows.map((window) => window.id);
107+
this.windowIDs = windows.map((window) => window.id)
101108

102-
commands.push(...getFrameTraversalCommands(
103-
session.state.recorder.activeFrame,
104-
cmd.frameLocation as string
105-
))
109+
commands.push(
110+
...getFrameTraversalCommands(
111+
session.state.recorder.activeFrame,
112+
cmd.frameLocation as string
113+
)
114+
)
106115
commands.push(mainCommand)
107116
return commands
108117
}
@@ -137,16 +146,18 @@ export default class RecorderController extends BaseController {
137146
const activeTest = getActiveTest(session)
138147
const activeIndex = getActiveCommandIndex(session)
139148

140-
const commands = activeTest.commands
141-
for (let i = activeIndex; i >= 0; i--) {
142-
let item = commands[i]
143-
if (item.opensWindow && item.windowHandleName) {
144-
return item.windowHandleName
145-
}
146-
147-
if (item.command == 'selectWindow') {
148-
let target = item.target as string
149-
return target.substring('handle=${'.length, target.length - 1)
149+
if (activeIndex > -1) {
150+
const commands = activeTest.commands
151+
for (let i = activeIndex; i >= 0; i--) {
152+
let item = commands[i]
153+
if (item.opensWindow && item.windowHandleName) {
154+
return item.windowHandleName
155+
}
156+
157+
if (item.command == 'selectWindow') {
158+
let target = item.target as string
159+
return target.substring('handle=${'.length, target.length - 1)
160+
}
150161
}
151162
}
152163
return 'root'
@@ -192,7 +203,6 @@ export default class RecorderController extends BaseController {
192203
}
193204
let url = new URL(currentCommand.target as string, state.project.url)
194205
playbackWindow.webContents.loadURL(url.toString())
195-
196206
}
197207
playbackWindow.focus()
198208
return null

packages/side-api/src/helpers/getActiveData.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,13 @@ export const getActiveCommand = (
3838
return activeTest.commands[activeCommandIndex] || defaultCommand
3939
}
4040

41-
export const getActiveCommandIndex = (session: CoreSessionData): number =>
42-
session.state.editor.selectedCommandIndexes.slice(-1)[0]
41+
export const getActiveCommandIndex = (session: CoreSessionData): number => {
42+
const commands = getActiveTest(session).commands
43+
if (!commands.length) {
44+
return -1
45+
}
46+
return session.state.editor.selectedCommandIndexes.slice(-1)[0]
47+
}
4348

4449
export const getCommandIndex = (
4550
session: CoreSessionData,

0 commit comments

Comments
 (0)