Skip to content

Commit ca6edab

Browse files
chrisbreidingemilyrohrboughmjhenkesAtofStrykerryanthemanuel
authored
10.11.0 (#4790)
* 10.11.0 * Update cy.origin dependencies / remove Cypress.require() (#4789) * update documentations around test isolation (#4797) Co-authored-by: Matt Henkes <[email protected]> Co-authored-by: Bill Glesias <[email protected]> Co-authored-by: Ryan Manuel <[email protected]> Co-authored-by: DEBRIS APRON <[email protected]> * Updating changelog * Removing duplicate changelog entry * Update content/_changelogs/10.11.0.md Co-authored-by: Matt Henkes <[email protected]> * Adding "Experimental Breaking Changes" section * Moving one issue in changelog and running prettier * Moving a few items around in the changelog * Updating changelog copy for cy.session support in Webkit Co-authored-by: Emily Rohrbough <[email protected]> Co-authored-by: Matt Henkes <[email protected]> Co-authored-by: Bill Glesias <[email protected]> Co-authored-by: Ryan Manuel <[email protected]> Co-authored-by: DEBRIS APRON <[email protected]> Co-authored-by: Stokes Player <[email protected]>
1 parent a5b4736 commit ca6edab

File tree

10 files changed

+315
-201
lines changed

10 files changed

+315
-201
lines changed

content/_changelogs/10.11.0.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
## 10.11.0
2+
3+
_Released 10/25/2022_
4+
5+
**Features:**
6+
7+
- [`cy.session()`](/api/commands/session) is now supported when using
8+
[WebKit (Experimental)](https://docs.cypress.io/guides/guides/launching-browsers#WebKit-Experimental)
9+
and `experimentalSessionAndOrigin` is enabled. Addresses
10+
[#24116](https://github.com/cypress-io/cypress/issues/24116),
11+
[#23832](https://github.com/cypress-io/cypress/issues/23832).
12+
- Improves user experience when connecting a project to the Dashboard. Addresses
13+
[#23379](https://github.com/cypress-io/cypress/issues/23379),
14+
[#23766](https://github.com/cypress-io/cypress/issues/23766),
15+
[#23767](https://github.com/cypress-io/cypress/issues/23767).
16+
- Users will be prompted to connect a project to the Dashboard when logging in
17+
from the Cypress Launchpad after a testing type has been selected.
18+
- Users will be prompted to record runs to the Dashboard from both the Cypress
19+
App and Cypress Launchpad if a project is connected to the Dashboard and has
20+
no recorded runs.
21+
22+
**Bugfixes:**
23+
24+
- When a chromium based browser tab or process crashes, Cypress will no longer
25+
hang indefinitely but will fail the current test and move on to the next.
26+
[#6170](https://github.com/cypress-io/cypress/issues/6170).
27+
- Fixed as issue where browser-skipped tests were incorrectly recorded to the
28+
Dashboard which resulted in the Dashboard marking the test as "new" or
29+
"modified" when it already existed. Fixes
30+
[#23517](https://github.com/cypress-io/cypress/issues/23517).
31+
- Fixed issue connecting to the cloud when a self-signed cert was in the cert
32+
chain. Fixes [#24298](https://github.com/cypress-io/cypress/issues/24298).
33+
- [`cy.origin()`](/api/commands/origin) now supports more than 30 unique origin
34+
spec bridges per test. Fixes
35+
[#22874](https://github.com/cypress-io/cypress/issues/22874),
36+
[#23967](https://github.com/cypress-io/cypress/issues/23967).
37+
- Fixed an issue where `document.cookie` would not reflect the correct value in
38+
cross-origin tests. Fixes
39+
[#23531](https://github.com/cypress-io/cypress/issues/23531).
40+
- Cypress will now restart on changes to the `blockHosts` configuration entry.
41+
Fixes [#22634](https://github.com/cypress-io/cypress/issues/22634).
42+
- When shown the command to record runs to the cloud, the user can select and
43+
copy parts of the command (like the record key), instead of only being able to
44+
use the "Copy" button to copy the entire command. Fixes
45+
[#22091](https://github.com/cypress-io/cypress/issues/22091).
46+
- Cleaned up inconsistencies in the UI between sentence case and title case.
47+
Fixes [#21854](https://github.com/cypress-io/cypress/issues/21854).
48+
- Fixed an issue where there is a visible "Project ID" section (with no
49+
`projectId`) when user has not connected to the Dashboard.
50+
[#21806](https://github.com/cypress-io/cypress/issues/21806).
51+
52+
**Experimental Breaking Changes:**
53+
54+
- [`cy.origin()`](/api/commands/origin) now supports using `require()` and
55+
dynamic `import()` to include dependencies. `Cypress.require()` has been
56+
removed. Addresses
57+
[#24293](https://github.com/cypress-io/cypress/issues/24293).
58+
- The way that Cypress handles
59+
[test isolation](/guides/core-concepts/writing-and-organizing-tests#Test-Isolation)
60+
has changed. The previous modes of `legacy` and `strict` have been replaced
61+
with `on` and `off`. Fixes
62+
[#24206](https://github.com/cypress-io/cypress/issues/24206).
63+
- The default mode is `on` when
64+
[`experimentalSessionAndOrigin`](/guides/references/experiments) is enabled.
65+
- The [cy.session()](/api/commands/session) command now inherits the test
66+
isolation behavior for the suite it runs in.

content/_data/sidebar.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -985,10 +985,6 @@
985985
"title": "platform",
986986
"slug": "platform"
987987
},
988-
{
989-
"title": "require",
990-
"slug": "require"
991-
},
992988
{
993989
"title": "session",
994990
"slug": "session"

content/api/commands/origin.md

Lines changed: 64 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,28 @@ limitation determined by standard web security features of the browser. The
1616
<strong class="alert-header"><Icon name="exclamation-triangle"></Icon>
1717
Experimental</strong>
1818

19-
The `cy.origin()` command is currently experimental and can be enabled by
20-
setting
21-
the [`experimentalSessionAndOrigin`](/guides/references/experiments) flag
22-
to `true` in the Cypress config.
19+
The `session` API is currently experimental, and can be enabled by setting the
20+
[`experimentalSessionAndOrigin`](/guides/references/experiments) option to
21+
`true` in the Cypress config.
2322

2423
Enabling this flag does the following:
2524

26-
- It adds the [`cy.session()`](/api/commands/session) and `cy.origin()`
27-
commands, and [`Cypress.session`](/api/cypress-api/session) API.
28-
- It adds the following new behaviors (that will be the default in a future
29-
major version release of Cypress) at the beginning of each test:
30-
- The page is cleared (by setting it to `about:blank`).
31-
- All active session data (cookies, `localStorage` and `sessionStorage`)
32-
across all domains are cleared.
33-
- It supersedes
34-
the [`Cypress.Cookies.preserveOnce()`](/api/cypress-api/cookies#Preserve-Once) and
35-
[`Cypress.Cookies.defaults()`](/api/cypress-api/cookies#Defaults) methods.
25+
- It adds the `cy.session()` and [`cy.origin()`](/api/commands/origin) commands,
26+
and [`Cypress.session`](/api/cypress-api/session) API.
27+
- It adds the concept of
28+
[`testIsolation`](/guides/core-concepts/writing-and-organizing-tests#Test-Isolation)
29+
which defaults to `on`, such that:
30+
- The page is cleared (by setting it to `about:blank`).
31+
- Cookies, local storage and session storage in all domains are cleared.
32+
- It supersedes the
33+
[`Cypress.Cookies.preserveOnce()`](/api/cypress-api/cookies#Preserve-Once) and
34+
[`Cypress.Cookies.defaults()`](/api/cypress-api/cookies#Defaults) methods.
3635
- Cross-origin requests will now succeed, however, to interact with a
3736
cross-origin page you must use a `cy.origin` block.
3837

39-
Because the page is cleared before each
40-
test, [`cy.visit()`](/api/commands/visit) must be explicitly called in each test
41-
to visit a page in your application.
38+
Because the page is cleared at the beginning of each test by default,
39+
[`cy.visit()`](/api/commands/visit) must be explicitly called at the beginning
40+
of each test.
4241

4342
</Alert>
4443

@@ -390,12 +389,12 @@ and reuse it across tests.
390389

391390
Enabling the `experimentalSessionAndOrigin` flag makes the test-runner work
392391
slightly differently, and some test suites that rely on the existing behaviour
393-
may have to be updated. The most important of these changes is **test
394-
isolation**. This means that after every test, the current page is reset to
395-
`about:blank` and all active session data
396-
(cookies, `localStorage` and `sessionStorage`) across all domains are cleared.
397-
This change is opt-in for now, but will be standardized in a future major
398-
release of Cypress, so eventually all tests will need to be isolated.
392+
may have to be updated. The most important of these changes is
393+
[**test isolation**]() which defaults to `on`. This means that after every test,
394+
the current page is reset to `about:blank` and cookies, local storage and
395+
session storage in all domains are cleared before each test. This change is
396+
opt-in for now, but will be standardized in a future major release of Cypress,
397+
so eventually all tests will need to be isolated.
399398

400399
Before this change, it was possible to write tests such that you could, for
401400
example, log in to a CMS in the first test, change some content in the second
@@ -507,27 +506,53 @@ into the callback.
507506

508507
### Dependencies / Sharing Code
509508

510-
It is not possible to use
509+
[ES module dynamic `import()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#dynamic_imports)
510+
and/or
511511
[CommonJS `require()`](https://nodejs.org/en/knowledge/getting-started/what-is-require/)
512-
or
513-
[dynamic ES module `import()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#dynamic_imports)
514-
within the callback. However, [`Cypress.require()`](/api/cypress-api/require)
515-
can be utilized to include [npm](https://www.npmjs.com/) packages and other
516-
files. It is functionally the same as using
517-
[CommonJS `require()`](https://nodejs.org/en/knowledge/getting-started/what-is-require/)
518-
in browser-targeted code.
512+
can be used within the callback to include [npm](https://www.npmjs.com/)
513+
packages and other files.
514+
515+
<Alert type="warning">
516+
517+
Using `import()` and `require()` within the callback requires version 5.15.0 or
518+
greater of the
519+
[`@cypress/webpack-preprocessor`](https://github.com/cypress-io/cypress/tree/master/npm/webpack-preprocessor).
520+
This is included in Cypress by default, but if your project installs its own
521+
version of `@cypress/webpack-preprocessor` that is set up in your Cypress
522+
config, make sure it is version 5.15.0 or greater.
523+
524+
If using an older version of the webpack or a different preprocessor, you'll see
525+
an error that includes the following text:
526+
527+
_Using require() or import() to include dependencies requires using the latest
528+
version of @cypress/webpack-preprocessor._
529+
530+
</Alert>
531+
532+
#### Example
519533

520534
```js
535+
// ES modules
536+
cy.origin('somesite.com', async () => {
537+
const _ = await import('lodash')
538+
const utils = await import('../support/utils')
539+
540+
// ... use lodash and utils ...
541+
})
542+
543+
// CommonJS
521544
cy.origin('somesite.com', () => {
522-
const _ = Cypress.require('lodash')
523-
const utils = Cypress.require('../support/utils')
545+
const _ = require('lodash')
546+
const utils = require('../support/utils')
524547

525548
// ... use lodash and utils ...
526549
})
527550
```
528551

529-
`Cypress.require()` can be used to share custom commands between tests run in
530-
primary and secondary origins. We recommend this pattern for setting up your
552+
#### Custom commands
553+
554+
This makes it possible to share custom commands between tests run in primary and
555+
secondary origins. We recommend this pattern for setting up your
531556
[support file](/guides/core-concepts/writing-and-organizing-tests#Support-file)
532557
and setting up custom commands to run within the `cy.origin()` callback:
533558

@@ -561,7 +586,7 @@ before(() => {
561586
// calls in this spec. put it in your support file to make them available to
562587
// all specs
563588
cy.origin('somesite.com', () => {
564-
Cypress.require('../support/commands')
589+
require('../support/commands')
565590
})
566591
})
567592

@@ -573,6 +598,8 @@ it('tests somesite.com', () => {
573598
})
574599
```
575600

601+
#### Shared execution context
602+
576603
The JavaScript execution context is persisted between `cy.origin()` callbacks
577604
that share the same origin. This can be utilized to share code between
578605
successive `cy.origin()` calls.
@@ -582,7 +609,7 @@ before(() => {
582609
cy.origin('somesite.com', () => {
583610
// makes commands defined in this file available to all callbacks
584611
// for somesite.com
585-
Cypress.require('../support/commands')
612+
require('../support/commands')
586613
})
587614
})
588615

content/api/commands/session.md

Lines changed: 63 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ Cache and restore [cookies](/api/cypress-api/cookies),
77
[`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage),
88
and
99
[`sessionStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage)
10-
in order to reduce test setup times.
10+
(i.e. session data) in order to recreate a consistent browser context between
11+
tests.
12+
13+
The `cy.session()` command will inherit the
14+
[`testIsolation`](/guides/core-concepts/writing-and-organizing-tests#Test-Isolation)
15+
mode value to determine whether or not the page is cleared when caching and
16+
restoring the browser context.
1117

1218
<Alert type="warning">
1319

@@ -22,20 +28,18 @@ Enabling this flag does the following:
2228

2329
- It adds the `cy.session()` and [`cy.origin()`](/api/commands/origin) commands,
2430
and [`Cypress.session`](/api/cypress-api/session) API.
25-
- It adds the following new behaviors (that will be the default in a future
26-
major update of Cypress) at the beginning of each test:
27-
- The page is cleared (by setting it to `about:blank`). Disable this by
28-
setting
29-
[`testIsolation=legacy`](/guides/core-concepts/writing-and-organizing-tests#Test-Isolation).
30-
- All active session data (cookies, `localStorage` and `sessionStorage`)
31-
across all domains are cleared.
32-
- It supersedes
33-
the [`Cypress.Cookies.preserveOnce()`](/api/cypress-api/cookies#Preserve-Once) and
34-
[`Cypress.Cookies.defaults()`](/api/cypress-api/cookies#Defaults) methods.
31+
- It adds the concept of
32+
[`testIsolation`](/guides/core-concepts/writing-and-organizing-tests#Test-Isolation)
33+
which defaults to `on`, such that:
34+
- The page is cleared (by setting it to `about:blank`).
35+
- Cookies, local storage and session storage in all domains are cleared.
36+
- It supersedes the
37+
[`Cypress.Cookies.preserveOnce()`](/api/cypress-api/cookies#Preserve-Once) and
38+
[`Cypress.Cookies.defaults()`](/api/cypress-api/cookies#Defaults) methods.
3539
- Cross-origin requests will now succeed, however, to interact with a
3640
cross-origin page you must use a `cy.origin` block.
3741

38-
Because the page is cleared at the beginning of each test,
42+
Because the page is cleared at the beginning of each test by default,
3943
[`cy.visit()`](/api/commands/visit) must be explicitly called at the beginning
4044
of each test.
4145

@@ -128,8 +132,11 @@ runs, Cypress will preserve all cookies, `sessionStorage`, and `localStorage`,
128132
so that subsequent calls to `cy.session()` with the same `id` will bypass
129133
`setup` and just restore the cached session data.
130134

131-
The page and all active session data (cookies, `localStorage` and
132-
`sessionStorage`) across all domains are always cleared before `setup` runs.
135+
The page is cleared before `setup` when `testIsolation='on'` and is not cleared
136+
when `testIsolation='off'`.
137+
138+
Cookies, local storage and session storage in all domains are always cleared
139+
before `setup` runs, regardless of the testIsolation configuration.
133140

134141
**<Icon name="angle-right"></Icon> options** **_(Object)_**
135142

@@ -331,10 +338,10 @@ describe('account details', () => {
331338

332339
### Switching sessions inside tests
333340

334-
Because `cy.session()` clears the page and all active session data before
335-
running `setup`, you can use it to easily switch between sessions without first
336-
needing to log the previous user out. This allows tests to more accurately
337-
represent real-world scenarios and helps keep test run times short.
341+
Because `cy.session()` clears the page and all session data before running
342+
`setup`, you can use it to easily switch between sessions without first needing
343+
to log the previous user out. This allows tests to more accurately represent
344+
real-world scenarios and helps keep test run times short.
338345

339346
```jsx
340347
const login = (name) => {
@@ -669,24 +676,46 @@ it('t3', () => {
669676

670677
## Notes
671678

672-
### When the page and active session data are cleared
679+
### When the page and session data are cleared
680+
681+
### Test Isolation `on`
682+
683+
The page is cleared and cookies, local storage and session storage (session
684+
data) in all domains are cleared automatically when `cy.session()` runs and
685+
`testIsolation` is `on`. This guarantees consistent behavior whether a session
686+
is being created or restored and allows you to switch sessions without first
687+
having to explicitly log out.
688+
689+
| | Page cleared (test) | Session data cleared |
690+
| -------------------------- | :---------------------------------------------: | :---------------------------------------------: |
691+
| Before `setup` | <Icon name="check-circle" color="green"></Icon> | <Icon name="check-circle" color="green"></Icon> |
692+
| Before `validate` | <Icon name="check-circle" color="green"></Icon> | |
693+
| Before `cy.session()` ends | <Icon name="check-circle" color="green"></Icon> | |
694+
695+
[`cy.visit()`](/api/commands/visit) must be explicitly called afterwards to
696+
ensure the page to test is loaded.
697+
698+
### Test Isolation `off`
699+
700+
When `testIsolation` is `off`, the page will not clear, however, the session
701+
data will clear when `cy.session()` runs.
702+
703+
| | Page cleared (test) | Session data cleared |
704+
| -------------------------- | :-----------------: | :---------------------------------------------: |
705+
| Before `setup` | | <Icon name="check-circle" color="green"></Icon> |
706+
| Before `validate` | | |
707+
| Before `cy.session()` ends | | |
673708

674-
The page is cleared and all active session data (cookies, `localStorage`, and
675-
`sessionStorage`) across all domains are cleared automatically when
676-
`cy.session()` runs. This guarantees consistent behavior whether a session is
677-
being created or restored and allows you to switch sessions without first having
678-
to explicitly log out.
709+
[`cy.visit()`](/api/commands/visit) does not need to be called afterwards to
710+
ensure the page to test is loaded.
679711

680-
| | Current page cleared | Active session data cleared |
681-
| -------------------- | :---------------------------------------------: | :---------------------------------------------: |
682-
| Before `setup` | <Icon name="check-circle" color="green"></Icon> | <Icon name="check-circle" color="green"></Icon> |
683-
| Before `validate` | <Icon name="check-circle" color="green"></Icon> | |
684-
| After `cy.session()` | <Icon name="check-circle" color="green"></Icon> | |
712+
NOTE: Turning test isolation off may improve performance of end-to-end tests,
713+
however, previous tests could impact the browser state of the next test and
714+
cause inconsistency when using .only(). Be mindful to write isolated tests when
715+
test isolation is off.
685716

686-
Calling `cy.session()` clears the current page in addition to restoring the
687-
cached session data. [`cy.visit()`](/api/commands/visit) must be explicitly
688-
called afterwards to ensure a page is visited if you did not provide a
689-
`validate` function that called `cy.visit()`.
717+
When test isolation is `off`, it is encouraged to setup your session in a before
718+
hook or in the first test to ensure a clean setup.
690719

691720
### Session caching
692721

@@ -880,7 +909,7 @@ that were run when creating and/or validating the session.
880909
In this image, a saved session is restored, but when `/personal` is visited in
881910
the `validate` function, the app redirects to `/signin`, which invalidates the
882911
session. A new session is created by visiting `/signin` where the user is logged
883-
in, after which, validation succeeds, and the session is made active for the
912+
in, after which, validation succeeds, and the session is available for the
884913
remainder of the test.
885914

886915
<DocsImage src="/img/api/session/session-expanded.png" alt="Recreated session (expanded)"></DocsImage>

0 commit comments

Comments
 (0)