Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove protocol element highlight selector tests #29533

Merged
merged 4 commits into from
May 17, 2024
Merged
Changes from all 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
106 changes: 0 additions & 106 deletions packages/driver/cypress/e2e/cy/snapshot.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,112 +175,6 @@ describe('driver/src/cy/snapshots', () => {
expect(body.get().find('iframe').css('height')).to.equal('70px')
})
})

context('protocol', () => {
beforeEach(() => {
// set to 0 to ensure protocol snapshots are taken
// since the driver support file sets the value to 1
Cypress.config('numTestsKeptInMemory', 0)
})

it('captures a protocol snapshot with highlight elements', {
protocolEnabled: true,
}, function () {
cy.window().then((win) => {
win.__cypressProtocolMetadata = { frameId: 'test-frame-id' }

const { elementsToHighlight, name, timestamp } = cy.createSnapshot('snapshot', cy.$$('a'))

expect(elementsToHighlight?.length).to.equal(3)
expect(elementsToHighlight?.[0].selector).to.equal('a:nth-child(2)')
expect(elementsToHighlight?.[0].frameId).to.equal('test-frame-id')
expect(elementsToHighlight?.[1].selector).to.equal('#hashchange')
expect(elementsToHighlight?.[1].frameId).to.equal('test-frame-id')
expect(elementsToHighlight?.[2].selector).to.equal('#dimensions')
expect(elementsToHighlight?.[2].frameId).to.equal('test-frame-id')
expect(name).to.equal('snapshot')
expect(timestamp).to.be.a('number')
})
})

it('captures a protocol snapshot with an embedded iframe highlight element', {
protocolEnabled: true,
}, function () {
const iframe = $('<iframe src=\'iframe-inner.html\' />')

iframe.on('load', () => {
const ownerDoc = iframe[0].contentDocument
const elWindow = iframe[0].contentWindow
const element = $(ownerDoc.querySelector('button'))

elWindow.__cypressProtocolMetadata = { frameId: 'test-frame-id' }

const { elementsToHighlight, name, timestamp } = cy.createSnapshot('snapshot', element)

expect(elementsToHighlight?.length).to.equal(1)
expect(elementsToHighlight?.[0].selector).to.equal('button:nth-child(1)')
expect(elementsToHighlight?.[0].frameId).to.equal('test-frame-id')
expect(name).to.equal('snapshot')
expect(timestamp).to.be.a('number')
})

iframe.appendTo(cy.$$('body'))
})

it('captures a protocol snapshot with a body highlight element', {
protocolEnabled: true,
}, function () {
cy.window().then((win) => {
win.__cypressProtocolMetadata = { frameId: 'test-frame-id' }

const { elementsToHighlight, name, timestamp } = cy.createSnapshot('snapshot', cy.$$('body'))

expect(elementsToHighlight?.length).to.equal(1)
expect(elementsToHighlight?.[0].selector).to.equal('body:nth-child(2)')
expect(elementsToHighlight?.[0].frameId).to.equal('test-frame-id')
expect(name).to.equal('snapshot')
expect(timestamp).to.be.a('number')
})
})

it('captures a protocol snapshot and excludes a null element', {
protocolEnabled: true,
}, function () {
// create an element but don't append it to the DOM
const element = $('<div id=\'foo\' />')

const { elementsToHighlight, name, timestamp } = cy.createSnapshot('snapshot', element)

expect(elementsToHighlight?.length).to.equal(0)
expect(name).to.equal('snapshot')
expect(timestamp).to.be.a('number')
})

it('captures shadow DOM selectors structure properly', {
protocolEnabled: true,
}, () => {
cy.visit('/fixtures/shadow-dom-type.html')
cy.window().then((win) => {
win.__cypressProtocolMetadata = { frameId: 'test-frame-id' }

cy.get('#shadow-dom-input', {
includeShadowDom: true,
}).then((shadowDomSlot) => {
const { elementsToHighlight, name, timestamp } = cy.createSnapshot('snapshot', shadowDomSlot)

expect(elementsToHighlight?.length).to.equal(1)
const elementToHighlight = elementsToHighlight[0]

expect(elementToHighlight.selector.length).to.equal(2)
expect(elementToHighlight.selector[0]).to.equal('#element')
expect(elementToHighlight.selector[1]).to.equal('#shadow-dom-input')
expect(elementToHighlight.frameId).to.equal('test-frame-id')
expect(name).to.equal('snapshot')
expect(timestamp).to.be.a('number')
})
})
})
})
})

context('custom elements', () => {
Expand Down
Loading