Skip to content

Commit d098179

Browse files
committed
work towards using bidi and electron side by side
1 parent 560ec36 commit d098179

File tree

46 files changed

+1162
-473
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1162
-473
lines changed

packages/selenium-ide/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@
9999
"@emotion/react": "^11.11.1",
100100
"@emotion/styled": "^11.11.0",
101101
"@fontsource/roboto": "^5.0.8",
102-
"@mui/icons-material": "^5.14.9",
103-
"@mui/material": "^5.14.10",
102+
"@mui/icons-material": "^5.15.0",
103+
"@mui/material": "^5.15.0",
104104
"@seleniumhq/code-export-csharp-nunit": "^4.0.0-alpha.1",
105105
"@seleniumhq/code-export-csharp-xunit": "^4.0.0-alpha.1",
106106
"@seleniumhq/code-export-java-junit": "^4.0.0-alpha.1",

packages/selenium-ide/src/browser/api/driver.ts renamed to packages/selenium-ide/src/browser/api/bidi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const api: Api = processApi((path: string) => {
1111
return Handler()(path)
1212
})
1313

14+
export { BrowserApiMutators } from './mutator'
1415
export { Api } from '@seleniumhq/side-api'
1516

1617
export default api

packages/selenium-ide/src/browser/api/classes/DriverEventListener.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { BaseListener, VariadicArgs } from '@seleniumhq/side-api'
2-
import { sendMessage } from './DriverUtils'
32

43
type DriverEventShape<PARAMS> = {
54
path: string
@@ -13,12 +12,12 @@ const baseListener = <ARGS extends VariadicArgs>(
1312
return {
1413
addListener(listener) {
1514
console.debug(path, 'listener added')
16-
sendMessage(`${path}.addListener`)
1715
listeners.push(listener)
1816
},
1917
dispatchEvent(...args) {
2018
console.debug(path, 'dispatching event')
21-
listeners.forEach((fn) => fn(...args))
19+
const results = listeners.map((fn) => fn(...args))
20+
return results;
2221
},
2322
hasListener(listener) {
2423
return listeners.includes(listener)
@@ -29,7 +28,6 @@ const baseListener = <ARGS extends VariadicArgs>(
2928
if (index === -1) {
3029
throw new Error(`Unable to remove listener for ${path} ${listener}`)
3130
}
32-
sendMessage(`${path}.removeListener`)
3331
console.debug(path, 'listener removed')
3432
listeners.splice(index, 1)
3533
},

packages/selenium-ide/src/browser/api/classes/DriverHandler.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
} from '@seleniumhq/side-api'
66
import { sendMessage } from './DriverUtils'
77

8+
export const resolversByID: Record<string, (...args: any[]) => void> = {}
9+
810
const doAPI = async <HANDLER extends ApiPromiseHandler>(
911
path: string,
1012
...args: Parameters<HANDLER>
@@ -18,7 +20,8 @@ const doAPI = async <HANDLER extends ApiPromiseHandler>(
1820
}
1921
}
2022
console.debug('Emitting to server', path, 'with args', args)
21-
sendMessage({ path, args })
23+
const id = sendMessage({ path, args })
24+
resolversByID[id] = resolve
2225
})
2326

2427
const Handler =
@@ -28,6 +31,7 @@ const Handler =
2831
...args: Parameters<HANDLER>
2932
): Promise<ThenArg<ReturnType<HANDLER>>> => {
3033
console.debug(path, 'api called', ...(args as any))
34+
console.info('SELENIUM_IDE_COMMAND:', path, ...(args as any))
3135
const result = await doAPI<HANDLER>(path, ...args)
3236
console.debug(path, 'api complete', result)
3337
return result
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
export const UniqueIdentifier = '!!!SELENIUM_IDE_IDENTIFIER_HERE!!!'
22

3-
export const sendMessage = (message: any) => {
4-
console.log(UniqueIdentifier + JSON.stringify(message))
3+
type Message = {
4+
path: string
5+
args: any[]
6+
}
7+
8+
let id = 0
9+
export const sendMessage = (message: Message) => {
10+
const nextID = id++
11+
console.log(UniqueIdentifier + JSON.stringify({ ...message, id: nextID }))
12+
return nextID
513
}

packages/selenium-ide/src/browser/api/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Api } from '@seleniumhq/side-api'
22
import { processApi } from '@seleniumhq/side-api'
3-
import EventListener from './classes/DriverEventListener'
4-
import Handler from './classes/DriverHandler'
3+
import EventListener from './classes/EventListener'
4+
import Handler from './classes/Handler'
55

66
const api: Api = processApi((path: string) => {
77
const trailingSegment: string = path.split('.').pop() as string
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import preload from './preload'
2+
import api from 'browser/api/bidi'
3+
4+
export default preload(api)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import api from 'browser/api'
2+
import { contextBridge } from 'electron'
3+
import preload from './preload'
4+
5+
export default preload(api, () => {
6+
/**
7+
* Binds our API on initialization
8+
*/
9+
process.once('loaded', async () => {
10+
/**
11+
* Expose it in the main context
12+
*/
13+
contextBridge.exposeInMainWorld('sideAPI', window.sideAPI)
14+
})
15+
})

packages/selenium-ide/src/browser/helpers/preload.ts

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,25 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717
import type { Api } from '@seleniumhq/side-api'
18-
import api, { BrowserApiMutators } from 'browser/api'
18+
import { BrowserApiMutators } from 'browser/api'
1919
import mutators from 'browser/api/mutator'
20-
import { contextBridge } from 'electron'
20+
import { noop } from 'lodash/fp'
2121

2222
export type NestedPartial<API> = {
2323
[K in keyof API]?: API[K] extends Record<string, unknown>
2424
? NestedPartial<API[K]>
2525
: API[K]
2626
}
2727

28-
export default (
29-
apiSubset: NestedPartial<Api> & { mutators: NestedPartial<BrowserApiMutators> } = {
30-
...api,
31-
mutators,
32-
},
33-
isElectron: boolean = true
34-
) => {
35-
window.sideAPI = apiSubset as Api & { mutators: BrowserApiMutators }
36-
37-
/**
38-
* Binds our API on initialization
39-
*/
40-
process.once('loaded', async () => {
41-
/**
42-
* Expose it in the main context
43-
*/
44-
if (isElectron) {
45-
contextBridge.exposeInMainWorld('sideAPI', window.sideAPI)
46-
}
47-
})
48-
}
28+
export default (api: Api, cb = noop) =>
29+
(
30+
apiSubset: NestedPartial<Api> & {
31+
mutators: NestedPartial<BrowserApiMutators>
32+
} = {
33+
...api,
34+
mutators,
35+
},
36+
) => {
37+
window.sideAPI = apiSubset as Api & { mutators: BrowserApiMutators }
38+
cb()
39+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react'
2-
import ReactDOM from 'react-dom'
2+
import {createRoot} from 'react-dom/client'
33

44
export default (Component: React.FC | React.ComponentClass) => {
55
document.addEventListener('DOMContentLoaded', () => {
66
const domContainer = document.querySelector('#root')
7-
ReactDOM.render(React.createElement(Component), domContainer)
7+
const root = createRoot(domContainer!)
8+
root.render(React.createElement(Component))
89
});
910
}

0 commit comments

Comments
 (0)