Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,6 @@ declare namespace Cypress {
*/
ElementSelector: {
defaults(options: Partial<ElementSelectorDefaultsOptions>): void
getSelector($el: JQuery): JQuery.Selector
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/runner/aut-iframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ export class AutIframe {

const Cypress = this.eventManager.getCypress()

const selector = Cypress.ElementSelector.getSelector($el)
const selector = Cypress.ElementSelector._getSelector($el)
const selectorPlaygroundStore = useSelectorPlaygroundStore()

this._addOrUpdateSelectorPlaygroundHighlight({
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/store/studio-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ export const useStudioStore = defineStore('studioRecorder', {
if (!this._matchPreviousMouseEvent(target)) {
this._previousMouseEvent = {
element: target,
selector: getCypress().ElementSelector.getSelector(window.UnifiedRunner.CypressJQuery(target)),
selector: getCypress().ElementSelector._getSelector(window.UnifiedRunner.CypressJQuery(target)),
}
}
},
Expand Down
12 changes: 8 additions & 4 deletions packages/driver/cypress/e2e/cypress/element_selector.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
import type { ElementSelectorAPI } from '../../../src/cypress/element_selector'
import { DEFAULT_SELECTOR_PRIORITIES } from '../../../src/cypress/element_selector'
const { $: $cypress } = Cypress.$Cypress
const ElementSelector = Cypress.ElementSelector as ElementSelectorAPI
const ElementSelector = Cypress.ElementSelector as ElementSelectorAPI & {
_reset(): void
getSelectorPriority(): Cypress.SelectorPriority[]
_getSelector($el: any): string
}

const SELECTOR_DEFAULTS: Cypress.SelectorPriority[] = [...DEFAULT_SELECTOR_PRIORITIES]

describe('src/cypress/element_selector', () => {
beforeEach(() => {
ElementSelector.reset()
ElementSelector._reset()
})

it('has defaults', () => {
Expand Down Expand Up @@ -108,13 +112,13 @@ describe('src/cypress/element_selector', () => {

Cypress.$('body').append($div)

expect(ElementSelector.getSelector($div)).to.eq('[data-cy="main button 123"]')
expect(ElementSelector._getSelector($div)).to.eq('[data-cy="main button 123"]')

ElementSelector.defaults({
selectorPriority: ['data-foo'],
})

expect(ElementSelector.getSelector($div)).to.eq('[data-foo="bar"]')
expect(ElementSelector._getSelector($div)).to.eq('[data-foo="bar"]')
})
})

Expand Down
23 changes: 13 additions & 10 deletions packages/driver/src/cypress/element_selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ export type ElementSelectorDefaultsOptions = {
}

export interface ElementSelectorAPI {
reset(): void
getSelectorPriority(): Cypress.SelectorPriority[]
getSelector($el: any): string
defaults(options: ElementSelectorDefaultsOptions): void
getSelectorPriority(): Cypress.SelectorPriority[]
}

interface ElementSelectorPrivate {
_reset(): void
_getSelector($el: any): string
}

const reset = (): Defaults => {
Expand All @@ -43,21 +46,21 @@ const reset = (): Defaults => {

let defaults = reset()

const ElementSelector: ElementSelectorAPI = {
reset () {
const ElementSelector: ElementSelectorAPI & ElementSelectorPrivate = {
_reset () {
defaults = reset()
},

getSelectorPriority () {
return defaults.selectorPriority
},

getSelector ($el: any) {
_getSelector ($el: any) {
return uniqueSelector($el.get(0), {
selectorTypes: defaults.selectorPriority,
})
},

getSelectorPriority () {
return defaults.selectorPriority
},

defaults (props: ElementSelectorDefaultsOptions) {
if (!_.isPlainObject(props)) {
$errUtils.throwErrByPath('element_selector.defaults_invalid_arg', {
Expand Down
Loading