Skip to content

Commit

Permalink
Merge branch 'develop' into feat/protocol_shadow_dom_support
Browse files Browse the repository at this point in the history
  • Loading branch information
AtofStryker authored Mar 8, 2024
2 parents bdc3dd1 + 96eab73 commit 7e1592a
Show file tree
Hide file tree
Showing 24 changed files with 320 additions and 99 deletions.
4 changes: 2 additions & 2 deletions browser-versions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"chrome:beta": "123.0.6312.22",
"chrome:stable": "122.0.6261.94",
"chrome:beta": "123.0.6312.28",
"chrome:stable": "122.0.6261.111",
"chrome:minimum": "64.0.3282.0"
}
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ _Released 2/27/2024 (PENDING)_

**Bugfixes:**

- Changed screenshot capture behavior in Chromium to activate the main Cypress tab before capturing. This prevents screenshot capture from timing out in certain situations. Fixed in [#29038](/~https://github.com/cypress-io/cypress/pull/29038). Fixes [#5016](/~https://github.com/cypress-io/cypress/issues/5016)
- Fixed an issue where `.click()` commands on children of disabled elements would still produce "click" events -- even without `{ force: true }`. Fixes [#28788](/~https://github.com/cypress-io/cypress/issues/28788).
- Changed RequestBody type to allow for boolean and null literals to be passed as body values. [#28789](/~https://github.com/cypress-io/cypress/issues/28789)

Expand Down
1 change: 0 additions & 1 deletion packages/extension/app/v2/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ const automation = {
})
.then(fn)
},

}

module.exports = automation
28 changes: 19 additions & 9 deletions packages/launchpad/cypress/e2e/choose-a-browser.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { FoundBrowser } from '@packages/types'

// TODO: fix flaky tests /~https://github.com/cypress-io/cypress/issues/23418
describe.skip('Choose a browser page', () => {
describe('Choose a browser page', () => {
beforeEach(() => {
cy.scaffoldProject('launchpad')
})
Expand All @@ -15,8 +14,7 @@ describe.skip('Choose a browser page', () => {
})
})

// TODO: fix flaky test /~https://github.com/cypress-io/cypress/issues/23158
it('preselects browser that is provided through the command line', { retries: 15 }, () => {
it('preselects browser that is provided through the command line', () => {
cy.withCtx((ctx, o) => {
// stub launching project since we have `--browser --testingType --project` here
o.sinon.stub(ctx._apis.projectApi, 'launchProject').resolves()
Expand All @@ -25,6 +23,7 @@ describe.skip('Choose a browser page', () => {
cy.openProject('launchpad', ['--e2e', '--browser', 'edge'])

cy.visitLaunchpad()
cy.skipWelcome()

cy.get('h1').should('contain', 'Choose a browser')

Expand All @@ -40,6 +39,7 @@ describe.skip('Choose a browser page', () => {
it('shows warning when launched with --browser name that cannot be matched to found browsers', () => {
cy.openProject('launchpad', ['--e2e', '--browser', 'doesNotExist'])
cy.visitLaunchpad()
cy.skipWelcome()

cy.get('h1').should('contain', 'Choose a browser')
cy.get('[data-cy="alert-header"]').should('contain', 'Warning: Browser Not Found')
Expand All @@ -63,13 +63,15 @@ describe.skip('Choose a browser page', () => {
cy.openProject('launchpad', ['--e2e', '--browser', path])

cy.visitLaunchpad()
cy.skipWelcome()

cy.get('h1').should('contain', 'Choose a browser')

cy.get('[data-cy="alert-header"]').should('contain', 'Warning: Browser Not Found')
cy.get('[data-cy="alert-body"]').as('AlertBody')
.should('contain', `We could not identify a known browser at the path you provided: ${path}`)
.validateExternalLink({

cy.validateExternalLink({
href: 'https://on.cypress.io/troubleshooting-launching-browsers',
})

Expand All @@ -96,6 +98,7 @@ describe.skip('Choose a browser page', () => {
cy.openProject('launchpad', ['--e2e'])

cy.visitLaunchpad()
cy.skipWelcome()

cy.get('h1').should('contain', 'Choose a browser')

Expand All @@ -112,6 +115,7 @@ describe.skip('Choose a browser page', () => {
cy.openProject('launchpad', ['--e2e'])

cy.visitLaunchpad()
cy.skipWelcome()

cy.get('h1').should('contain', 'Choose a browser')

Expand Down Expand Up @@ -164,6 +168,7 @@ describe.skip('Choose a browser page', () => {
cy.openProject('launchpad', ['--e2e'])

cy.visitLaunchpad()
cy.skipWelcome()

cy.get('h1').should('contain', 'Choose a browser')

Expand All @@ -188,6 +193,7 @@ describe.skip('Choose a browser page', () => {
cy.openProject('launchpad', ['--e2e'])

cy.visitLaunchpad()
cy.skipWelcome()

cy.get('h1').should('contain', 'Choose a browser')

Expand All @@ -205,6 +211,7 @@ describe.skip('Choose a browser page', () => {
cy.openProject('launchpad', ['--e2e'])

cy.visitLaunchpad()
cy.skipWelcome()

cy.withCtx((ctx) => {
ctx.actions.app.setBrowserStatus('open')
Expand All @@ -217,11 +224,11 @@ describe.skip('Choose a browser page', () => {
cy.wait('@closeBrowser')
})

// TODO: fix flaky test /~https://github.com/cypress-io/cypress/issues/23220
it('performs mutation to focus open browser when focus button is pressed', { retries: 15 }, () => {
cy.openProject('launchpad', ['--e2e'])

cy.visitLaunchpad()
cy.skipWelcome()

cy.withCtx((ctx) => {
ctx.actions.app.setBrowserStatus('open')
Expand Down Expand Up @@ -262,6 +269,7 @@ describe.skip('Choose a browser page', () => {
})

cy.visitLaunchpad()
cy.skipWelcome()

cy.get('h1').should('contain', 'Choose a browser')

Expand All @@ -270,11 +278,11 @@ describe.skip('Choose a browser page', () => {
})
})

// TODO: fix flaky test /~https://github.com/cypress-io/cypress/issues/23158
it('subscribes to changes to browserStatus/activeBrowser through the browserStatusUpdated subscription', { retries: 15 }, () => {
cy.openProject('launchpad', ['--e2e'])

cy.visitLaunchpad()
cy.skipWelcome()

cy.get('h1').should('contain', 'Choose a browser')

Expand Down Expand Up @@ -306,6 +314,7 @@ describe.skip('Choose a browser page', () => {
it('should return to welcome screen if user modifies the config file to not include the current testing type and recover', () => {
cy.openProject('launchpad', ['--e2e'])
cy.visitLaunchpad()
cy.skipWelcome()

cy.get('h1').should('contain', 'Choose a browser')

Expand All @@ -314,7 +323,7 @@ describe.skip('Choose a browser page', () => {
})

cy.get('h1').should('contain', 'Welcome to Cypress!')
cy.contains('[data-cy-testingtype="e2e"]', 'Not configured')
cy.contains('[data-cy-testingtype="e2e"]', 'Not Configured')

cy.withCtx(async (ctx) => {
await ctx.actions.file.writeFileInProject('cypress.config.js',
Expand All @@ -327,7 +336,7 @@ describe.skip('Choose a browser page', () => {
})

cy.get('h1').should('contain', 'Welcome to Cypress!')
cy.get('[data-cy-testingtype="e2e"]').should('not.contain', 'Not configured')
cy.get('[data-cy-testingtype="e2e"]').should('not.contain', 'Not Configured')
})
})

Expand All @@ -343,6 +352,7 @@ describe.skip('Choose a browser page', () => {
cy.openProject('launchpad', ['--e2e'])

cy.visitLaunchpad()
cy.skipWelcome()

cy.get('h1').should('contain', 'Choose a browser')

Expand Down
22 changes: 0 additions & 22 deletions packages/launchpad/cypress/e2e/global-mode.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,6 @@ describe('Launchpad: Global Mode', () => {
.should('have.length', projectList.length)
})

// FIXME: fix Search by project path logic - https://cypress-io.atlassian.net/browse/UNIFY-646
it.skip('filters project results when searching by project path', () => {
setupAndValidateProjectsList(projectList)
cy.get('#project-search').type('packages')
cy.get('[data-cy="project-card"')
.should('have.length', projectList.length)

cy.get('#project-search').type(`${path.sep}todos`)
cy.contains(defaultMessages.globalPage.noResultsMessage)
})

it('shows "empty results" pages when searching for a non-existent name', () => {
setupAndValidateProjectsList(projectList)
cy.get('#project-search').type('hi')
Expand All @@ -317,17 +306,6 @@ describe('Launchpad: Global Mode', () => {
cy.get('[data-cy="project-card"]')
.should('have.length', projectList.length)
})

// FIXME: fix Search by project path logic - https://cypress-io.atlassian.net/browse/UNIFY-646
it.skip('shows "empty results" pages when searching for a non-existent path', () => {
setupAndValidateProjectsList(projectList)
cy.get('#project-search').type('packages')
cy.get('[data-cy="project-card"')
.should('have.length', projectList.length)

cy.get('#project-search').type(`${path.sep}random`)
cy.contains(defaultMessages.globalPage.noResultsMessage)
})
})
})

Expand Down
17 changes: 0 additions & 17 deletions packages/launchpad/cypress/e2e/migration.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1024,23 +1024,6 @@ describe('Full migration flow for each project', { retries: { openMode: 0, runMo
checkOutcome()
})

// TODO: Do we need to consider this case?
it.skip('completes journey for migration-e2e-defaults-no-specs', () => {
startMigrationFor('migration-e2e-defaults-no-specs')
// no specs, nothing to rename?
cy.get(renameAutoStep).should('not.exist')
// no CT
cy.get(renameManualStep).should('not.exist')
// supportFile is false - cannot migrate
cy.get(renameSupportStep).should('exist')
cy.get(setupComponentStep).should('not.exist')
cy.get(configFileStep).should('exist')

renameSupport()
migrateAndVerifyConfig()
checkOutcome()
})

it('completes journey for migration-e2e-plugins-implicit-index-js', () => {
startMigrationFor('migration-e2e-plugins-implicit-index-js')
// no specs, nothing to rename?
Expand Down
3 changes: 1 addition & 2 deletions packages/launchpad/cypress/e2e/project-setup.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,7 @@ describe('Launchpad: Setup Project', () => {
verifyScaffoldedFiles('e2e')
})

// TODO: fix failing test /~https://github.com/cypress-io/cypress/issues/23418
it.skip('takes the user to first step of ct setup when switching from app', () => {
it('takes the user to first step of ct setup when switching from app', () => {
scaffoldAndOpenProject('pristine-with-e2e-testing')
cy.visitLaunchpad()
verifyWelcomePage({ e2eIsConfigured: true, ctIsConfigured: false })
Expand Down
2 changes: 1 addition & 1 deletion packages/launchpad/cypress/e2e/scaffold-project.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ describe('scaffolding new projects', { defaultCommandTimeout: 7000 }, () => {
assertScaffoldedFilesAreCorrect({ language, testingType: 'component', ctFramework: 'Create React App (v5)', customDirectory: 'without-fixtures' })
})

// NOTE: Skipping this test because it is flaky
// TODO: Fix flaky test
it.skip('generates valid config file for pristine project without cypress installed', () => {
cy.intercept('mutation-ScaffoldedFiles_completeSetup').as('mutationScaffoldedFiles')
cy.intercept('query-MainLaunchpadQuery').as('mainLaunchpadQuery')
Expand Down
70 changes: 64 additions & 6 deletions packages/server/lib/browsers/cdp_automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ export class CdpAutomation implements CDPClient {
on: OnFn
off: OffFn
send: SendDebuggerCommand
private frameTree: any
private gettingFrameTree: any
private frameTree: Protocol.Page.FrameTree | undefined
private gettingFrameTree: Promise<void> | undefined | null

private constructor (private sendDebuggerCommandFn: SendDebuggerCommand, private onFn: OnFn, private offFn: OffFn, private sendCloseCommandFn: SendCloseCommand, private automation: Automation) {
private constructor (private sendDebuggerCommandFn: SendDebuggerCommand, private onFn: OnFn, private offFn: OffFn, private sendCloseCommandFn: SendCloseCommand, private automation: Automation, private focusTabOnScreenshot: boolean = false, private isHeadless: boolean = false) {
onFn('Network.requestWillBeSent', this.onNetworkRequestWillBeSent)
onFn('Network.responseReceived', this.onResponseReceived)
onFn('Network.requestServedFromCache', this.onRequestServedFromCache)
Expand Down Expand Up @@ -197,14 +197,62 @@ export class CdpAutomation implements CDPClient {
await this.sendDebuggerCommandFn('Page.startScreencast', screencastOpts)
}

static async create (sendDebuggerCommandFn: SendDebuggerCommand, onFn: OnFn, offFn: OffFn, sendCloseCommandFn: SendCloseCommand, automation: Automation, protocolManager?: ProtocolManagerShape): Promise<CdpAutomation> {
const cdpAutomation = new CdpAutomation(sendDebuggerCommandFn, onFn, offFn, sendCloseCommandFn, automation)
static async create (sendDebuggerCommandFn: SendDebuggerCommand, onFn: OnFn, offFn: OffFn, sendCloseCommandFn: SendCloseCommand, automation: Automation, protocolManager?: ProtocolManagerShape, focusTabOnScreenshot: boolean = false, isHeadless?: boolean): Promise<CdpAutomation> {
const cdpAutomation = new CdpAutomation(sendDebuggerCommandFn, onFn, offFn, sendCloseCommandFn, automation, focusTabOnScreenshot, isHeadless)

await sendDebuggerCommandFn('Network.enable', protocolManager?.networkEnableOptions ?? DEFAULT_NETWORK_ENABLE_OPTIONS)

return cdpAutomation
}

private async activateMainTab () {
const ActivationTimeoutMessage = 'Unable to communicate with Cypress Extension'

const sendActivationMessage = `
(() => {
if (document.defaultView !== top) { return Promise.resolve() }
return new Promise((res) => {
const onMessage = (ev) => {
if (ev.data.message === 'cypress:extension:main:tab:activated') {
window.removeEventListener('message', onMessage)
res()
}
}
window.addEventListener('message', onMessage)
window.postMessage({ message: 'cypress:extension:activate:main:tab' })
})
})()`

if (this.isHeadless) {
debugVerbose('Headless, so bringing page to front instead of negotiating with extension')
await this.sendDebuggerCommandFn('Page.bringToFront')
} else {
try {
debugVerbose('sending activation message ', sendActivationMessage)
await Promise.race([
this.sendDebuggerCommandFn('Runtime.evaluate', {
expression: sendActivationMessage,
awaitPromise: true,
}),
new Promise((_, reject) => {
setTimeout(() => reject(new Error(ActivationTimeoutMessage)), 500)
}),
])
} catch (e) {
debugVerbose('Error occurred while attempting to activate main tab: ', e)
// If rejected due to timeout, fall back to bringing the main tab to focus -
// this will steal window focus, so it is a last resort. If any other error
// was thrown, re-throw as it was unexpected.
if ((e as Error).message === ActivationTimeoutMessage) {
await this.sendDebuggerCommandFn('Page.bringToFront')
} else {
throw e
}
}
}
}

private onNetworkRequestWillBeSent = async (params: Protocol.Network.RequestWillBeSentEvent) => {
debugVerbose('received networkRequestWillBeSent %o', params)

Expand Down Expand Up @@ -420,7 +468,7 @@ export class CdpAutomation implements CDPClient {
client.on('Page.frameDetached', this._updateFrameTree(client, 'Page.frameDetached'))
}

onRequest = (message, data) => {
onRequest = async (message, data) => {
let setCookie

switch (message) {
Expand Down Expand Up @@ -494,6 +542,16 @@ export class CdpAutomation implements CDPClient {
case 'remote:debugger:protocol':
return this.sendDebuggerCommandFn(data.command, data.params, data.sessionId)
case 'take:screenshot':
debugVerbose('capturing screenshot')

if (this.focusTabOnScreenshot) {
try {
await this.activateMainTab()
} catch (e) {
debugVerbose('Error while attempting to activate main tab: %O', e)
}
}

return this.sendDebuggerCommandFn('Page.captureScreenshot', { format: 'png' })
.catch((err) => {
throw new Error(`The browser responded with an error when Cypress attempted to take a screenshot.\n\nDetails:\n${err.message}`)
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/browsers/chrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ const _handleDownloads = async function (client, downloadsFolder: string, automa
let onReconnect: (client: CriClient) => Promise<void> = async () => undefined

const _setAutomation = async (client: CriClient, automation: Automation, resetBrowserTargets: (shouldKeepTabOpen: boolean) => Promise<void>, options: BrowserLaunchOpts) => {
const cdpAutomation = await CdpAutomation.create(client.send, client.on, client.off, resetBrowserTargets, automation, options.protocolManager)
const cdpAutomation = await CdpAutomation.create(client.send, client.on, client.off, resetBrowserTargets, automation, options.protocolManager, true, options.isTextTerminal)

automation.use(cdpAutomation)

Expand Down
Loading

4 comments on commit 7e1592a

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7e1592a Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.7/linux-x64/feat/protocol_shadow_dom_support-7e1592ae0131d9f1294e9b28377e51f85ad94069/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7e1592a Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.7/linux-arm64/feat/protocol_shadow_dom_support-7e1592ae0131d9f1294e9b28377e51f85ad94069/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7e1592a Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.7/darwin-x64/feat/protocol_shadow_dom_support-7e1592ae0131d9f1294e9b28377e51f85ad94069/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7e1592a Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.7/darwin-arm64/feat/protocol_shadow_dom_support-7e1592ae0131d9f1294e9b28377e51f85ad94069/cypress.tgz

Please sign in to comment.