Skip to content

Commit 43be137

Browse files
committed
hide url workaround behind a pref
1 parent 88b1f92 commit 43be137

File tree

6 files changed

+74
-23
lines changed

6 files changed

+74
-23
lines changed

packages/selenium-ide/src/browser/windows/ProjectEditor/tabs/Project/ProjectTab.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import MenuItem from '@mui/material/MenuItem'
99
import Paper from '@mui/material/Paper'
1010
import Select from '@mui/material/Select'
1111
import Stack from '@mui/material/Stack'
12-
import { CoreSessionData } from '@seleniumhq/side-api'
12+
import { CoreSessionData, VerboseBoolean } from '@seleniumhq/side-api'
1313
import TextField from 'browser/components/UncontrolledTextField'
1414
import React, { FC } from 'react'
1515
import EditorToolbar from '../../components/Drawer/EditorToolbar'
@@ -131,6 +131,25 @@ const ProjectTab: FC<ProjectTabProps> = ({ session: { project, state } }) => (
131131
<MenuItem value="No">No</MenuItem>
132132
</Select>
133133
</FormControl>
134+
<FormControl>
135+
<InputLabel id="disableCodeExportCompat">
136+
Disable code export compatibility mode
137+
</InputLabel>
138+
<Select
139+
id="disableCodeExportCompatPref"
140+
label="Disable code export compatibility mode"
141+
name="ignoreCertificateErrorsPref"
142+
value={state.userPrefs.disableCodeExportCompat}
143+
onChange={(e) => {
144+
window.sideAPI.state.toggleUserPrefDisableCodeExportCompat(
145+
e.target.value as VerboseBoolean
146+
)
147+
}}
148+
>
149+
<MenuItem value="Yes">Yes</MenuItem>
150+
<MenuItem value="No">No</MenuItem>
151+
</Select>
152+
</FormControl>
134153
</Stack>
135154
<List
136155
dense

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ export interface BrowsersInfo {
3737
* WebdriverExecutor class, which is in itself a wrapper on an selenium-
3838
* webdriver. This is why, when mounted onto the session, we may have to
3939
* do this pattern of de-referencing (I'm sorry):
40-
*
40+
*
4141
* this.session.driver.driver.driver
42-
*
42+
*
4343
* :(
4444
*/
4545
export default class DriverController extends BaseController {
@@ -68,19 +68,24 @@ export default class DriverController extends BaseController {
6868
...capabilities,
6969
},
7070
customCommands: this.session.commands.customCommands,
71+
disableCodeExportCompat:
72+
this.session.state.state.userPrefs.disableCodeExportCompat === 'Yes'
73+
? true
74+
: false,
7175
hooks: {
7276
onBeforePlay: (v) => this.session.playback.onBeforePlay(v),
7377
},
7478
server,
7579
windowAPI: {
7680
setWindowSize: async (_executor, width, height) => {
7781
const window = this.session.windows.getLastPlaybackWindow()
78-
const pbWinCount = this.session.windows.playbackWindows.length
82+
const pbWinCount = this.session.windows.playbackWindows.length
7983
const b = await window.getBounds()
8084
const calcNewX = b.x + Math.floor(b.width / 2) - Math.floor(width / 2)
81-
const calcNewY = b.y + Math.floor(b.height / 2) - Math.floor(height / 2)
82-
const newX = calcNewX < 0 ? pbWinCount*20 : calcNewX
83-
const newY = calcNewY < 0 ? pbWinCount*20 : calcNewY
85+
const calcNewY =
86+
b.y + Math.floor(b.height / 2) - Math.floor(height / 2)
87+
const newX = calcNewX < 0 ? pbWinCount * 20 : calcNewX
88+
const newY = calcNewY < 0 ? pbWinCount * 20 : calcNewY
8489
await window.setBounds({
8590
x: newX,
8691
y: newY,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { Shape as SetCopiedCommands } from './setCopiedCommands'
1010
import type { Shape as ToggleBreakpoint } from './toggleBreakpoint'
1111
import type { Shape as ToggleSuiteMode } from './toggleSuiteMode'
1212
import type { Shape as ToggleUserPrefCamelCase } from './toggleUserPrefCamelCase'
13+
import type { Shape as ToggleUserPrefDisableCodeExportCompat } from './toggleUserPrefDisableCodeExportCompat'
1314
import type { Shape as ToggleUserPrefIgnoreCertificateErrors } from './toggleUserPrefIgnoreCertificateErrors'
1415
import type { Shape as ToggleUserPrefInsert } from './toggleUserPrefInsert'
1516
import type { Shape as ToggleUserPrefTheme } from './toggleUserPrefTheme'
@@ -28,6 +29,7 @@ import * as setCopiedCommands from './setCopiedCommands'
2829
import * as toggleBreakpoint from './toggleBreakpoint'
2930
import * as toggleSuiteMode from './toggleSuiteMode'
3031
import * as toggleUserPrefCamelCase from './toggleUserPrefCamelCase'
32+
import * as toggleUserPrefDisableCodeExportCompat from './toggleUserPrefDisableCodeExportCompat'
3133
import * as toggleUserPrefIgnoreCertificateErrors from './toggleUserPrefIgnoreCertificateErrors'
3234
import * as toggleUserPrefInsert from './toggleUserPrefInsert'
3335
import * as toggleUserPrefTheme from './toggleUserPrefTheme'
@@ -47,6 +49,7 @@ export const commands = {
4749
toggleBreakpoint,
4850
toggleSuiteMode,
4951
toggleUserPrefCamelCase,
52+
toggleUserPrefDisableCodeExportCompat,
5053
toggleUserPrefIgnoreCertificateErrors,
5154
toggleUserPrefInsert,
5255
toggleUserPrefTheme,
@@ -70,6 +73,7 @@ export type Shape = {
7073
toggleBreakpoint: ToggleBreakpoint
7174
toggleSuiteMode: ToggleSuiteMode
7275
toggleUserPrefCamelCase: ToggleUserPrefCamelCase
76+
toggleUserPrefDisableCodeExportCompat: ToggleUserPrefDisableCodeExportCompat
7377
toggleUserPrefIgnoreCertificateErrors: ToggleUserPrefIgnoreCertificateErrors
7478
toggleUserPrefInsert: ToggleUserPrefInsert
7579
toggleUserPrefTheme: ToggleUserPrefTheme
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import set from 'lodash/fp/set'
2+
import { VerboseBoolean } from '../../models/state'
3+
import { Mutator } from '../../types'
4+
5+
/**
6+
* Customizes command insert behavior to either follow or lead the current
7+
* command
8+
*/
9+
export type Shape = (pref: VerboseBoolean) => Promise<void>
10+
11+
export const mutator: Mutator<Shape> = (session, { params: [pref] }) =>
12+
set('state.userPrefs.disableCodeExportCompat', pref, session)

packages/side-api/src/models/state/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,22 @@ export const defaultRecorderState: RecorderStateShape = {
3131
activeFrame: 'root',
3232
}
3333

34+
export type VerboseBoolean = 'Yes' | 'No'
3435
export type InsertCommandPref = 'Before' | 'After'
3536
export type ThemePref = 'Dark' | 'Light' | 'System'
36-
export type CamelCaseNamesPref = 'Yes' | 'No'
37-
export type IgnoreCertificateErrorsPref = 'Yes' | 'No'
37+
export type CamelCaseNamesPref = VerboseBoolean
38+
export type IgnoreCertificateErrorsPref = VerboseBoolean
3839

3940
export interface UserPrefs {
41+
disableCodeExportCompat: VerboseBoolean
4042
insertCommandPref: InsertCommandPref
4143
themePref: ThemePref
4244
camelCaseNamesPref: CamelCaseNamesPref
4345
ignoreCertificateErrorsPref: IgnoreCertificateErrorsPref
4446
}
4547

4648
export const defaultUserPrefs: UserPrefs = {
49+
disableCodeExportCompat: 'No',
4750
insertCommandPref: 'After',
4851
themePref: 'System',
4952
camelCaseNamesPref: 'No',

packages/side-runtime/src/webdriver.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export interface WindowAPI {
7272
export interface WebDriverExecutorConstructorArgs {
7373
capabilities?: ExpandedCapabilities
7474
customCommands?: PluginShape['commands']
75+
disableCodeExportCompat?: boolean
7576
driver?: WebDriver
7677
hooks?: WebDriverExecutorHooks
7778
implicitWait?: number
@@ -131,6 +132,7 @@ const defaultWindowAPI: WindowAPI = {
131132
export default class WebDriverExecutor {
132133
constructor({
133134
customCommands = {},
135+
disableCodeExportCompat = false,
134136
driver,
135137
capabilities,
136138
server,
@@ -144,6 +146,7 @@ export default class WebDriverExecutor {
144146
this.capabilities = capabilities || DEFAULT_CAPABILITIES
145147
this.server = server
146148
}
149+
this.disableCodeExportCompat = disableCodeExportCompat
147150
this.initialized = false
148151
this.implicitWait = implicitWait || 5 * 1000
149152
this.hooks = hooks
@@ -157,6 +160,7 @@ export default class WebDriverExecutor {
157160
cancellable?: { cancel: () => void }
158161
capabilities?: ExpandedCapabilities
159162
customCommands: Required<PluginShape>['commands']
163+
disableCodeExportCompat: boolean
160164
// @ts-expect-error
161165
driver: WebDriver
162166
server?: string
@@ -318,22 +322,26 @@ export default class WebDriverExecutor {
318322
for (let frameTarget of frameTargets) {
319323
if (frameTarget === '..') await targetLocator.parentFrame()
320324
else {
321-
const frameIndex = locator.substring('index='.length)
322-
// Delay for a second. Check too fast, and browser will think this iframe location is 'about:blank'
323-
await new Promise((f) => setTimeout(f, 1000))
324-
const frameUrl = await this.driver.executeScript(
325-
"return window.frames['" + frameIndex + "'].location.href"
326-
)
327-
const windowFrames = await this.driver.findElements(By.css('iframe'))
328-
let matchIndex = 0
329-
for (let frame of windowFrames) {
330-
let localFrameUrl = await frame.getAttribute('src')
331-
if (localFrameUrl === frameUrl) {
332-
break
325+
if (this.disableCodeExportCompat) {
326+
const frameIndex = locator.substring('index='.length)
327+
// Delay for a second. Check too fast, and browser will think this iframe location is 'about:blank'
328+
await new Promise((f) => setTimeout(f, 1000))
329+
const frameUrl = await this.driver.executeScript(
330+
"return window.frames['" + frameIndex + "'].location.href"
331+
)
332+
const windowFrames = await this.driver.findElements(By.css('iframe'))
333+
let matchIndex = 0
334+
for (let frame of windowFrames) {
335+
let localFrameUrl = await frame.getAttribute('src')
336+
if (localFrameUrl === frameUrl) {
337+
break
338+
}
339+
matchIndex++
333340
}
334-
matchIndex++
341+
this.driver.switchTo().frame(matchIndex)
342+
} else {
343+
await targetLocator.frame(Number(frameTarget))
335344
}
336-
this.driver.switchTo().frame(matchIndex)
337345
}
338346
}
339347
} else {

0 commit comments

Comments
 (0)