Skip to content

Commit e3161a0

Browse files
mjhenkesmschile
andauthored
chore: [Multi-domain] Break out separate CI tasks to test the driver with experimentalSessionAndOrigin on (#21148)
* Attempt to run tests without the feature flag and the multi-domain folder * do it for real this time dummy * trying circleci changes * valid file??? * moar changes! * i am a master of bash scripting * try another exclude pattern * one more time with feeling * lets do it again * maybe this? * different parallel group * lets try this * updating tests phase 1 * updating tests phase 2 * Apply suggestions from code review Co-authored-by: Matt Schile <mschile@gmail.com> * Update tests * Run more tests * Re-locate system test * Flex message for firefox Co-authored-by: Matt Schile <mschile@gmail.com>
1 parent d7ce865 commit e3161a0

File tree

9 files changed

+183
-224
lines changed

9 files changed

+183
-224
lines changed

circle.yml

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,10 @@ commands:
406406
description: chrome channel to install
407407
type: string
408408
default: ''
409+
experimentalSessionAndOrigin:
410+
description: experimental flag to apply
411+
type: boolean
412+
default: false
409413
steps:
410414
- restore_cached_workspace
411415
- when:
@@ -423,8 +427,13 @@ commands:
423427
424428
if [[ -v MAIN_RECORD_KEY ]]; then
425429
# internal PR
426-
CYPRESS_RECORD_KEY=$MAIN_RECORD_KEY \
427-
yarn cypress:run --record --parallel --group 5x-driver-<<parameters.browser>> --browser <<parameters.browser>>
430+
if <<parameters.experimentalSessionAndOrigin>>; then
431+
CYPRESS_RECORD_KEY=$MAIN_RECORD_KEY \
432+
yarn cypress:run-experimentalSessionAndOrigin --record --parallel --group 5x-driver-<<parameters.browser>>-experimentalSessionAndOrigin --browser <<parameters.browser>>
433+
else
434+
CYPRESS_RECORD_KEY=$MAIN_RECORD_KEY \
435+
yarn cypress:run --record --parallel --group 5x-driver-<<parameters.browser>> --browser <<parameters.browser>>
436+
fi
428437
else
429438
# external PR
430439
TESTFILES=$(circleci tests glob "cypress/integration/**/*spec.*" | circleci tests split --total=$CIRCLE_NODE_TOTAL)
@@ -433,7 +442,11 @@ commands:
433442
if [[ -z "$TESTFILES" ]]; then
434443
echo "Empty list of test files"
435444
fi
436-
yarn cypress:run --browser <<parameters.browser>> --spec $TESTFILES
445+
if <<parameters.experimentalSessionAndOrigin>>; then
446+
yarn cypress:run-experimentalSessionAndOrigin --browser <<parameters.browser>> --spec $TESTFILES
447+
else
448+
yarn cypress:run --browser <<parameters.browser>> --spec $TESTFILES
449+
fi
437450
fi
438451
working_directory: packages/driver
439452
- verify-mocha-results
@@ -1294,6 +1307,44 @@ jobs:
12941307
- run-driver-integration-tests:
12951308
browser: electron
12961309

1310+
driver-integration-tests-chrome-experimentalSessionAndOrigin:
1311+
<<: *defaults
1312+
resource_class: medium
1313+
parallelism: 5
1314+
steps:
1315+
- run-driver-integration-tests:
1316+
browser: chrome
1317+
install-chrome-channel: stable
1318+
experimentalSessionAndOrigin: true
1319+
1320+
driver-integration-tests-chrome-beta-experimentalSessionAndOrigin:
1321+
<<: *defaults
1322+
resource_class: medium
1323+
parallelism: 5
1324+
steps:
1325+
- run-driver-integration-tests:
1326+
browser: chrome:beta
1327+
install-chrome-channel: beta
1328+
experimentalSessionAndOrigin: true
1329+
1330+
driver-integration-tests-firefox-experimentalSessionAndOrigin:
1331+
<<: *defaults
1332+
resource_class: medium
1333+
parallelism: 5
1334+
steps:
1335+
- run-driver-integration-tests:
1336+
browser: firefox
1337+
experimentalSessionAndOrigin: true
1338+
1339+
driver-integration-tests-electron-experimentalSessionAndOrigin:
1340+
<<: *defaults
1341+
resource_class: medium
1342+
parallelism: 5
1343+
steps:
1344+
- run-driver-integration-tests:
1345+
browser: electron
1346+
experimentalSessionAndOrigin: true
1347+
12971348
desktop-gui-integration-tests-7x:
12981349
<<: *defaults
12991350
parallelism: 7
@@ -2084,6 +2135,22 @@ linux-workflow: &linux-workflow
20842135
context: test-runner:cypress-record-key
20852136
requires:
20862137
- build
2138+
- driver-integration-tests-chrome-experimentalSessionAndOrigin:
2139+
context: test-runner:cypress-record-key
2140+
requires:
2141+
- build
2142+
- driver-integration-tests-chrome-beta-experimentalSessionAndOrigin:
2143+
context: test-runner:cypress-record-key
2144+
requires:
2145+
- build
2146+
- driver-integration-tests-firefox-experimentalSessionAndOrigin:
2147+
context: test-runner:cypress-record-key
2148+
requires:
2149+
- build
2150+
- driver-integration-tests-electron-experimentalSessionAndOrigin:
2151+
context: test-runner:cypress-record-key
2152+
requires:
2153+
- build
20872154
- runner-integration-tests-chrome:
20882155
context: [test-runner:cypress-record-key, test-runner:percy]
20892156
requires:
@@ -2180,6 +2247,10 @@ linux-workflow: &linux-workflow
21802247
- driver-integration-tests-chrome
21812248
- driver-integration-tests-chrome-beta
21822249
- driver-integration-tests-electron
2250+
- driver-integration-tests-firefox-experimentalSessionAndOrigin
2251+
- driver-integration-tests-chrome-experimentalSessionAndOrigin
2252+
- driver-integration-tests-chrome-beta-experimentalSessionAndOrigin
2253+
- driver-integration-tests-electron-experimentalSessionAndOrigin
21832254
- system-tests-non-root
21842255
- system-tests-firefox
21852256
- system-tests-electron

packages/driver/cypress.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@
1313
"retries": {
1414
"runMode": 2,
1515
"openMode": 0
16-
},
17-
"experimentalSessionAndOrigin": true
16+
}
1817
}

packages/driver/cypress/integration/commands/navigation_spec.js

Lines changed: 71 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,10 +1409,11 @@ describe('src/cy/commands/navigation', () => {
14091409
it('throws when attempting to visit a 2nd domain on different port', function (done) {
14101410
cy.on('fail', (err) => {
14111411
const { lastLog } = this
1412+
const experimentalMessage = Cypress.config('experimentalSessionAndOrigin') ? `You likely forgot to use \`cy.origin()\`:\n` : `In order to visit a different origin, you can enable the \`experimentalSessionAndOrigin\` flag and use \`cy.origin()\`:\n`
14121413

14131414
expect(err.message).to.equal(stripIndent`\
14141415
\`cy.visit()\` failed because you are attempting to visit a URL that is of a different origin.\n
1415-
You likely forgot to use \`cy.origin()\`:\n
1416+
${experimentalMessage}
14161417
\`cy.visit('http://localhost:3500/fixtures/generic.html')\`
14171418
\`<commands targeting http://localhost:3500 go here>\`\n
14181419
\`cy.origin('http://localhost:3501', () => {\`
@@ -1441,10 +1442,11 @@ describe('src/cy/commands/navigation', () => {
14411442
it('throws when attempting to visit a 2nd domain on different protocol', function (done) {
14421443
cy.on('fail', (err) => {
14431444
const { lastLog } = this
1445+
const experimentalMessage = Cypress.config('experimentalSessionAndOrigin') ? `You likely forgot to use \`cy.origin()\`:\n` : `In order to visit a different origin, you can enable the \`experimentalSessionAndOrigin\` flag and use \`cy.origin()\`:\n`
14441446

14451447
expect(err.message).to.equal(stripIndent`\
14461448
\`cy.visit()\` failed because you are attempting to visit a URL that is of a different origin.\n
1447-
You likely forgot to use \`cy.origin()\`:\n
1449+
${experimentalMessage}
14481450
\`cy.visit('http://localhost:3500/fixtures/generic.html')\`
14491451
\`<commands targeting http://localhost:3500 go here>\`\n
14501452
\`cy.origin('https://localhost:3502', () => {\`
@@ -1473,10 +1475,11 @@ describe('src/cy/commands/navigation', () => {
14731475
it('throws when attempting to visit a 2nd domain on different superdomain', function (done) {
14741476
cy.on('fail', (err) => {
14751477
const { lastLog } = this
1478+
const experimentalMessage = Cypress.config('experimentalSessionAndOrigin') ? `You likely forgot to use \`cy.origin()\`:\n` : `In order to visit a different origin, you can enable the \`experimentalSessionAndOrigin\` flag and use \`cy.origin()\`:\n`
14761479

14771480
expect(err.message).to.equal(stripIndent`\
14781481
\`cy.visit()\` failed because you are attempting to visit a URL that is of a different origin.\n
1479-
You likely forgot to use \`cy.origin()\`:\n
1482+
${experimentalMessage}
14801483
\`cy.visit('http://localhost:3500/fixtures/generic.html')\`
14811484
\`<commands targeting http://localhost:3500 go here>\`\n
14821485
\`cy.origin('http://foobar.com:3500', () => {\`
@@ -1505,10 +1508,11 @@ describe('src/cy/commands/navigation', () => {
15051508
it('throws attempting to visit 2 unique ip addresses', function (done) {
15061509
cy.on('fail', (err) => {
15071510
const { lastLog } = this
1511+
const experimentalMessage = Cypress.config('experimentalSessionAndOrigin') ? `You likely forgot to use \`cy.origin()\`:\n` : `In order to visit a different origin, you can enable the \`experimentalSessionAndOrigin\` flag and use \`cy.origin()\`:\n`
15081512

15091513
expect(err.message).to.equal(stripIndent`\
15101514
\`cy.visit()\` failed because you are attempting to visit a URL that is of a different origin.\n
1511-
You likely forgot to use \`cy.origin()\`:\n
1515+
${experimentalMessage}
15121516
\`cy.visit('http://127.0.0.1:3500/fixtures/generic.html')\`
15131517
\`<commands targeting http://127.0.0.1:3500 go here>\`\n
15141518
\`cy.origin('http://0.0.0.0:3500', () => {\`
@@ -2145,6 +2149,53 @@ describe('src/cy/commands/navigation', () => {
21452149
.get('#does-not-exist', { timeout: 200 }).should('have.class', 'foo')
21462150
})
21472151

2152+
it('displays cross origin failures when navigating to a cross origin', { pageLoadTimeout: 3000 }, function (done) {
2153+
cy.on('fail', (err) => {
2154+
const { lastLog } = this
2155+
2156+
if (Cypress.config('experimentalSessionAndOrigin')) {
2157+
// When the experimentalSessionAndOrigin feature is enabled, we will timeout and display this message.
2158+
expect(err.message).to.equal(stripIndent`\
2159+
Timed out after waiting \`3000ms\` for your remote page to load on origin(s):\n
2160+
- \`http://localhost:3500\`\n
2161+
A cross-origin request for \`http://www.foobar.com:3500/fixtures/multi-domain-secondary.html\` was detected.\n
2162+
A command that triggers cross-origin navigation must be immediately followed by a \`cy.origin()\` command:\n
2163+
\`cy.origin(\'http://foobar.com:3500\', () => {\`
2164+
\` <commands targeting http://www.foobar.com:3500 go here>\`
2165+
\`})\`\n
2166+
If the cross-origin request was an intermediary state, you can try increasing the \`pageLoadTimeout\` value in \`cypress.json\` to wait longer.\n
2167+
Browsers will not fire the \`load\` event until all stylesheets and scripts are done downloading.\n
2168+
When this \`load\` event occurs, Cypress will continue running commands.`)
2169+
2170+
expect(err.docsUrl).to.eq('https://on.cypress.io/origin')
2171+
} else {
2172+
const error = Cypress.isBrowser('firefox') ? 'Permission denied to access property "document" on cross-origin object' : 'Blocked a frame with origin "http://localhost:3500" from accessing a cross-origin frame.'
2173+
2174+
// When the experimentalSessionAndOrigin feature is disabled, we will immediately and display this message.
2175+
expect(err.message).to.equal(stripIndent`\
2176+
Cypress detected a cross origin error happened on page load:\n
2177+
> ${error}\n
2178+
Before the page load, you were bound to the origin policy:\n
2179+
> http://localhost:3500\n
2180+
A cross origin error happens when your application navigates to a new URL which does not match the origin policy above.\n
2181+
A new URL does not match the origin policy if the 'protocol', 'port' (if specified), and/or 'host' (unless of the same superdomain) are different.\n
2182+
Cypress does not allow you to navigate to a different origin URL within a single test.\n
2183+
You may need to restructure some of your test code to avoid this problem.\n
2184+
Alternatively you can also disable Chrome Web Security in Chromium-based browsers which will turn off this restriction by setting { chromeWebSecurity: false } in \`cypress.json\`.`)
2185+
2186+
expect(err.docsUrl).to.eq('https://on.cypress.io/cross-origin-violation')
2187+
}
2188+
2189+
assertLogLength(this.logs, 6)
2190+
expect(lastLog.get('error')).to.eq(err)
2191+
2192+
done()
2193+
})
2194+
2195+
cy.visit('/fixtures/multi-domain.html')
2196+
cy.get('a[data-cy="cross-origin-secondary-link"]').click()
2197+
})
2198+
21482199
return null
21492200
})
21502201
})
@@ -2269,41 +2320,28 @@ describe('src/cy/commands/navigation', () => {
22692320
})
22702321
})
22712322

2272-
it('waits for stability at the end of the command queue when not stable', { experimentalSessionAndOrigin: false }, (done) => {
2323+
it('tests waiting on stability at the end of the command queue', (done) => {
22732324
cy
22742325
.visit('/fixtures/generic.html')
22752326
.then((win) => {
2276-
cy.on('window:load', () => {
2327+
// We do not wait if the experimentalSessionAndOrigin feature is enabled
2328+
if (Cypress.config('experimentalSessionAndOrigin')) {
2329+
const onLoad = cy.spy()
2330+
2331+
cy.on('window:load', onLoad)
2332+
22772333
cy.on('command:queue:end', () => {
2334+
expect(onLoad).not.have.been.called
22782335
done()
22792336
})
2280-
})
2281-
2282-
cy.on('command:queue:before:end', () => {
2283-
// force us to become unstable immediately
2284-
// else the beforeunload event fires at the end
2285-
// of the tick which is too late
2286-
cy.isStable(false, 'testing')
2287-
2288-
win.location.href = '/timeout?ms=100'
2289-
})
2290-
2291-
return null
2292-
})
2293-
})
2294-
2295-
it('does not wait for stability at the end of the command queue when not stable with experimentalSessionAndOrigin', (done) => {
2296-
const onLoad = cy.spy()
2297-
2298-
cy
2299-
.visit('/fixtures/generic.html')
2300-
.then((win) => {
2301-
cy.on('window:load', onLoad)
2302-
2303-
cy.on('command:queue:end', () => {
2304-
expect(onLoad).not.have.been.called
2305-
done()
2306-
})
2337+
} else {
2338+
// We do wait if the experimentalSessionAndOrigin feature is not enabled
2339+
cy.on('window:load', () => {
2340+
cy.on('command:queue:end', () => {
2341+
done()
2342+
})
2343+
})
2344+
}
23072345

23082346
cy.on('command:queue:before:end', () => {
23092347
// force us to become unstable immediately
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
describe('stability', () => {
2+
describe('before each transitions', () => {
3+
describe('transitioning from a before block to an it block while unstable', () => {
4+
beforeEach(() => {
5+
cy.visit('/fixtures/auth/index.html')
6+
cy.window().then((win) => {
7+
win.location.href = 'http://localhost:3500/timeout?ms=1000'
8+
})
9+
})
10+
11+
it('fails if the page does not load within the page load timeout', { defaultCommandTimeout: 50, pageLoadTimeout: 500 }, (done) => {
12+
cy.on('fail', (err) => {
13+
expect(err.message).to.include(`Timed out after waiting \`500ms\` for your remote page to load.`)
14+
done()
15+
})
16+
17+
cy.get('[data-cy="login-idp"]').click() // Takes you to idp.com
18+
})
19+
20+
it('waits for the page to load before running the command', { defaultCommandTimeout: 50 }, () => {
21+
cy.get('body').invoke('text').should('equal', 'timeout')
22+
})
23+
24+
it('will retry and fail the command after the page loads', { defaultCommandTimeout: 50 }, (done) => {
25+
cy.on('fail', (err) => {
26+
expect(err.message).to.include(`Timed out retrying after 50ms: expected 'timeout' to equal 'not timeout'`)
27+
done()
28+
})
29+
30+
cy.get('body').invoke('text').should('equal', 'not timeout')
31+
})
32+
})
33+
})
34+
})

packages/driver/cypress/integration/e2e/stability_spec.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

packages/driver/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"scripts": {
66
"clean-deps": "rm -rf node_modules",
77
"cypress:open": "node ../../scripts/cypress open",
8-
"cypress:run": "node ../../scripts/cypress run",
8+
"cypress:run": "node ../../scripts/cypress run --spec \"cypress/integration/*/*\",\"cypress/integration/*/!(multi-domain)/**/*\"",
9+
"cypress:open-experimentalSessionAndOrigin": "node ../../scripts/cypress open --config experimentalSessionAndOrigin=true",
10+
"cypress:run-experimentalSessionAndOrigin": "node ../../scripts/cypress run --config experimentalSessionAndOrigin=true",
911
"postinstall": "patch-package",
1012
"start": "node -e 'console.log(require(`chalk`).red(`\nError:\n\tRunning \\`yarn start\\` is no longer needed for driver/cypress tests.\n\tWe now automatically spawn the server in the pluginsFile.\n\tChanges to the server will be watched and reloaded automatically.`))'"
1113
},

0 commit comments

Comments
 (0)