Skip to content

Commit ce84e2b

Browse files
committed
highlight element command
1 parent ee44ded commit ce84e2b

File tree

8 files changed

+70
-8
lines changed

8 files changed

+70
-8
lines changed

packages/selenium-ide/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@seleniumhq/selenium-ide",
3-
"version": "4.0.0-alpha.24",
3+
"version": "4.0.0-alpha.25",
44
"private": true,
55
"description": "Selenium IDE electron app",
66
"author": "Todd <[email protected]>",
@@ -100,7 +100,7 @@
100100
"@mui/lab": "^5.0.0-alpha.72",
101101
"@mui/material": "^5.5.0",
102102
"@seleniumhq/get-driver": "^4.0.0-alpha.1",
103-
"@seleniumhq/side-api": "^4.0.0-alpha.10",
103+
"@seleniumhq/side-api": "^4.0.0-alpha.11",
104104
"@seleniumhq/side-model": "^4.0.0-alpha.2",
105105
"@seleniumhq/side-plugin-example": "^4.0.0-alpha.1",
106106
"@seleniumhq/side-runtime": "^4.0.0-alpha.14",

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,16 @@ const init = () => {
2525
window.sideAPI.recorder.onRequestSelectElement.addListener(
2626
processSelectionCommand
2727
)
28+
window.sideAPI.recorder.onHighlightElement.addListener(
29+
processHighlightCommand
30+
)
2831
window.addEventListener('beforeunload', () => {
2932
window.sideAPI.recorder.onRequestSelectElement.removeListener(
3033
processSelectionCommand
3134
)
35+
window.sideAPI.recorder.onHighlightElement.removeListener(
36+
processHighlightCommand
37+
)
3238
})
3339
}
3440

@@ -88,6 +94,12 @@ function processMessage(event: MessageEvent<any>) {
8894
}
8995
}
9096

97+
async function processHighlightCommand(locator: string): Promise<void> {
98+
const element = await locatorBuilders.findElement(locator)
99+
console.log('Highlighting element', element)
100+
await highlight(element)
101+
}
102+
91103
function highlight(element: HTMLElement): Promise<void> {
92104
return new Promise((res) => {
93105
const highlightElement = document.createElement('div')
@@ -103,12 +115,17 @@ function highlight(element: HTMLElement): Promise<void> {
103115
highlightElement.style.zIndex = '100'
104116
highlightElement.style.display = 'block'
105117
highlightElement.style.pointerEvents = 'none'
118+
highlightElement.style.outline = '2px solid #a7f'
119+
highlightElement.style.opacity = '1'
120+
highlightElement.style.transition = 'opacity 3s'
106121
scrollIntoViewIfNeeded(highlightElement, { block: 'center' })
107-
highlightElement.className = 'active-selenium-highlight'
122+
setTimeout(() => {
123+
highlightElement.style.opacity = '0'
124+
}, 500)
108125
setTimeout(() => {
109126
document.body.removeChild(highlightElement)
110127
res()
111-
}, 500)
128+
}, 3500)
112129
})
113130
}
114131

packages/selenium-ide/src/browser/windows/ProjectEditor/tabs/Tests/CommandFields/LocatorField.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import HelpCenter from '@mui/icons-material/HelpCenter'
22
import AddToHomeScreenIcon from '@mui/icons-material/AddToHomeScreen'
3+
import FindInPageIcon from '@mui/icons-material/FindInPage';
34
import Autocomplete from '@mui/material/Autocomplete'
45
import FormControl from '@mui/material/FormControl'
56
import IconButton from '@mui/material/IconButton'
@@ -80,6 +81,13 @@ const CommandLocatorField: FC<CommandArgFieldProps> = ({
8081
/>
8182
<IconButton
8283
className="ml-4"
84+
onClick={() =>
85+
window.sideAPI.recorder.requestHighlightElement(fieldName)
86+
}
87+
>
88+
<FindInPageIcon />
89+
</IconButton>
90+
<IconButton
8391
onClick={() =>
8492
window.sideAPI.recorder.requestSelectElement(true, fieldName)
8593
}

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { CommandShape } from '@seleniumhq/side-model'
22
import { getActiveCommand } from '@seleniumhq/side-api/dist/helpers/getActiveData'
33
import { LocatorFields } from '@seleniumhq/side-api'
44
import { randomInt, randomUUID } from 'crypto'
5+
import { Session } from 'main/types'
56
import { relative } from 'path'
67
import BaseController from '../Base'
78

@@ -51,6 +52,16 @@ export interface RecordNewCommandInput {
5152
}
5253

5354
export default class RecorderController extends BaseController {
55+
constructor(session: Session) {
56+
super(session)
57+
}
58+
async requestHighlightElement(fieldName: LocatorFields) {
59+
const activeCommand = getActiveCommand(await this.session.state.get())
60+
this.session.api.recorder.onHighlightElement.dispatchEvent(
61+
activeCommand[fieldName] as string
62+
)
63+
}
64+
5465
async recordNewCommand(
5566
cmd: RecordNewCommandInput
5667
): Promise<CommandShape[] | null> {
@@ -108,13 +119,16 @@ export default class RecorderController extends BaseController {
108119
let inited = false
109120
if (playbackWindow) {
110121
const playbackURL = playbackWindow.webContents.getURL()
111-
inited = !(playbackURL.startsWith('file://') && playbackURL.endsWith('/playback-window.html'))
122+
inited = !(
123+
playbackURL.startsWith('file://') &&
124+
playbackURL.endsWith('/playback-window.html')
125+
)
112126
} else {
113127
await this.session.windows.initializePlaybackWindow()
114128
playbackWindow = await this.session.windows.getLastPlaybackWindow()
115129
inited = false
116-
}
117-
130+
}
131+
118132
if (!inited) {
119133
// Needs to open a URL, if on an open command, just use that
120134
// Otherwise add an open command to the record commands

packages/side-api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@seleniumhq/side-api",
3-
"version": "4.0.0-alpha.10",
3+
"version": "4.0.0-alpha.11",
44
"description": "Selenium IDE shared models",
55
"author": "Todd Tarsi <[email protected]>",
66
"homepage": "http://github.com/SeleniumHQ/selenium-ide",

packages/side-api/src/commands/recorder/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { Shape as GetFrameLocation } from './getFrameLocation'
22
import type { Shape as OnFrameDeleted } from './onFrameDeleted'
33
import type { Shape as OnFrameRecalculate } from './onFrameRecalculate'
4+
import type { Shape as OnHighlightElement } from './onHighlightElement'
45
import type { Shape as OnNewWindow } from './onNewWindow'
6+
import type { Shape as RequestHighlightElement } from './requestHighlightElement'
57
import type { Shape as OnRequestSelectElement } from './onRequestSelectElement'
68
import type { Shape as RecordNewCommand } from './recordNewCommand'
79
import type { Shape as RequestSelectElement } from './requestSelectElement'
@@ -13,7 +15,9 @@ import type { Shape as Stop } from './stop'
1315
import * as getFrameLocation from './getFrameLocation'
1416
import * as onFrameDeleted from './onFrameDeleted'
1517
import * as onFrameRecalculate from './onFrameRecalculate'
18+
import * as onHighlightElement from './onHighlightElement'
1619
import * as onNewWindow from './onNewWindow'
20+
import * as requestHighlightElement from './requestHighlightElement'
1721
import * as onRequestSelectElement from './onRequestSelectElement'
1822
import * as recordNewCommand from './recordNewCommand'
1923
import * as requestSelectElement from './requestSelectElement'
@@ -26,7 +30,9 @@ export const commands = {
2630
getFrameLocation,
2731
onFrameDeleted,
2832
onFrameRecalculate,
33+
onHighlightElement,
2934
onNewWindow,
35+
requestHighlightElement,
3036
onRequestSelectElement,
3137
recordNewCommand,
3238
requestSelectElement,
@@ -44,9 +50,11 @@ export type Shape = {
4450
getFrameLocation: GetFrameLocation
4551
onFrameDeleted: OnFrameDeleted
4652
onFrameRecalculate: OnFrameRecalculate
53+
onHighlightElement: OnHighlightElement
4754
onNewWindow: OnNewWindow
4855
onRequestSelectElement: OnRequestSelectElement
4956
recordNewCommand: RecordNewCommand
57+
requestHighlightElement: RequestHighlightElement
5058
requestSelectElement: RequestSelectElement
5159
selectElement: SelectElement
5260
setWindowHandle: SetWindowHandle
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { BaseListener } from '../../types'
2+
3+
/**
4+
* Called when the project editor asks the recorder to highlight an element
5+
* on the playback page.
6+
*/
7+
export type Shape = BaseListener<OnHighlightElementRecorder>
8+
export type OnHighlightElementRecorder = [string]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { LocatorFields } from '../../types'
2+
3+
/**
4+
* Asks the playback windows to set the next element clicked as the currently
5+
* selected locator field element.
6+
*/
7+
export type Shape = (fieldName: LocatorFields) => Promise<void>

0 commit comments

Comments
 (0)