Skip to content

Commit e4cbda6

Browse files
authored
Merge branch 'v11' into content/remove-obsolete-for-multidomain-ga
2 parents da3a511 + 8a0185f commit e4cbda6

File tree

12 files changed

+138
-350
lines changed

12 files changed

+138
-350
lines changed

content/_changelogs/11.0.0.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## 11.0.0
2+
3+
_Released MM/DD/YYYY_
4+
5+
**Breaking Changes:**
6+
7+
- `experimentalSessionAndOrigin` flag has been removed and all functionality is
8+
on by default now.
9+
- `testIsolation` defaults to `strict` now.
10+
- `Cookies.defaults` and `Cookies.preserveOnce` have been removed. Please update
11+
to use [`cy.session()`](/api/commands/session) to preserve session details
12+
between tests. Addresses
13+
[#21472](https://github.com/cypress-io/cypress/issues/21472).

content/api/commands/origin.md

100755100644
Lines changed: 2 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,6 @@ limitation determined by standard web security features of the browser. The
1313

1414
<Alert type="warning">
1515

16-
<strong class="alert-header"><Icon name="exclamation-triangle"></Icon>
17-
Experimental</strong>
18-
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.
23-
24-
Enabling this flag does the following:
25-
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.
36-
- Cross-origin requests will now succeed, however, to interact with a
37-
cross-origin page you must use a `cy.origin` block.
38-
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.
42-
43-
</Alert>
44-
45-
<Alert type="warning">
46-
4716
<strong class="alert-header"><Icon name="exclamation-triangle"></Icon>
4817
Obstructive Third Party Code</strong>
4918

@@ -341,9 +310,8 @@ performant. Up until now you could get around this problem by putting login code
341310
in the first test of your file, then performing subsequent tests reusing the
342311
same session.
343312

344-
However, once the `experimentalSessionAndOrigin` flag is activated, this is no
345-
longer possible, since all session state is now cleared between tests. So to
346-
avoid this overhead we recommend you leverage the
313+
However, this is no longer possible, since all session state is now cleared
314+
between tests. So to avoid this overhead we recommend you leverage the
347315
[`cy.session()`](/api/commands/session) command, which allows you to easily
348316
cache session information and reuse it across tests. So now let's enhance our
349317
custom login command with `cy.session()` for a complete syndicated login flow
@@ -386,81 +354,6 @@ and reuse it across tests.
386354

387355
## Notes
388356

389-
### Migrating existing tests
390-
391-
Enabling the `experimentalSessionAndOrigin` flag makes the test-runner work
392-
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.
399-
400-
Before this change, it was possible to write tests such that you could, for
401-
example, log in to a CMS in the first test, change some content in the second
402-
test, verify the new version is displayed on a different URL in the third, and
403-
log out in the fourth. Here's a simplified example of such a test strategy.
404-
405-
<Badge type="danger">Before</Badge> Multiple small tests against different
406-
origins
407-
408-
```js
409-
it('logs in', () => {
410-
cy.visit('https://supersecurelogons.com')
411-
cy.get('input#password').type('Password123!')
412-
cy.get('button#submit').click()
413-
})
414-
415-
it('updates the content', () => {
416-
cy.get('#current-user').contains('logged in')
417-
cy.get('button#edit-1').click()
418-
cy.get('input#title').type('Updated title')
419-
cy.get('button#submit').click()
420-
cy.get('.toast').type('Changes saved!')
421-
})
422-
423-
it('validates the change', () => {
424-
cy.visit('/items/1')
425-
cy.get('h1').contains('Updated title')
426-
})
427-
```
428-
429-
After switching on `experimentalSessionAndOrigin`, this flow would need to be
430-
contained within a single test. While this practice has always been
431-
[discouraged](/guides/references/best-practices#Having-tests-rely-on-the-state-of-previous-tests)
432-
we know some users have historically written tests this way, often to get around
433-
the same-origin restrictions. But with `cy.origin()` you no longer need these
434-
kind of brittle hacks, as your multi-origin logic can all reside in a single
435-
test, like the following.
436-
437-
<Badge type="success">After</Badge> One big test using `cy.origin()`
438-
439-
```js
440-
it('securely edits content', () => {
441-
cy.origin('supersecurelogons.com', () => {
442-
cy.visit('https://supersecurelogons.com')
443-
cy.get('input#password').type('Password123!')
444-
cy.get('button#submit').click()
445-
})
446-
447-
cy.origin('mycms.com', () => {
448-
cy.url().should('contain', 'cms')
449-
cy.get('#current-user').contains('logged in')
450-
cy.get('button#edit-1').click()
451-
cy.get('input#title').type('Updated title')
452-
cy.get('button#submit').click()
453-
cy.get('.toast').type('Changes saved!')
454-
})
455-
456-
cy.visit('/items/1')
457-
cy.get('h1').contains('Updated title')
458-
})
459-
```
460-
461-
Always remember,
462-
[Cypress tests are not unit tests](https://docs.cypress.io/guides/references/best-practices#Creating-tiny-tests-with-a-single-assertion).
463-
464357
### Serialization
465358

466359
When entering a `cy.origin()` block, Cypress injects itself at runtime, with all
@@ -615,7 +508,6 @@ following Cypress commands will throw errors if used in the callback:
615508
- `cy.origin()`
616509
- [`cy.intercept()`](/api/commands/intercept)
617510
- [`cy.session()`](/api/commands/session)
618-
- [`Cypress.Cookies.preserveOnce()`](/api/cypress-api/cookies)
619511

620512
### Other limitations
621513

content/api/commands/session.md

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,6 @@ and
99
[`sessionStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage)
1010
in order to reduce test setup times.
1111

12-
<Alert type="warning">
13-
14-
<strong class="alert-header"><Icon name="exclamation-triangle"></Icon>
15-
Experimental</strong>
16-
17-
The `session` API is currently experimental, and can be enabled by setting the
18-
[`experimentalSessionAndOrigin`](/guides/references/experiments) option to
19-
`true` in the Cypress config.
20-
21-
Enabling this flag does the following:
22-
23-
- It adds the `cy.session()` and [`cy.origin()`](/api/commands/origin) commands,
24-
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 overrides the
33-
[`Cypress.Cookies.preserveOnce()`](/api/cypress-api/cookies#Preserve-Once) and
34-
[`Cypress.Cookies.defaults()`](/api/cypress-api/cookies#Defaults) methods.
35-
- Cross-origin navigation will no longer fail immediately, but instead, time out
36-
based on [`pageLoadTimeout`](/guides/references/configuration#Timeouts).
37-
- Tests will no longer wait on page loads before moving on to the next test.
38-
39-
Because the page is cleared at the beginning of each test,
40-
[`cy.visit()`](/api/commands/visit) must be explicitly called at the beginning
41-
of each test.
42-
43-
</Alert>
44-
4512
## Syntax
4613

4714
```javascript

content/api/commands/should.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,35 @@ Be sure _not_ to include any code that has side effects in your callback
172172
function. The callback function will be retried over and over again until no
173173
assertions within it throw.
174174

175+
You cannot invoke Cypress commands inside of a `.should()` callback function.
176+
Use Cypress commands before or after `.should()` instead.
177+
178+
**<Icon name="exclamation-triangle" color="red"></Icon> Incorrect Usage**
179+
180+
```javascript
181+
cy.get('p').should(($p) => {
182+
cy.log($p)
183+
// ...
184+
})
185+
```
186+
187+
**<Icon name="check-circle" color="green"></Icon> Correct Usage**
188+
189+
```javascript
190+
cy.get('p')
191+
.should(($p) => {
192+
// ...
193+
})
194+
.log()
195+
196+
// or
197+
198+
cy.get('p').then(($p) => {
199+
// ...
200+
cy.log($p)
201+
})
202+
```
203+
175204
#### Verify length, content, and classes from multiple `<p>`
176205

177206
```html
@@ -467,10 +496,11 @@ following:
467496

468497
## History
469498

470-
| Version | Changes |
471-
| --------------------------------------------- | --------------------------------- |
472-
| [0.11.4](/guides/references/changelog#0-11-4) | Allows callback function argument |
473-
| [< 0.3.3](/guides/references/changelog#0-3-3) | `.should()` command added |
499+
| Version | Changes |
500+
| --------------------------------------------- | ----------------------------------------------- |
501+
| [11.0.0](/guides/references/changelog#11-0-0) | Throw error if Cypress command used in callback |
502+
| [0.11.4](/guides/references/changelog#0-11-4) | Allows callback function argument |
503+
| [< 0.3.3](/guides/references/changelog#0-3-3) | `.should()` command added |
474504

475505
## See also
476506

content/api/commands/visit.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -415,23 +415,12 @@ pass.</li></List>
415415

416416
## Visiting cross-origin sites
417417

418-
<Alert type="warning">
419-
420-
<strong class="alert-header"><Icon name="exclamation-triangle"></Icon>
421-
Experimental</strong>
422-
423-
Visiting cross-origin sites will currently throw an error. It can be enabled by
424-
setting
425-
the [`experimentalSessionAndOrigin`](/guides/references/experiments) flag
426-
to `true` in the Cypress config. This will allow you to visit the cross-origin
427-
site without errors. However, to interact with the content on the cross-origin
428-
site, you must use a [`cy.origin()`](/api/commands/origin) block.
418+
After visiting a cross-origin site, to interact with the content, you must use a
419+
[`cy.origin()`](/api/commands/origin) block.
429420

430421
When visiting a cross-origin site, the `onBeforeLoad` and `onLoad` options are
431422
not supported.
432423

433-
</Alert>
434-
435424
## Command Log
436425

437426
**_Visit example application in a `beforeEach`_**
@@ -455,6 +444,7 @@ following:
455444

456445
| Version | Changes |
457446
| --------------------------------------------- | -------------------------------------------------------------------------------- |
447+
| [11.0.0](/guides/references/changelog#11-0-0) | Removed `experimentalSessionAndOrigin` reference |
458448
| [3.5.0](/guides/references/changelog#3-5-0) | Added support for options `qs` |
459449
| [3.3.0](/guides/references/changelog#3-3-0) | Added support for options `retryOnStatusCodeFailure` and `retryOnNetworkFailure` |
460450
| [3.2.0](/guides/references/changelog#3-2-0) | Added options `url`, `method`, `body`, and `headers` |

0 commit comments

Comments
 (0)