Skip to content

Commit

Permalink
feat(webkit): fix multidomain driver tests in WebKit (#23442)
Browse files Browse the repository at this point in the history
* Initial async changes

* Small fixes and test updates.

* updating tests

* Fixes for cookie login tests

* remove the onlys

* Most tests passing

* Fix driver tests?

* fix firefox test?

* fix unit tests

* fix tests??

* a better check

* fix integration tests

* minor cleanup

* Comment out tyler fix for 10.0 origin issue

* also fix integration tests

* remove fixmes

* Adding Retries for cookie actions. May break other error tests.

* Address (some) PR comments

* factor console logging out of run.ts

* fix print-run

* minimize diff

* chore(server): convert browsers/index to typescript

* fix tests

* update stubbed tests

* convert electron.js to .ts

* Suggestions from code review

* Clean up new type errors

* electron.connectToExisting can be sync

* more type errors for the type god

* Suggestions from code review

* refactor: move more of video capture into browser automations

* unit tests

* refactor: move videoCapture to browsers

* fix snapshots

* update to warn about cross origin command AUT in assertions

* Fix type errors

* fix multi-spec videos?

* webkit video recording works!

* webkit system tests

* skip system-tests that won't be fixed in this PR

~60 tests skipped out of ~99:
* ~6 skipped due to needing multidomain support
* ~8 skipped due to missing before:browser:launch support
* ~22 skipped due to broken stack traces

* fix single-tab mode

* cleanup/api renames

* fix more tests

* minimize diff, fix ff

* fix unit tests

* fix tests

* cleanup

* Move document.cookie patch to injection

* enable ci job

* fix up/add request events to webkit automation

* update undefined message

* doesn't need an underscore

* Adding iframe patching.

* forward errors prior to attaching

* Add error message when using visit to visit a cross origin site with the onLoad or onBeforeLoad options.

* Attempt to fix test errors.

* more fixes, but not all

* use the origin policy

* Fix types

* more fixes

* consider chromeWebSecurity when checking if you can communicate with the AUT

* firefox

* prevent hangs if before unload happens after on load.

* Fix some ToDos

* code cleanup

* remove quotes

* Code review changes

* more cr changes

* fix tests possibly

* Updating cy.origin websocket for webkit connection error

* for realz this time

* temp fix for before:unload/load issue

* roll back change

* Fix some flake

* temporarily comment out autWindow.Error patch

* updating cookies to match develop

* update circle.yml

* commenting out driver-integration-tests-webkit-experimentalSessionAndOrigin

* revert cookie test change

* revert cross origin change

* Fix clear cookie problem

* Try it again

* test cy.origin in webkit

* Skip origin tests when running in webkit

* missed one

* attempt to revert web_security changes

* enable sessions on webkit

* maybe this fixes system tests??

* Update web_security_spec.js

* Update web_security_spec.js

* file cleanup

* Unify socket creation logic

* Address PR Comments

Co-authored-by: mjhenkes <mjhenkes@gmail.com>
Co-authored-by: Matt Schile <mschile@cypress.io>
  • Loading branch information
3 people committed Oct 12, 2022
1 parent b7213c9 commit 688b7ea
Show file tree
Hide file tree
Showing 53 changed files with 267 additions and 202 deletions.
12 changes: 6 additions & 6 deletions .circleci/config.yml
Expand Up @@ -47,6 +47,7 @@ linuxArm64WorkflowFilters: &linux-arm64-workflow-filters
when:
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ 'webkit-multidomain', << pipeline.git.branch >> ]
- equal: [ 'issue-23843_electron_21_upgrade', << pipeline.git.branch >> ]
- matches:
pattern: "-release$"
Expand Down Expand Up @@ -1856,7 +1857,7 @@ jobs:
name: Build
command: yarn workspace @cypress/mount-utils build
- store-npm-logs

npm-xpath:
<<: *defaults
resource_class: small
Expand Down Expand Up @@ -2437,11 +2438,10 @@ linux-x64-workflow: &linux-x64-workflow
context: test-runner:cypress-record-key
requires:
- build
# TODO: Implement WebKit network automation to fix the majority of these tests before re-enabling
# - driver-integration-tests-webkit-experimentalSessionAndOrigin:
# context: test-runner:cypress-record-key
# requires:
# - build
- driver-integration-tests-webkit-experimentalSessionAndOrigin:
context: test-runner:cypress-record-key
requires:
- build
- run-frontend-shared-component-tests-chrome:
context: [test-runner:cypress-record-key, test-runner:launchpad-tests, test-runner:percy]
percy: true
Expand Down
8 changes: 2 additions & 6 deletions packages/app/src/runner/index.ts
Expand Up @@ -22,7 +22,7 @@ import { getRunnerElement, empty } from './utils'
import { IframeModel } from './iframe-model'
import { AutIframe } from './aut-iframe'
import { EventManager } from './event-manager'
import { client } from '@packages/socket/lib/browser'
import { createWebsocket as createWebsocketIo } from '@packages/socket/lib/browser'
import { decodeBase64Unicode } from '@packages/frontend-shared/src/utils/base64'
import type { AutomationElementId } from '@packages/types/src'
import { useSnapshotStore } from './snapshot-store'
Expand All @@ -31,11 +31,7 @@ import { useStudioStore } from '../store/studio-store'
let _eventManager: EventManager | undefined

export function createWebsocket (config: Cypress.Config) {
const ws = client({
path: config.socketIoRoute,
// TODO(webkit): the websocket socket.io transport is busted in WebKit, need polling
transports: config.browser.family === 'webkit' ? ['polling'] : ['websocket'],
})
const ws = createWebsocketIo({ path: config.socketIoRoute, browserFamily: config.browser.family })

ws.on('connect', () => {
ws.emit('runner:connected')
Expand Down
19 changes: 19 additions & 0 deletions packages/driver/cypress/e2e/commands/cookies.cy.js
Expand Up @@ -2,6 +2,25 @@ const { assertLogLength } = require('../../support/utils')
const { stripIndent } = require('common-tags')
const { Promise } = Cypress

describe('src/cy/commands/cookies - no stub', () => {
it('clears all cookies', () => {
cy.setCookie('foo', 'bar')
cy.getCookies().should('have.length', 1)
cy.clearCookies()
cy.getCookies().should('have.length', 0)
})

it('clears a single cookie', () => {
cy.setCookie('foo', 'bar')
cy.setCookie('key', 'val')
cy.getCookies().should('have.length', 2)
cy.clearCookie('foo')
cy.getCookies().should('have.length', 1).then((cookies) => {
expect(cookies[0].name).to.eq('key')
})
})
})

describe('src/cy/commands/cookies', () => {
beforeEach(() => {
// call through normally on everything
Expand Down
138 changes: 52 additions & 86 deletions packages/driver/cypress/e2e/commands/sessions/sessions.cy.js
Expand Up @@ -24,6 +24,27 @@ const clearAllSavedSessions = () => {
})
}

// In webkit, the clear page and clear cookies, etc log messages may be reversed. This isn't an issue, but we just want to test we have both messages.
const validateClearLogs = (logs, sessionGroupId) => {
let clearPageLogIndex = 0
let clearCookiesIndex = 1

if (logs[1].get('name') === 'Clear page') {
clearPageLogIndex = 1
clearCookiesIndex = 0
}

expect(logs[clearPageLogIndex].get()).to.contain({
name: 'Clear page',
group: sessionGroupId,
})

expect(logs[clearCookiesIndex].get()).to.contain({
displayName: 'Clear cookies, localStorage and sessionStorage',
group: sessionGroupId,
})
}

describe('cy.session', { retries: 0 }, () => {
describe('args', () => {
it('accepts string as id', () => {
Expand Down Expand Up @@ -200,15 +221,7 @@ describe('cy.session', { retries: 0 }, () => {
},
})

expect(logs[1].get()).to.contain({
name: 'Clear page',
group: sessionGroupId,
})

expect(logs[2].get()).to.contain({
displayName: 'Clear cookies, localStorage and sessionStorage',
group: sessionGroupId,
})
validateClearLogs([logs[1], logs[2]], sessionGroupId)

const createNewSessionGroup = logs[3].get()

Expand Down Expand Up @@ -282,15 +295,7 @@ describe('cy.session', { retries: 0 }, () => {
},
})

expect(logs[1].get()).to.contain({
name: 'Clear page',
group: sessionGroupId,
})

expect(logs[2].get()).to.contain({
displayName: 'Clear cookies, localStorage and sessionStorage',
group: sessionGroupId,
})
validateClearLogs([logs[1], logs[2]], sessionGroupId)

const createNewSessionGroup = logs[3].get()

Expand Down Expand Up @@ -344,15 +349,7 @@ describe('cy.session', { retries: 0 }, () => {
},
})

expect(logs[1].get()).to.contain({
name: 'Clear page',
group: sessionGroupId,
})

expect(logs[2].get()).to.contain({
displayName: 'Clear cookies, localStorage and sessionStorage',
group: sessionGroupId,
})
validateClearLogs([logs[1], logs[2]], sessionGroupId)

const createNewSessionGroup = logs[3].get()

Expand Down Expand Up @@ -437,15 +434,7 @@ describe('cy.session', { retries: 0 }, () => {
},
})

expect(logs[1].get()).to.contain({
name: 'Clear page',
group: sessionGroupId,
})

expect(logs[2].get()).to.contain({
displayName: 'Clear cookies, localStorage and sessionStorage',
group: sessionGroupId,
})
validateClearLogs([logs[1], logs[2]], sessionGroupId)

const restoreSavedSessionGroup = logs[3].get()

Expand Down Expand Up @@ -500,15 +489,7 @@ describe('cy.session', { retries: 0 }, () => {
},
})

expect(logs[1].get()).to.contain({
name: 'Clear page',
group: sessionGroupId,
})

expect(logs[2].get()).to.contain({
displayName: 'Clear cookies, localStorage and sessionStorage',
group: sessionGroupId,
})
validateClearLogs([logs[1], logs[2]], sessionGroupId)

const restoreSavedSessionGroup = logs[3].get()

Expand Down Expand Up @@ -582,15 +563,7 @@ describe('cy.session', { retries: 0 }, () => {
},
})

expect(logs[1].get()).to.contain({
name: 'Clear page',
group: sessionGroupId,
})

expect(logs[2].get()).to.contain({
displayName: 'Clear cookies, localStorage and sessionStorage',
group: sessionGroupId,
})
validateClearLogs([logs[1], logs[2]], sessionGroupId)

const restoreSavedSessionGroup = logs[3].get()

Expand Down Expand Up @@ -618,15 +591,7 @@ describe('cy.session', { retries: 0 }, () => {

expect(logs[6].get('error').message).to.eq('Your `cy.session` **validate** callback returned false.')

expect(logs[7].get()).to.contain({
name: 'Clear page',
group: sessionGroupId,
})

expect(logs[8].get()).to.contain({
displayName: 'Clear cookies, localStorage and sessionStorage',
group: sessionGroupId,
})
validateClearLogs([logs[7], logs[8]], sessionGroupId)

const createNewSessionGroup = logs[9].get()

Expand Down Expand Up @@ -692,15 +657,7 @@ describe('cy.session', { retries: 0 }, () => {
},
})

expect(logs[1].get()).to.contain({
name: 'Clear page',
group: sessionGroupId,
})

expect(logs[2].get()).to.contain({
displayName: 'Clear cookies, localStorage and sessionStorage',
group: sessionGroupId,
})
validateClearLogs([logs[1], logs[2]], sessionGroupId)

const restoreSavedSessionGroup = logs[3].get()

Expand Down Expand Up @@ -728,15 +685,7 @@ describe('cy.session', { retries: 0 }, () => {

expect(logs[6].get('error').message).to.eq('Your `cy.session` **validate** callback returned false.')

expect(logs[7].get()).to.contain({
name: 'Clear page',
group: sessionGroupId,
})

expect(logs[8].get()).to.contain({
displayName: 'Clear cookies, localStorage and sessionStorage',
group: sessionGroupId,
})
validateClearLogs([logs[7], logs[8]], sessionGroupId)

const createNewSessionGroup = logs[9].get()

Expand Down Expand Up @@ -1046,7 +995,10 @@ describe('cy.session', { retries: 0 }, () => {
cy.once('fail', (err) => {
expect(err.message).contain('Expected to find element: `#does_not_exist`')
expect(err.message).contain(errorHookMessage)
expect(err.codeFrame).exist
// TODO: Webkit does not have correct stack traces on errors currently
if (Cypress.isBrowser('!webkit')) {
expect(err.codeFrame).exist
}

done()
})
Expand All @@ -1064,7 +1016,11 @@ describe('cy.session', { retries: 0 }, () => {
cy.once('fail', (err) => {
expect(err.message).contain('validate error')
expect(err.message).contain(errorHookMessage)
expect(err.codeFrame).exist
// TODO: Webkit does not have correct stack traces on errors currently
if (Cypress.isBrowser('!webkit')) {
expect(err.codeFrame).exist
}

done()
})

Expand All @@ -1081,7 +1037,10 @@ describe('cy.session', { retries: 0 }, () => {
cy.once('fail', (err) => {
expect(err.message).contain('validate error')
expect(err.message).contain(errorHookMessage)
expect(err.codeFrame).exist
// TODO: Webkit does not have correct stack traces on errors currently
if (Cypress.isBrowser('!webkit')) {
expect(err.codeFrame).exist
}

done()
})
Expand All @@ -1099,7 +1058,10 @@ describe('cy.session', { retries: 0 }, () => {
cy.once('fail', (err) => {
expect(err.message).to.contain('Your `cy.session` **validate** callback returned false.')
expect(err.message).contain(errorHookMessage)
expect(err.codeFrame).exist
// TODO: Webkit does not have correct stack traces on errors currently
if (Cypress.isBrowser('!webkit')) {
expect(err.codeFrame).exist
}

done()
})
Expand All @@ -1117,7 +1079,11 @@ describe('cy.session', { retries: 0 }, () => {
cy.once('fail', (err) => {
expect(err.message).to.contain('Your `cy.session` **validate** callback resolved false.')
expect(err.message).contain(errorHookMessage)
expect(err.codeFrame).exist
// TODO: Webkit does not have correct stack traces on errors currently
if (Cypress.isBrowser('!webkit')) {
expect(err.codeFrame).exist
}

done()
})

Expand Down
4 changes: 2 additions & 2 deletions packages/driver/cypress/e2e/e2e/origin/basic_login.cy.ts
@@ -1,4 +1,4 @@
describe('basic login', () => {
describe('basic login', { browser: '!webkit' }, () => {
// Scenario, Token based auth. Visit site, redirect to IDP hosted on secondary origin, login and redirect back to site.
describe('visit primary first', () => {
it('logs in with idp redirect', () => {
Expand Down Expand Up @@ -148,7 +148,7 @@ describe('basic login', () => {
})
})

describe('Multi-step Auth', () => {
describe('Multi-step Auth', { browser: '!webkit' }, () => {
// TODO: cy.origin does not work in cy.origin yet.
it.skip('final auth redirects back to localhost - nested', () => {
cy.visit('/fixtures/auth/index.html')
Expand Down
@@ -1,6 +1,6 @@
import { findCrossOriginLogs } from '../../../../support/utils'

context('cy.origin actions', () => {
context('cy.origin actions', { browser: '!webkit' }, () => {
beforeEach(() => {
cy.visit('/fixtures/primary-origin.html')
})
Expand Down
@@ -1,6 +1,6 @@
import { findCrossOriginLogs } from '../../../../support/utils'

context('cy.origin aliasing', () => {
context('cy.origin aliasing', { browser: '!webkit' }, () => {
beforeEach(() => {
cy.visit('/fixtures/primary-origin.html')
})
Expand Down
@@ -1,6 +1,6 @@
import { findCrossOriginLogs } from '../../../../support/utils'

context('cy.origin assertions', () => {
context('cy.origin assertions', { browser: '!webkit' }, () => {
beforeEach(() => {
cy.visit('/fixtures/primary-origin.html')
cy.get('a[data-cy="dom-link"]').click()
Expand Down
@@ -1,6 +1,6 @@
import { findCrossOriginLogs } from '../../../../support/utils'

context('cy.origin connectors', () => {
context('cy.origin connectors', { browser: '!webkit' }, () => {
beforeEach(() => {
cy.visit('/fixtures/primary-origin.html')
cy.get('a[data-cy="dom-link"]').click()
Expand Down
@@ -1,6 +1,6 @@
import { findCrossOriginLogs, assertLogLength } from '../../../../support/utils'

describe('cy.origin cookies', () => {
describe('cy.origin cookies', { browser: '!webkit' }, () => {
context('client side', () => {
beforeEach(() => {
cy.visit('/fixtures/primary-origin.html')
Expand Down
@@ -1,6 +1,6 @@
import { findCrossOriginLogs } from '../../../../support/utils'

context('cy.origin files', () => {
context('cy.origin files', { browser: '!webkit' }, () => {
beforeEach(() => {
cy.visit('/fixtures/primary-origin.html')
cy.get('a[data-cy="cross-origin-secondary-link"]').click()
Expand Down
@@ -1,6 +1,6 @@
import { findCrossOriginLogs } from '../../../../support/utils'

context('cy.origin local storage', () => {
context('cy.origin local storage', { browser: '!webkit' }, () => {
beforeEach(() => {
cy.visit('/fixtures/primary-origin.html')
cy.get('a[data-cy="cross-origin-secondary-link"]').click()
Expand Down

7 comments on commit 688b7ea

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 688b7ea Oct 12, 2022

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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.11.0/linux-x64/develop-688b7ea33e8243a76fc1b3bd7f5ef7f2bfba07f9/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 688b7ea Oct 12, 2022

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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.11.0/linux-arm64/develop-688b7ea33e8243a76fc1b3bd7f5ef7f2bfba07f9/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 688b7ea Oct 12, 2022

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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.11.0/darwin-x64/develop-688b7ea33e8243a76fc1b3bd7f5ef7f2bfba07f9/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 688b7ea Oct 12, 2022

Choose a reason for hiding this comment

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

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

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.11.0/win32-x64/develop-688b7ea33e8243a76fc1b3bd7f5ef7f2bfba07f9/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 688b7ea Oct 12, 2022

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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.11.0/darwin-arm64/develop-688b7ea33e8243a76fc1b3bd7f5ef7f2bfba07f9/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 688b7ea Oct 13, 2022

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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.11.0/linux-x64/develop-688b7ea33e8243a76fc1b3bd7f5ef7f2bfba07f9/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 688b7ea Oct 13, 2022

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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.11.0/linux-x64/develop-688b7ea33e8243a76fc1b3bd7f5ef7f2bfba07f9/cypress.tgz

Please sign in to comment.