Skip to content

Commit

Permalink
adding back plugin comm channel capabiltiy
Browse files Browse the repository at this point in the history
  • Loading branch information
toddtarsi committed Dec 31, 2023
1 parent 7ce32e2 commit 14d01a4
Show file tree
Hide file tree
Showing 34 changed files with 208 additions and 64 deletions.
2 changes: 1 addition & 1 deletion packages/selenium-ide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"@seleniumhq/code-export-python-pytest": "^4.0.0-alpha.4",
"@seleniumhq/code-export-ruby-rspec": "^4.0.0-alpha.3",
"@seleniumhq/get-driver": "^4.0.0-alpha.3",
"@seleniumhq/side-api": "^4.0.0-alpha.40",
"@seleniumhq/side-api": "^4.0.0-alpha.41",
"@seleniumhq/side-model": "^4.0.0-alpha.5",
"@seleniumhq/side-runtime": "^4.0.0-alpha.33",
"dnd-core": "^16.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BaseListener, VariadicArgs } from '@seleniumhq/side-api'

const baseListener = <ARGS extends VariadicArgs>(
path: string
): BaseListener<ARGS> => {
): BaseListener<ARGS> & { emitEvent: (...args: ARGS) => void } => {
const listeners: any[] = []
return {
addListener(listener) {
Expand All @@ -15,7 +15,11 @@ const baseListener = <ARGS extends VariadicArgs>(
console.debug(path, 'dispatching event')
const results = listeners.map((fn) => fn(...args))
ipcRenderer.send(`${path}.response`, results)
return results;
return results
},
emitEvent(...args) {
console.debug(path, 'emitting event')
ipcRenderer.send(`${path}.emit`, ...args)
},
hasListener(listener) {
return listeners.includes(listener)
Expand Down
43 changes: 26 additions & 17 deletions packages/selenium-ide/src/browser/windows/PlaybackWindow/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,23 @@ import { RecorderPreprocessor } from '@seleniumhq/side-api'
import api from 'browser/api'
import apiMutators from 'browser/api/mutator'
import preload from 'browser/helpers/preload'
import {cb as ElectronCallback} from 'browser/helpers/preload-electron'
import { cb as ElectronCallback } from 'browser/helpers/preload-electron'
import { webFrame } from 'electron'
import Recorder from './preload/recorder'

const recorderProcessors: RecorderPreprocessor[] = []
async function main() {
const preloads = await api.plugins.getPreloads()
for (const preload of preloads) {
eval(preload)
}
window.addEventListener('DOMContentLoaded', async () => {
const preloads = await api.plugins.getPreloads()
for (const preload of preloads) {
try {
console.debug(`Loading preload: ${preload}`)
eval(preload)
console.debug(`Loaded preload!`)
} catch (e) {
console.error(`Error loading preload: ${preload}`, e)
}
}
webFrame.executeJavaScript(`
Object.defineProperty(navigator, 'webdriver', {
get () {
Expand All @@ -44,17 +50,20 @@ async function main() {
})
}

preload(api, ElectronCallback, main)(
{
plugins: {
addRecorderPreprocessor: (fn) => {
recorderProcessors.push(fn)
},
},
recorder: api.recorder,
mutators: {
plugins: {},
recorder: apiMutators.recorder,
preload(
api,
ElectronCallback,
main
)({
channels: api.channels,
plugins: {
addRecorderPreprocessor: (fn) => {
recorderProcessors.push(fn)
},
},
)
recorder: api.recorder,
mutators: {
plugins: {},
recorder: apiMutators.recorder,
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ListSubheader, { ListSubheaderProps } from '@mui/material/ListSubheader'
import React, { FC } from 'react'

interface EditorToolbarProps extends ListSubheaderProps {
disabled?: boolean
onAdd?: () => void
onEdit?: () => void
onRemove?: () => void
Expand All @@ -24,6 +25,7 @@ const standardIconProps = {
const EditorToolbar: FC<EditorToolbarProps> = ({
children,
className = 'lh-36',
disabled = false,
onAdd,
onEdit,
onRemove,
Expand All @@ -41,7 +43,12 @@ const EditorToolbar: FC<EditorToolbarProps> = ({
{onAdd ? (
<Box sx={{ flex: 0 }}>
<Tooltip title="Add">
<IconButton {...standardIconProps} color="success" onClick={onAdd}>
<IconButton
{...standardIconProps}
color="success"
disabled={disabled}
onClick={onAdd}
>
<AddIcon />
</IconButton>
</Tooltip>
Expand All @@ -50,7 +57,12 @@ const EditorToolbar: FC<EditorToolbarProps> = ({
{onRemove ? (
<Box sx={{ flex: 0 }}>
<Tooltip title="Remove">
<IconButton {...standardIconProps} color="warning" onClick={onRemove}>
<IconButton
{...standardIconProps}
color="warning"
disabled={disabled}
onClick={onRemove}
>
<RemoveIcon />
</IconButton>
</Tooltip>
Expand All @@ -59,7 +71,12 @@ const EditorToolbar: FC<EditorToolbarProps> = ({
{onEdit ? (
<Box sx={{ flex: 0 }}>
<Tooltip title="Edit">
<IconButton {...standardIconProps} color="info" onClick={onEdit}>
<IconButton
{...standardIconProps}
color="info"
disabled={disabled}
onClick={onEdit}
>
<EditIcon />
</IconButton>
</Tooltip>
Expand All @@ -68,7 +85,12 @@ const EditorToolbar: FC<EditorToolbarProps> = ({
{onView ? (
<Box sx={{ flex: 0 }}>
<Tooltip title="View Playback Results">
<IconButton {...standardIconProps} color="info" onClick={onView}>
<IconButton
{...standardIconProps}
color="info"
disabled={disabled}
onClick={onView}
>
<VisibilityIcon />
</IconButton>
</Tooltip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ const ProjectSettings: FC<ProjectSettingsProps> = ({
value={project.url}
/>
</FormControl>
<FormControl>
<TextField
id="timeout"
label="Step Timeout (MILLISECONDS)"
helperText="Steps will fail if they take longer than this setting"
name="timeout"
type="number"
inputProps={{ min:0, step: 1000 }}
onChange={(e: any) => {
update({
delay: Math.max(parseInt(e.target.value || '0'), 0),
})
}}
size="small"
value={project.delay || 0}
/>
</FormControl>
<FormControl>
<TextField
id="delay"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const updateCommand = updateACField('command')
const CommandSelector: FC<CommandSelectorProps> = ({
command,
commands,
disabled,
isDisabled,
testID,
}) => {
Expand All @@ -40,6 +41,7 @@ const CommandSelector: FC<CommandSelectorProps> = ({
<Autocomplete
id="command-selector"
className="flex-1"
disabled={disabled}
onChange={updateCommand(testID, command.id)}
getOptionLabel={(option) => option.label}
options={commandOptions}
Expand All @@ -65,7 +67,10 @@ const CommandSelector: FC<CommandSelectorProps> = ({
} a new window`}
placement="top-end"
>
<IconButton onClick={() => setOpensWindow(!command.opensWindow)}>
<IconButton
disabled={disabled}
onClick={() => setOpensWindow(!command.opensWindow)}
>
<OpenInNew color={command.opensWindow ? 'info' : 'inherit'} />
</IconButton>
</Tooltip>
Expand All @@ -75,6 +80,7 @@ const CommandSelector: FC<CommandSelectorProps> = ({
placement="top-end"
>
<IconButton
disabled={disabled}
onClick={() =>
setCommand(isDisabled ? command.command : `//${command.command}`)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type PluralField = 'targets' | 'values'
const CommandLocatorField: FC<CommandArgFieldProps> = ({
command,
commands,
disabled,
fieldName,
testID,
}) => {
Expand Down Expand Up @@ -44,6 +45,7 @@ const CommandLocatorField: FC<CommandArgFieldProps> = ({
<FormControl className="flex flex-row">
<Autocomplete
className="flex-1"
disabled={disabled}
freeSolo
inputValue={localValue || ''}
componentsProps={{
Expand Down Expand Up @@ -81,13 +83,15 @@ const CommandLocatorField: FC<CommandArgFieldProps> = ({
/>
<IconButton
className="ml-4"
disabled={disabled}
onClick={() =>
window.sideAPI.recorder.requestHighlightElement(fieldName)
}
>
<FindInPageIcon />
</IconButton>
<IconButton
disabled={disabled}
onClick={() =>
window.sideAPI.recorder.requestSelectElement(true, fieldName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import Tooltip from '@mui/material/Tooltip'
import { LocatorFields } from '@seleniumhq/side-api'

const CommandTextField: FC<CommandFieldProps> = ({
commands,
command,
commands,
disabled,
fieldName,
note,
testID,
Expand All @@ -27,6 +28,7 @@ const CommandTextField: FC<CommandFieldProps> = ({
<FormControl className="flex flex-row">
<TextField
className="flex-1"
disabled={disabled}
id={`${fieldName}-${command.id}`}
label={label}
InputLabelProps={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import CommandTextField from './CommandFields/TextField'
export interface CommandEditorProps {
command: CommandShape
commands: CoreSessionData['state']['commands']
disabled?: boolean
selectedCommandIndexes: number[]
testID: string
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface CommandListProps {
bottomOffset: number
commands: CommandShape[]
commandStates: CommandsStateShape
disabled?: boolean
selectedCommandIndexes: number[]
}

Expand All @@ -22,6 +23,7 @@ const CommandList: FC<CommandListProps> = ({
bottomOffset,
commandStates,
commands,
disabled = false,
selectedCommandIndexes,
}) => {
const [preview, reorderPreview, resetPreview] = useReorderPreview(
Expand All @@ -34,9 +36,10 @@ const CommandList: FC<CommandListProps> = ({
<ReorderableList
bottomOffset={bottomOffset}
dense
aria-disabled={disabled}
subheader={
<EditorToolbar
sx={{ top: '48px', zIndex: 100 }}
disabled={disabled}
onAdd={() =>
window.sideAPI.tests.addSteps(
activeTest,
Expand All @@ -52,6 +55,7 @@ const CommandList: FC<CommandListProps> = ({
)
: undefined
}
sx={{ top: '48px', zIndex: 100 }}
>
<span className="ml-4">Commands</span>
</EditorToolbar>
Expand All @@ -67,6 +71,7 @@ const CommandList: FC<CommandListProps> = ({
activeTest={activeTest}
command={command}
commandState={commandStates[id]}
disabled={disabled}
key={id}
index={index}
reorderPreview={reorderPreview}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface CommandRowProps {
activeTest: string
commandState: PlaybackEventShapes['COMMAND_STATE_CHANGED']
command: CommandShape
disabled?: boolean
index: number
reorderPreview: ReorderPreview
resetPreview: () => void
Expand All @@ -54,6 +55,7 @@ const CommandRow: React.FC<CommandRowProps> = ({
activeTest,
commandState = defaultCommandState,
command: { command, id, isBreakpoint, opensWindow, target, value },
disabled = false,
index,
reorderPreview,
resetPreview,
Expand Down Expand Up @@ -93,6 +95,7 @@ const CommandRow: React.FC<CommandRowProps> = ({
secondaryAction={
<IconButton
color={isBreakpoint ? 'primary' : 'default'}
disabled={disabled}
edge="end"
onClick={toggleBreakpoint}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ interface CommandRowProps {
activeTest: string
commandState: PlaybackEventShapes['COMMAND_STATE_CHANGED']
command: CommandShape
disabled?: boolean
index: number
reorderPreview: ReorderPreview
resetPreview: () => void
Expand All @@ -81,6 +82,7 @@ const CommandRow: React.FC<CommandRowProps> = ({
activeTest,
commandState = {},
command: { command, comment, id, isBreakpoint, target, value },
disabled = false,
index,
reorderPreview,
resetPreview,
Expand Down Expand Up @@ -133,6 +135,7 @@ const CommandRow: React.FC<CommandRowProps> = ({
secondaryAction={
<IconButton
color={isBreakpoint ? 'warning' : 'default'}
disabled={disabled}
onClick={toggleBreakpoint}
>
<PauseIcon />
Expand Down Expand Up @@ -191,7 +194,7 @@ const CommandRow: React.FC<CommandRowProps> = ({
<Box sx={{ flex: 2, ...argTextFormat }}>{value}</Box>
<Box sx={{ flex: 0, flexBasis: 50 }}></Box>
</Box>
{commandState.message && (
{'message' in commandState && (
<Box sx={errorTextFormat}>
<Typography>{commandState.message}</Typography>
</Box>
Expand Down
Loading

0 comments on commit 14d01a4

Please sign in to comment.