Skip to content

Commit 0b07b69

Browse files
committed
window mgmt improvement and sigint fix
sigint would previously break chromedriver even if we didnt use it similarly we would get too many windows and now we get less
1 parent 6cc2d55 commit 0b07b69

8 files changed

Lines changed: 87 additions & 61 deletions

File tree

packages/selenium-ide/src/browser/windows/Alert/controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { WindowConfig } from 'browser/types'
22

3-
const DEFAULT_WIDTH = 600
4-
const DEFAULT_HEIGHT = 600
3+
const DEFAULT_WIDTH = 400
4+
const DEFAULT_HEIGHT = 150
55

66
export const window: WindowConfig['window'] = () => ({
77
width: DEFAULT_WIDTH,

packages/selenium-ide/src/browser/windows/Alert/renderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import React from 'react'
77

88
const Prompt = () => {
99
// @ts-expect-error this exists
10-
const acceptAlert = () => window.acceptAlert(answerRef.current!.value);
10+
const acceptAlert = () => window.acceptAlert();
1111

1212
React.useEffect(() => {
1313
window.addEventListener('error', (e) => {

packages/selenium-ide/src/browser/windows/Confirm/controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { WindowConfig } from 'browser/types'
22

3-
const DEFAULT_WIDTH = 600
4-
const DEFAULT_HEIGHT = 600
3+
const DEFAULT_WIDTH = 400
4+
const DEFAULT_HEIGHT = 150
55

66
export const window: WindowConfig['window'] = () => ({
77
width: DEFAULT_WIDTH,

packages/selenium-ide/src/browser/windows/Prompt/controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { WindowConfig } from 'browser/types'
22

3-
const DEFAULT_WIDTH = 600
4-
const DEFAULT_HEIGHT = 600
3+
const DEFAULT_WIDTH = 500
4+
const DEFAULT_HEIGHT = 200
55

66
export const window: WindowConfig['window'] = () => ({
77
width: DEFAULT_WIDTH,

packages/selenium-ide/src/main/session/controllers/Driver/start.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const startDriver: StartDriver = () => (info) =>
7878
)
7979
if (fs.existsSync(driverPath)) {
8080
const driver = spawn(driverPath.replace(/\s/g, ' '), args, {
81+
detached: true,
8182
env: {},
8283
shell: false,
8384
})

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

Lines changed: 78 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { CommandShape, getActiveCommand, hasID } from '@seleniumhq/side-api'
1+
import {
2+
CommandShape,
3+
getActiveCommand,
4+
getActiveTest,
5+
hasID,
6+
} from '@seleniumhq/side-api'
27
import {
38
Playback,
49
PlaybackEvents,
@@ -169,48 +174,56 @@ export default class PlaybackController extends BaseController {
169174
// Confirm webdriver connection
170175
driver.executeScript('true')
171176
try {
172-
const handle = await driver.getWindowHandle()
173-
const existingWindow =
174-
await this.session.windows.getPlaybackWindowByHandle(handle)
175-
if (existingWindow && existingWindow.isVisible()) {
176-
await driver.switchTo().window(handle)
177+
const existingWindow = await this.session.windows.getLastPlaybackWindow()
178+
if (existingWindow!.isVisible()) {
179+
const handle = await this.session.windows.getPlaybackWindowHandleByID(existingWindow.id)
180+
await driver.switchTo().window(handle!)
177181
return
178182
}
179-
} catch (windowDoesNotExist) {}
180-
let success = false
181-
const UUID = randomUUID()
182-
const window = await this.session.windows.openPlaybackWindow({
183-
title: UUID,
184-
})
185-
await this.session.windows.arrangeWindow(
186-
window,
187-
'windowSizePlayback',
188-
'windowPositionPlayback'
189-
)
190-
const handles = await driver.getAllWindowHandles()
191-
for (let i = 0, ii = handles.length; i !== ii; i++) {
192-
const handle = handles[i]
193-
await driver.switchTo().window(handle)
194-
const title = await driver.getTitle()
195-
if (title === UUID) {
196-
await this.session.windows.registerPlaybackWindowHandle(
197-
handle,
198-
window.id
199-
)
200-
success = true
201-
break
183+
} catch (windowDoesNotExist) {
184+
let success = false
185+
const UUID = randomUUID()
186+
const window = await this.session.windows.openPlaybackWindow({
187+
title: UUID,
188+
})
189+
console.log('Opened playback window?', UUID)
190+
await this.session.windows.arrangeWindow(
191+
window,
192+
'windowSizePlayback',
193+
'windowPositionPlayback'
194+
)
195+
const handles = await driver.getAllWindowHandles()
196+
for (let i = 0, ii = handles.length; i !== ii; i++) {
197+
const handle = handles[i]
198+
await driver.switchTo().window(handle)
199+
const title = await driver.getTitle()
200+
if (title === UUID) {
201+
await this.session.windows.registerPlaybackWindowHandle(
202+
handle,
203+
window.id
204+
)
205+
success = true
206+
break
207+
}
202208
}
209+
if (!success) {
210+
throw new Error('Failed to switch to playback window')
211+
}
212+
} finally {
213+
const state = await this.session.state.get()
214+
const currentTest = getActiveTest(state)
215+
const currentCommand = getActiveCommand(state)
216+
const firstURL = new URL(
217+
currentTest.commands.find((cmd) => cmd.command === 'open')?.target ??
218+
'/',
219+
state.project.url
220+
)
221+
const url =
222+
currentCommand.command === 'open'
223+
? new URL(currentCommand.target as string, state.project.url).href
224+
: firstURL.href
225+
playback.executor.doOpen(url)
203226
}
204-
if (!success) {
205-
throw new Error('Failed to switch to playback window')
206-
}
207-
const state = await this.session.state.get()
208-
const currentCommand = getActiveCommand(state)
209-
const url =
210-
currentCommand.command === 'open'
211-
? new URL(currentCommand.target as string, state.project.url).href
212-
: state.project.url
213-
playback.executor.doOpen(url)
214227
}
215228

216229
async play(testID: string, playRange = PlaybackController.defaultPlayRange) {
@@ -246,15 +259,22 @@ export default class PlaybackController extends BaseController {
246259
})
247260
}
248261
const handleTestResolution = async () => {
249-
await promise()
250-
EE.removeListener(
251-
PlaybackEvents.PLAYBACK_STATE_CHANGED,
252-
handlePlaybackStateChanged
253-
)
254-
EE.removeListener(
255-
PlaybackEvents.COMMAND_STATE_CHANGED,
256-
this.handleCommandStateChanged
257-
)
262+
console.log('Waiting for play to finish...')
263+
try {
264+
await promise()
265+
} catch (e) {
266+
console.error(e)
267+
} finally {
268+
console.log('Play finished!')
269+
EE.removeListener(
270+
PlaybackEvents.PLAYBACK_STATE_CHANGED,
271+
handlePlaybackStateChanged
272+
)
273+
EE.removeListener(
274+
PlaybackEvents.COMMAND_STATE_CHANGED,
275+
this.handleCommandStateChanged
276+
)
277+
}
258278
}
259279
handleTestResolution()
260280
}
@@ -335,12 +355,9 @@ export default class PlaybackController extends BaseController {
335355
case 'failed':
336356
case 'finished':
337357
case 'stopped':
358+
this.playbacks.splice(this.playbacks.indexOf(playback), 1)
359+
await playback.cleanup()
338360
if (this.playingSuite) {
339-
try {
340-
await playback.executor.driver.close()
341-
} catch (e) {}
342-
this.playbacks.splice(this.playbacks.indexOf(playback), 1)
343-
await playback.cleanup()
344361
if (!this.testQueue.length) {
345362
this.playingSuite = ''
346363
this.session.api.state.onMutate.dispatchEvent('playback.stop', {
@@ -350,6 +367,14 @@ export default class PlaybackController extends BaseController {
350367
this.playNextTest()
351368
}
352369
}
370+
if (e.state === 'finished') {
371+
await this.session.api.state.updateStepSelection(
372+
0,
373+
false,
374+
false,
375+
true
376+
)
377+
}
353378
}
354379
this.session.api.playback.onPlayUpdate.dispatchEvent(e)
355380
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ export default class SystemController extends BaseController {
116116

117117
async beforeQuit() {
118118
await this.shutdown()
119-
await this.session.windows.closeAllPlaybackWindows()
120119
return this.isDown
121120
}
122121

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ export default class WindowsController extends BaseController {
223223

224224
async getPlaybackWindowByHandle(handle: string) {
225225
const id = this.handlesToIDs[handle]
226+
console.log('match?', handle, id);
226227
return this.playbackWindows.find((bw) => bw.id === id)
227228
}
228229

0 commit comments

Comments
 (0)