Skip to content

Commit 106e6fd

Browse files
committed
all tests passing, legacy preload works
1 parent e37429c commit 106e6fd

File tree

8 files changed

+90
-61
lines changed

8 files changed

+90
-61
lines changed

packages/selenium-ide/src/browser/windows/PlaybackWindow/preload.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ preload({
3535
},
3636
})
3737
window.addEventListener('DOMContentLoaded', async () => {
38+
const plugins = await api.plugins.listPreloadPaths()
39+
for (const plugin of plugins) {
40+
__non_webpack_require__(plugin)
41+
}
3842
webFrame.executeJavaScript(`
3943
Object.defineProperty(navigator, 'webdriver', {
4044
get () {

packages/selenium-ide/src/main/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,7 @@ app.on('ready', async () => {
3232
connectSessionLogging(session)
3333
await session.system.startup()
3434

35-
process.on('SIGINT', async () => {
36-
await session.system.shutdown()
37-
if (session.system.isDown) {
38-
await session.system.quit()
39-
}
40-
})
35+
process.on('SIGINT', () => app.quit())
4136
app.on('open-file', async (_e, path) => {
4237
// Instantiate the session
4338
await session.projects.load(path)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ export default class DriverController extends BaseController {
186186
}
187187

188188
async stopProcess(): Promise<null | string> {
189+
await this.session.recorder.stop()
190+
await Promise.all(
191+
this.session.playback.playbacks.map((playback) => playback.cleanup())
192+
)
189193
await this.session.windows.closeAllPlaybackWindows()
190194
await this.session.driver.executor?.cleanup()
191195
if (this.driverProcess) {

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

Lines changed: 71 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,32 @@ export default class PlaybackController extends BaseController {
4747
if (useBidi) {
4848
const handles = await driver.getAllWindowHandles()
4949
if (!handles.length) {
50-
const playbackPos = await this.session.store.get('windowPositionPlayback')
50+
const playbackPos = await this.session.store.get(
51+
'windowPositionPlayback'
52+
)
5153
const playbackSize = await this.session.store.get('windowSizePlayback')
5254
await driver.switchTo().newWindow('tab')
53-
await driver.manage().window().setPosition(...playbackPos)
54-
await driver.manage().window().setSize(...playbackSize)
55+
await driver
56+
.manage()
57+
.window()
58+
.setPosition(...playbackPos)
59+
await driver
60+
.manage()
61+
.window()
62+
.setSize(...playbackSize)
5563
const windowDimensionCache = setInterval(async () => {
5664
const handles = await driver.getAllWindowHandles()
5765
if (!handles.length) {
5866
clearInterval(windowDimensionCache)
5967
}
6068
const pos = await driver.manage().window().getPosition()
6169
const size = await driver.manage().window().getSize()
62-
await this.session.store.set('windowPositionPlayback', [pos.x, pos.y])
63-
await this.session.store.set('windowSizePlayback', [size.width, size.height])
64-
}, 1000);
70+
await this.session.store.set('windowPositionPlayback', [pos.x, pos.y])
71+
await this.session.store.set('windowSizePlayback', [
72+
size.width,
73+
size.height,
74+
])
75+
}, 1000)
6576
}
6677
return
6778
}
@@ -151,37 +162,48 @@ export default class PlaybackController extends BaseController {
151162
}
152163
}
153164

165+
async getPlayback(testID?: string) {
166+
const browserInfo = this.session.store.get('browserInfo')
167+
const allowMultiplePlaybacks =
168+
(await this.isParallel()) && this.testQueue.length
169+
const makeNewPlayback = allowMultiplePlaybacks || !this.playbacks.length
170+
if (makeNewPlayback) {
171+
const playback = new Playback({
172+
baseUrl: this.session.projects.project.url,
173+
executor: await this.session.driver.build({
174+
browser: browserInfo.browser,
175+
}),
176+
getTestByName: (name: string) => this.session.tests.getByName(name),
177+
logger: console,
178+
variables: new Variables(),
179+
options: {
180+
delay: this.session.projects.project.delay || 0,
181+
},
182+
})
183+
await playback.init()
184+
const EE = playback['event-emitter']
185+
EE.addListener(
186+
PlaybackEvents.PLAYBACK_STATE_CHANGED,
187+
this.handlePlaybackStateChanged(
188+
playback,
189+
allowMultiplePlaybacks ? testID : null
190+
)
191+
)
192+
EE.addListener(
193+
PlaybackEvents.COMMAND_STATE_CHANGED,
194+
this.handleCommandStateChanged
195+
)
196+
this.playbacks.push(playback)
197+
return playback
198+
}
199+
return this.playbacks[0]
200+
}
201+
154202
async play(testID: string, playRange = PlaybackController.defaultPlayRange) {
155203
this.playingTest = testID
156204
this.playRange = playRange
157205
this.isPlaying = true
158-
/**
159-
* Create playback if none exists
160-
*/
161-
const browserInfo = this.session.store.get('browserInfo')
162-
const playback = new Playback({
163-
baseUrl: this.session.projects.project.url,
164-
executor: await this.session.driver.build({
165-
browser: browserInfo.browser,
166-
}),
167-
getTestByName: (name: string) => this.session.tests.getByName(name),
168-
logger: console,
169-
variables: new Variables(),
170-
options: {
171-
delay: this.session.projects.project.delay || 0,
172-
},
173-
})
174-
await playback.init()
175-
const EE = playback['event-emitter']
176-
EE.addListener(
177-
PlaybackEvents.PLAYBACK_STATE_CHANGED,
178-
this.handlePlaybackStateChanged(playback, testID)
179-
)
180-
EE.addListener(
181-
PlaybackEvents.COMMAND_STATE_CHANGED,
182-
this.handleCommandStateChanged
183-
)
184-
this.playbacks.push(playback)
206+
const playback = await this.getPlayback(testID)
185207
/**
186208
* If not ending at end of test, use playTo command
187209
* or playSingleCommand if just one command specified.
@@ -190,7 +212,7 @@ export default class PlaybackController extends BaseController {
190212
if (playRange[1] !== -1) {
191213
const test = this.session.tests.getByID(testID)
192214
if (playRange[0] === playRange[1]) {
193-
await playback.playSingleCommand(test.commands[playRange[0]])
215+
await playback.playSingleCommand(test.commands[playRange[0]])
194216
} else {
195217
await playback.playTo(test, playRange[1], playRange[0])
196218
}
@@ -201,6 +223,17 @@ export default class PlaybackController extends BaseController {
201223
}
202224
}
203225

226+
async isParallel() {
227+
const {
228+
project: { suites },
229+
state: { activeSuiteID },
230+
} = await this.session.state.get()
231+
this.playingSuite = activeSuiteID
232+
const suite = suites.find(hasID(activeSuiteID))
233+
this.testQueue = suite?.tests ?? []
234+
return suite?.parallel ?? false
235+
}
236+
204237
async playSuite() {
205238
const {
206239
project: { suites },
@@ -248,9 +281,11 @@ export default class PlaybackController extends BaseController {
248281
}
249282

250283
handlePlaybackStateChanged =
251-
(playback: Playback, testID: string) =>
284+
(playback: Playback, testID: string | null = null) =>
252285
async (e: PlaybackEventShapes['PLAYBACK_STATE_CHANGED']) => {
253-
const testName = this.session.tests.getByID(testID)?.name
286+
const testName = this.session.tests.getByID(
287+
testID || this.session.state.state.activeTestID
288+
)?.name
254289
console.debug(
255290
`Playing state changed ${e.state} for test ${testName}`,
256291
this.playingSuite

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ import {
88
LocatorFields,
99
RecordNewCommandInput,
1010
} from '@seleniumhq/side-api'
11-
import { randomInt, randomUUID } from 'crypto'
11+
import { randomUUID } from 'crypto'
1212
import { relative } from 'node:path'
1313
import BaseController from '../Base'
1414
import { BrowserWindow } from 'electron'
15-
import { WebDriverExecutor } from '@seleniumhq/side-runtime'
1615

1716
const uninitializedWindows = ['data:,', 'about:blank']
1817

@@ -54,7 +53,6 @@ const getFrameTraversalCommands = (
5453
}
5554

5655
export default class RecorderController extends BaseController {
57-
driver!: WebDriverExecutor
5856
windowIDs: number[] = []
5957

6058
async recordNewCommand(
@@ -65,6 +63,7 @@ export default class RecorderController extends BaseController {
6563
return null
6664
}
6765
const activeWindowHandleID = getActiveWindowHandleID(session) || 'root'
66+
console.log(activeWindowHandleID, session.project.tests[0].commands)
6867
const commands = []
6968
if (activeWindowHandleID != cmd.winHandleId) {
7069
const selectWindowCommand: CommandShape = {
@@ -102,16 +101,6 @@ export default class RecorderController extends BaseController {
102101
)
103102
}
104103

105-
async handleNewWindow() {
106-
const session = await this.session.state.get()
107-
if (session.state.status !== 'recording') return
108-
const newWindowID = `win${randomInt(1, 9999)}`
109-
this.session.api.recorder.onNewWindow.dispatchEvent(
110-
newWindowID,
111-
randomUUID()
112-
)
113-
}
114-
115104
async requestSelectElement(activate: boolean, fieldName: LocatorFields) {
116105
this.session.windows.getLastPlaybackWindow().focus()
117106
this.session.api.recorder.onRequestSelectElement.dispatchEvent(
@@ -159,15 +148,17 @@ export default class RecorderController extends BaseController {
159148
newStepID: string
160149
windowHandle: string | null
161150
} | null> {
151+
const playback = await this.session.playback.getPlayback()
152+
const executor = playback.executor
153+
const driver = executor.driver
162154
const useBidi = this.session.store.get('browserInfo.useBidi')
163155
const newStepID = randomUUID()
164-
this.driver = await this.session.driver.build()
165156
if (useBidi) {
166-
const firstWindowURL = await this.driver.driver.getCurrentUrl()
157+
const firstWindowURL = await driver.getCurrentUrl()
167158
if (uninitializedWindows.includes(firstWindowURL)) {
168-
await this.driver.doOpen(this.session.projects.project.url)
159+
await executor.doOpen(this.session.projects.project.url)
169160
}
170-
const windowHandle = await this.driver.driver.getWindowHandle()
161+
const windowHandle = await driver.getWindowHandle()
171162
return { newStepID, windowHandle }
172163
}
173164

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ export default class WindowsController extends BaseController {
251251
this.playbackWindows.push(window)
252252
window.webContents.insertCSS(playbackCSS)
253253
window.webContents.setWindowOpenHandler(() => {
254-
this.session.recorder.handleNewWindow()
255254
return {
256255
action: 'allow',
257256
overrideBrowserWindowOptions: playbackWindowOptions,

packages/side-runtime/src/__tests__/playback.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ describe('Playback', () => {
421421
value: '',
422422
})
423423
await playback.resume()
424+
await psetTimeout(10)
424425
expect(executor.doOpen).toHaveBeenCalledTimes(4)
425426
})
426427

packages/side-runtime/src/webdriver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export default class WebDriverExecutor {
191191
}
192192

193193
async cleanup() {
194-
if (this.initialized) {
194+
if (this.driver) {
195195
await this.driver.quit()
196196
// @ts-expect-error
197197
this.driver = undefined

0 commit comments

Comments
 (0)