mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-20 15:20:23 -05:00
docs: cleanup of api content
This commit is contained in:
@@ -79,7 +79,7 @@ cy
|
||||
|
||||
## Timeout
|
||||
|
||||
`.and` will continue to retry the assertion to the duration of the previous cy commands `timeout` or the `defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts)
|
||||
`.and()` will continue to retry the assertion to the duration of the previous cy commands `timeout` or the `defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts).
|
||||
|
||||
```javascript
|
||||
cy.get('input', {timeout: 10000}).should('have.value', '10').and('have.class', 'error')
|
||||
@@ -204,14 +204,12 @@ Take this *explicit* assertion for example:
|
||||
expect({foo: 'bar'}).to.have.property('foo').and.eq('bar')
|
||||
```
|
||||
|
||||
`cy.and` reproduces this same assertion behavior.
|
||||
`.and()` reproduces this same assertion behavior.
|
||||
|
||||
**How do I know which assertions change the subject and which keep it the same?**
|
||||
|
||||
The chainers that come from [Chai](https://on.cypress.io/guides/bundled-tools#chai) or [Chai-jQuery](https://on.cypress.io/guides/bundled-tools#chai-jquery) will always document what they return.
|
||||
|
||||
Alternatively, it is very easy to use Cypress itself to figure this out.
|
||||
|
||||
You can [read more about debugging assertions](https://on.cypress.io/guides/making-assertions#debugging-assertions) here.
|
||||
|
||||
# Command Log
|
||||
|
||||
@@ -59,9 +59,9 @@ Option | Default | Notes
|
||||
`force404` | `false` | Forcibly send XHR's a 404 status when the XHR's do not match any existing [`cy.routes`](https://on.cypress.io/api/routes)
|
||||
`headers` | `null` | Response headers for stubbed routes
|
||||
`method` | `GET` | Method to match against requests
|
||||
`onAbort` | `null` | Callback function which fires anytime an XHR is aborted
|
||||
`onRequest` | `null` | Callback function when a request is sent
|
||||
`onResponse` | `null` | Callback function when a response is returned
|
||||
`onAbort` | `null` | Callback function which fires anytime an XHR is aborted
|
||||
`response` | `null` | Response body when stubbing routes
|
||||
`status` | `200` | Response status code when stubbing routes
|
||||
`url` | `null` | String or RegExp url to match against request urls
|
||||
|
||||
@@ -4,12 +4,13 @@ comments: true
|
||||
description: ''
|
||||
---
|
||||
|
||||
Start a server to begin routing responses to `.route()` and `.request()`.
|
||||
Start a server to begin routing responses to `cy.route()` and `cy.request()`.
|
||||
|
||||
{% note info New to Cypress? %}
|
||||
[Read about Network Requests first.](https://on.cypress.io/guides/network-requests-xhr)
|
||||
{% note info %}
|
||||
**Note:** `cy.server()` assumes you are already familiar with core concepts such as [network requests](https://on.cypress.io/guides/network-requests-xhr)
|
||||
{% endnote %}
|
||||
|
||||
|
||||
# Syntax
|
||||
|
||||
```javascript
|
||||
@@ -19,7 +20,7 @@ cy.server(options)
|
||||
|
||||
## Usage
|
||||
|
||||
`.server()` cannot be chained off any other cy commands, so should be chained off of `cy` for clarity.
|
||||
`cy.server()` cannot be chained off any other cy commands, so should be chained off of `cy` for clarity.
|
||||
|
||||
**{% fa fa-check-circle green %} Valid Usage**
|
||||
|
||||
@@ -31,23 +32,24 @@ cy.server()
|
||||
|
||||
**{% fa fa-angle-right %} options** ***(Object)***
|
||||
|
||||
Pass in an options object to change the default behavior of `.server()`. These options are used for 2 different purposes
|
||||
Pass in an options object to change the default behavior of `cy.server()`. These options are used for 2 different purposes:
|
||||
|
||||
1. As defaults that are merged into [`.route()`](https://on.cypress.io/api/route).
|
||||
2. As configuration behavior for *all* requests.
|
||||
- As defaults that are merged into [`cy.route()`](https://on.cypress.io/api/route).
|
||||
|
||||
- As configuration behavior for *all* requests.
|
||||
|
||||
***The following options are merged in as default options to [`.route()`](https://on.cypress.io/api/route)***
|
||||
|
||||
Option | Default | Notes
|
||||
--- | --- | ---
|
||||
`method` | `"GET"` | method to match against requests
|
||||
`response` | `null` | response body when stubbing routes
|
||||
`status` | `200` | response status code when stubbing routes
|
||||
`delay` | `0` | delay for stubbed responses (in ms)
|
||||
`headers` | `null` | response headers for stubbed routes
|
||||
`method` | `"GET"` | method to match against requests
|
||||
`onAbort` | `undefined` | callback function which fires anytime an XHR is aborted
|
||||
`onRequest` | `undefined` | callback function when a request is sent
|
||||
`onResponse` | `undefined` | callback function when a response is returned
|
||||
`onAbort` | `undefined` | callback function which fires anytime an XHR is aborted
|
||||
`response` | `null` | response body when stubbing routes
|
||||
`status` | `200` | response status code when stubbing routes
|
||||
|
||||
***The following options control the behavior of the server affecting all requests:***
|
||||
|
||||
@@ -60,7 +62,7 @@ Option | Default | Notes
|
||||
|
||||
## Yields
|
||||
|
||||
`.server()` yields the Cypress server instance.
|
||||
`cy.server()` yields the Cypress server instance.
|
||||
|
||||
## Timeout
|
||||
|
||||
@@ -71,7 +73,7 @@ Option | Default | Notes
|
||||
|
||||
**After starting a server:**
|
||||
|
||||
- Any request that does not match a [`.route()`](https://on.cypress.io/api/route) will be sent a `404` status code.
|
||||
- Any request that does not match a [`cy.route()`](https://on.cypress.io/api/route) will be sent a `404` status code.
|
||||
- Any request that matches the `options.whitelist` function will **NOT** be logged or stubbed. In other words it is "whitelisted" and ignored.
|
||||
- You will see requests named as `(XHR Stub)` or `(XHR)` in the Command Log.
|
||||
|
||||
@@ -81,11 +83,11 @@ cy.server()
|
||||
|
||||
## Options
|
||||
|
||||
## Change defaults for [`.route()`](https://on.cypress.io/api/route)
|
||||
**Change defaults for [`.route()`](https://on.cypress.io/api/route)**
|
||||
|
||||
By default [`cy.route`](https://on.cypress.io/api/route) inherits some of its options from `cy.server()`.
|
||||
By default [`cy.route()`](https://on.cypress.io/api/route) inherits some of its options from `cy.server()`.
|
||||
|
||||
In this example, our matching requests will be delayed 1000ms and have a status of 422, but its response will be what was set in [`.route()`](https://on.cypress.io/api/route).
|
||||
In this example, our matching requests will be delayed 1000ms and have a status of `422`, but its `response` will be what was set in [`cy.route()`](https://on.cypress.io/api/route).
|
||||
|
||||
```javascript
|
||||
cy.server({
|
||||
@@ -124,7 +126,6 @@ cy.route('/activities/**', 'fixture:activities.json')
|
||||
|
||||
```javascript
|
||||
// Application Code
|
||||
|
||||
$(function(){
|
||||
$.get('/activities')
|
||||
|
||||
@@ -136,10 +137,10 @@ $(function(){
|
||||
|
||||
**Change the default response headers for all routes**
|
||||
|
||||
When you stub requests, you can automatically control their response headers. This is useful when you want to send back meta data in the headers, such as *pagination* or *token* information.
|
||||
When you stub requests, you can automatically control their response `headers`. This is useful when you want to send back meta data in the `headers`, such as *pagination* or *token* information.
|
||||
|
||||
{% note info %}
|
||||
Cypress automatically sets `Content-Length` and `Content-Type` based on the response body you stub.
|
||||
Cypress automatically sets `Content-Length` and `Content-Type` based on the response `body` you stub.
|
||||
{% endnote %}
|
||||
|
||||
```javascript
|
||||
@@ -150,9 +151,8 @@ cy.server({
|
||||
})
|
||||
cy.route('GET', '/users/1', {id: 1, name: 'Amanda'}).as('getUser')
|
||||
cy.visit('/users/1/profile')
|
||||
cy.wait('@getUser')
|
||||
.its('responseHeaders')
|
||||
.should('have.property', 'x-token', 'abc-123-foo-bar') // true
|
||||
cy.wait('@getUser').its('responseHeaders')
|
||||
.should('have.property', 'x-token', 'abc-123-foo-bar') // true
|
||||
```
|
||||
|
||||
```javascript
|
||||
@@ -173,13 +173,13 @@ xhr.send()
|
||||
|
||||
**Change the default whitelisting**
|
||||
|
||||
`.server()` comes with a `whitelist` function that will filter out any requests that are for static assets like `.html`, `.js`, `.jsx`, and `.css`.
|
||||
`cy.server()` comes with a `whitelist` function that by default filters out any requests that are for static assets like `.html`, `.js`, `.jsx`, and `.css`.
|
||||
|
||||
Any request that passes the `whitelist` will be ignored - it will not be logged nor will it be stubbed in any way (even if it matches a specific [`.route()`](https://on.cypress.io/api/route)).
|
||||
Any request that passes the `whitelist` will be ignored - it will not be logged nor will it be stubbed in any way (even if it matches a specific [`cy.route()`](https://on.cypress.io/api/route)).
|
||||
|
||||
The idea is that we never want to interfere with static assets that are fetched via AJAX.
|
||||
|
||||
The default whitelist function in Cypress is:
|
||||
***The default whitelist function in Cypress is:***
|
||||
|
||||
```javascript
|
||||
var whitelist = function(xhr){
|
||||
@@ -189,7 +189,7 @@ var whitelist = function(xhr){
|
||||
}
|
||||
```
|
||||
|
||||
You can override this function with your own specific logic.
|
||||
***You can override this function with your own specific logic:***
|
||||
|
||||
```javascript
|
||||
cy.server({
|
||||
@@ -210,7 +210,6 @@ You can disable all stubbing and its effects and restore it to the default behav
|
||||
```javascript
|
||||
cy.server()
|
||||
cy.route('POST', '/users', {}).as('createUser')
|
||||
|
||||
cy.server({enable: false})
|
||||
```
|
||||
|
||||
@@ -226,16 +225,16 @@ However between tests, when a new test runs, the previous configuration is resto
|
||||
|
||||
When a new test runs, any outstanding requests still in flight are automatically aborted. In fact this happens by default whether or not you've even started a `cy.server()`.
|
||||
|
||||
**Server can be started before you [`cy.visit`](https://on.cypress.io/api/visit)**
|
||||
**Server can be started before you [`cy.visit()`](https://on.cypress.io/api/visit)**
|
||||
|
||||
Oftentimes your application may make initial requests immediately when it loads (such as authenticating a user). Cypress makes it possible to start your server and define routes before a [`cy.visit`](https://on.cypress.io/api/visit). Upon the next visit, the server + routes will be instantly applied before your application loads.
|
||||
Oftentimes your application may make initial requests immediately when it loads (such as authenticating a user). Cypress makes it possible to start your server and define routes before a [`cy.visit()`](https://on.cypress.io/api/visit). Upon the next visit, the server + routes will be instantly applied before your application loads.
|
||||
|
||||
You can [read more about XHR strategy here](https://on.cypress.io/guides/network-requests-xhr).
|
||||
|
||||
# See also
|
||||
|
||||
- [route](https://on.cypress.io/api/route)
|
||||
- [wait](https://on.cypress.io/api/wait)
|
||||
- [request](https://on.cypress.io/api/request)
|
||||
- [visit](https://on.cypress.io/api/visit)
|
||||
- [Network Requests](https://on.cypress.io/guides/network-requests-xhr)
|
||||
- [request](https://on.cypress.io/api/request)
|
||||
- [route](https://on.cypress.io/api/route)
|
||||
- [visit](https://on.cypress.io/api/visit)
|
||||
- [wait](https://on.cypress.io/api/wait)
|
||||
|
||||
@@ -20,7 +20,7 @@ cy.setCookie(name, value, options)
|
||||
**{% fa fa-check-circle green %} Valid Usage**
|
||||
|
||||
```javascript
|
||||
cy.setCookie('auth_key', '123key')
|
||||
cy.setCookie('auth_key', '123key') // Set the 'auth_key' cookie to '123key'
|
||||
```
|
||||
|
||||
## Arguments
|
||||
@@ -39,17 +39,17 @@ Pass in an options object to change the default behavior of `cy.setCookie()`.
|
||||
|
||||
Option | Default | Notes
|
||||
--- | --- | ---
|
||||
`path` | `/` | the cookie path
|
||||
`domain` | `window.location.hostname` | the domain the cookie is visible to
|
||||
`secure` | `false` | whether the cookie is a secure cookie
|
||||
`httpOnly` | `false` | whether the cookie is an HTTP only cookie
|
||||
`expiry` | 20 years into the future | when the cookie expires, specified in seconds since [Unix Epoch](https://en.wikipedia.org/wiki/Unix_time).
|
||||
`timeout` | [`responseTimeout`](https://on.cypress.io/guides/configuration#timeouts) | Total time to wait for the `cy.setCookie()` command to be processed
|
||||
`domain` | `window.location.hostname` | The domain the cookie is visible to
|
||||
`expiry` | 20 years into the future | When the cookie expires, specified in seconds since [Unix Epoch](https://en.wikipedia.org/wiki/Unix_time).
|
||||
`httpOnly` | `false` | Whether the cookie is an HTTP only cookie
|
||||
`log` | `true` | Whether to display command in Command Log
|
||||
`path` | `/` | The cookie path
|
||||
`secure` | `false` | Whether the cookie is a secure cookie
|
||||
`timeout` | [`responseTimeout`](https://on.cypress.io/guides/configuration#timeouts) | Total time to wait for the `cy.setCookie()` command to be processed
|
||||
|
||||
## Yields
|
||||
|
||||
`.setCookie()` yields a cookie object literal with the following properties:
|
||||
`cy.setCookie()` yields a cookie object literal with the following properties:
|
||||
|
||||
- `name`
|
||||
- `value`
|
||||
@@ -61,7 +61,7 @@ Option | Default | Notes
|
||||
|
||||
## Timeout
|
||||
|
||||
`.setCookie()` will wait up for the duration of [`responseTimeout`](https://on.cypress.io/guides/configuration#timeouts) for the automation server to process this command.
|
||||
`cy.setCookie()` will wait up for the duration of [`responseTimeout`](https://on.cypress.io/guides/configuration#timeouts) for the automation server to process this command.
|
||||
|
||||
# Examples
|
||||
|
||||
@@ -70,10 +70,9 @@ Option | Default | Notes
|
||||
**Set a cookie**
|
||||
|
||||
```javascript
|
||||
cy
|
||||
.getCookies().should('be.empty')
|
||||
.setCookie('session_id', '189jd09sufh33aaiidhf99d09')
|
||||
.getCookie('session_id').should('have.property', 'value', '189jd09sufh33aaiidhf99d09')
|
||||
cy.getCookies().should('be.empty')
|
||||
cy.setCookie('session_id', '189jd09sufh33aaiidhf99d09')
|
||||
cy.getCookie('session_id').should('have.property', 'value', '189jd09sufh33aaiidhf99d09')
|
||||
```
|
||||
|
||||
# Command Log
|
||||
@@ -81,10 +80,9 @@ cy
|
||||
**Set a cookie**
|
||||
|
||||
```javascript
|
||||
cy
|
||||
.getCookies().should('be.empty')
|
||||
.setCookie('fakeCookie1', '123ABC')
|
||||
.getCookie('fakeCookie1').should('have.property', 'value', '123ABC')
|
||||
cy.getCookies().should('be.empty')
|
||||
cy.setCookie('fakeCookie1', '123ABC')
|
||||
cy.getCookie('fakeCookie1').should('have.property', 'value', '123ABC')
|
||||
```
|
||||
|
||||
The commands above will display in the command log as:
|
||||
@@ -99,6 +97,6 @@ When clicking on `setCookie` within the command log, the console outputs the fol
|
||||
|
||||
- [clearCookie](https://on.cypress.io/api/clearcookie)
|
||||
- [clearCookies](https://on.cypress.io/api/clearcookies)
|
||||
- [Cypress Cookies API](https://on.cypress.io/api/cookies)
|
||||
- [getCookie](https://on.cypress.io/api/getcookie)
|
||||
- [getCookies](https://on.cypress.io/api/getcookies)
|
||||
- [Cypress Cookies API](https://on.cypress.io/api/cookies)
|
||||
|
||||
@@ -10,8 +10,8 @@ Make an assertion.
|
||||
An alias of [`.and()`](https://on.cypress.io/api/and)
|
||||
{% endnote %}
|
||||
|
||||
{% note info New to Cypress? %}
|
||||
[Read about making assertions first.](https://on.cypress.io/guides/making-assertions)
|
||||
{% note info %}
|
||||
**Note:** `.should()` assumes you are already familiar with core concepts such as [assertions](https://on.cypress.io/guides/making-assertions)
|
||||
{% endnote %}
|
||||
|
||||
# Syntax
|
||||
@@ -60,7 +60,6 @@ A method to be called on the chainer.
|
||||
|
||||
Pass a function that can have any number of explicit assertions within it. Whatever was passed to the function is what is yielded.
|
||||
|
||||
|
||||
## Yields
|
||||
|
||||
In most cases, `.should()` yields the previous cy command's yield.
|
||||
@@ -81,7 +80,7 @@ cy
|
||||
|
||||
## Timeout
|
||||
|
||||
`.should` will continue to retry the assertion to the duration of the previous cy commands `timeout` or the `defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts)
|
||||
`.should()` will continue to retry the assertion to the duration of the previous cy commands `timeout` or the `defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts).
|
||||
|
||||
```javascript
|
||||
cy.get('input', {timeout: 10000}).should('have.value', '10')
|
||||
@@ -145,9 +144,7 @@ cy.get('#header a').should('have.attr', 'href', '/users')
|
||||
|
||||
Passing a function to `.should()` enables you to assert on the yielded subject. This gives you the opportunity to *massage* what you'd like to assert on.
|
||||
|
||||
Just be sure *not* to include any code that has side effects in your callback function.
|
||||
|
||||
The callback function will be retried over and over again until no assertions within it throw.
|
||||
Just be sure *not* to include any code that has side effects in your callback function. The callback function will be retried over and over again until no assertions within it throw.
|
||||
|
||||
```html
|
||||
<div>
|
||||
@@ -184,6 +181,8 @@ cy
|
||||
|
||||
**Assert explicitly within `.should()`**
|
||||
|
||||
Any errors raised by failed assertions will immediately bubble up and cause the test to fail.
|
||||
|
||||
```html
|
||||
<div id="todos">
|
||||
<li>Walk the dog</li>
|
||||
@@ -201,9 +200,6 @@ cy.get("#todos li").should(function($lis){
|
||||
})
|
||||
```
|
||||
|
||||
{% note warning %}
|
||||
Any errors raised by failed assertions will immediately bubble up and cause the test to fail.
|
||||
{% endnote %}
|
||||
|
||||
**Using a callback function will not change the subject**
|
||||
|
||||
@@ -234,7 +230,6 @@ In this example we use [`.and()`](https://on.cypress.io/api/and) which is identi
|
||||
cy.get('option:first').should('be.selected').and('have.value', 'Metallica')
|
||||
```
|
||||
|
||||
|
||||
## Wait until the assertions pass
|
||||
|
||||
Cypress won't resolve your commands until all of its assertions pass.
|
||||
@@ -251,11 +246,9 @@ $('button').click(function(){
|
||||
```
|
||||
|
||||
```javascript
|
||||
cy
|
||||
.get('button')
|
||||
.click()
|
||||
.should('have.class', 'active')
|
||||
.and('not.have.class', 'inactive')
|
||||
cy.get('button').click()
|
||||
.should('have.class', 'active')
|
||||
.and('not.have.class', 'inactive')
|
||||
```
|
||||
|
||||
You can [read more about how Cypress resolves your assertions](https://on.cypress.io/guides/making-assertions#resolving-assertions) here.
|
||||
@@ -266,8 +259,6 @@ You can [read more about how Cypress resolves your assertions](https://on.cypres
|
||||
|
||||
The chainers that come from [Chai](https://on.cypress.io/guides/bundled-tools#chai) or [Chai-jQuery](https://on.cypress.io/guides/bundled-tools#chai-jquery) will always document what they return.
|
||||
|
||||
Alternatively, it is very easy to use Cypress itself to figure this out.
|
||||
|
||||
You can [read more about debugging assertions](https://on.cypress.io/guides/making-assertions#debugging-assertions) here.
|
||||
|
||||
# Command Log
|
||||
@@ -275,11 +266,7 @@ You can [read more about debugging assertions](https://on.cypress.io/guides/maki
|
||||
**Assert that there should be 8 children in a nav**
|
||||
|
||||
```javascript
|
||||
//
|
||||
cy
|
||||
.get('.left-nav>.nav')
|
||||
.children()
|
||||
.should('have.length', 8)
|
||||
cy.get('.left-nav>.nav').children().should('have.length', 8)
|
||||
```
|
||||
|
||||
The commands above will display in the command log as:
|
||||
|
||||
@@ -54,9 +54,7 @@ Option | Default | Notes
|
||||
|
||||
## Timeout
|
||||
|
||||
`.siblings()` will continue to look for the sibling element(s) for the duration of the [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts)
|
||||
|
||||
|
||||
`.siblings()` will continue to look for the sibling element(s) for the duration of the [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts).
|
||||
|
||||
# Examples
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ description: ''
|
||||
Expand an array into multiple arguments.
|
||||
|
||||
{% note info %}
|
||||
Similar of [`.then()`](https://on.cypress.io/api/then), but always expects an array as it's subject.
|
||||
Similar to [`.then()`](https://on.cypress.io/api/then), but always expects an array as it's subject.
|
||||
{% endnote %}
|
||||
|
||||
# Syntax
|
||||
@@ -23,7 +23,7 @@ Similar of [`.then()`](https://on.cypress.io/api/then), but always expects an ar
|
||||
**{% fa fa-check-circle green %} Valid Usage**
|
||||
|
||||
```javascript
|
||||
cy.getCookies.spread(function() {}) // Yield all el's with class '.users'
|
||||
cy.getCookies.spread(function() {}) // Yield all cookies
|
||||
```
|
||||
|
||||
**{% fa fa-exclamation-triangle red %} Invalid Usage**
|
||||
@@ -52,12 +52,11 @@ Whatever was passed to the function is what is yielded.
|
||||
**Expand the array of aliased routes**
|
||||
|
||||
```javascript
|
||||
cy
|
||||
.server()
|
||||
.route('/users/').as('getUsers')
|
||||
.route('/activities/').as('getActivities')
|
||||
.route('/comments/').as('getComments')
|
||||
.wait(['@getUsers', '@getActivities', '@getComments'])
|
||||
cy.server()
|
||||
cy.route('/users/').as('getUsers')
|
||||
cy.route('/activities/').as('getActivities')
|
||||
cy.route('/comments/').as('getComments')
|
||||
cy.wait(['@getUsers', '@getActivities', '@getComments'])
|
||||
.spread(function(getUsers, getActivities, getComments){
|
||||
// each XHR is now an individual argument
|
||||
})
|
||||
@@ -79,5 +78,6 @@ cy.getCookies().spread(function(cookie1, cookie2, cookie3){
|
||||
|
||||
# See also
|
||||
|
||||
- [getCookies](https://on.cypress.io/api/getCookies)
|
||||
- [then](https://on.cypress.io/api/then)
|
||||
- [wait](https://on.cypress.io/api/wait)
|
||||
|
||||
@@ -14,7 +14,7 @@ cy.spy(object, method)
|
||||
|
||||
## Usage
|
||||
|
||||
`.spy()` cannot be chained off any other cy commands, so should be chained off of `cy` for clarity.
|
||||
`cy.spy()` cannot be chained off any other cy commands, so should be chained off of `cy` for clarity.
|
||||
|
||||
**{% fa fa-check-circle green %} Valid Usage**
|
||||
|
||||
@@ -26,7 +26,7 @@ cy.spy(user, 'addFriend')
|
||||
|
||||
**{% fa fa-angle-right %} object** ***(Object)***
|
||||
|
||||
The object that has the `method` to be wrapped.
|
||||
The `object` that has the `method` to be wrapped.
|
||||
|
||||
**{% fa fa-angle-right %} method** ***(String)***
|
||||
|
||||
@@ -34,9 +34,9 @@ The name of the `method` on the `object` to be wrapped.
|
||||
|
||||
## Yields
|
||||
|
||||
Unlike most Cypress commands, `cy.spy` is *synchronous* and returns a value (the spy) instead of a Promise-like chain-able object.
|
||||
Unlike most Cypress commands, `cy.spy()` is *synchronous* and returns a value (the spy) instead of a Promise-like chain-able object.
|
||||
|
||||
`cy.spy` returns a [Sinon.js spy](http://sinonjs.org/docs/#spies). All [methods](http://sinonjs.org/docs/#spies-api) found on Sinon.JS spies are supported.
|
||||
`cy.spy()` returns a [Sinon.js spy](http://sinonjs.org/docs/#spies). All [methods](http://sinonjs.org/docs/#spies-api) found on Sinon.JS spies are supported.
|
||||
|
||||
## Timeout
|
||||
|
||||
@@ -82,11 +82,11 @@ You will see the following in the command log:
|
||||
|
||||
**Automatic reset/restore between tests**
|
||||
|
||||
`cy.spy` creates spies in a [sandbox](http://sinonjs.org/docs/#sandbox), so all spies created are automatically reset/restored between tests without you having to explicitly reset/restore them.
|
||||
`cy.spy()` creates spies in a [sandbox](http://sinonjs.org/docs/#sandbox), so all spies created are automatically reset/restored between tests without you having to explicitly reset/restore them.
|
||||
|
||||
**Difference between cy.spy() and cy.stub()**
|
||||
|
||||
The main difference between `cy.spy` and [`cy.stub`](https://on.cypress.io/api/stub) is that `cy.spy` does not replace the method, it only wraps it. So, while invocations are recorded, the original method is still called. This can be very useful when testing methods on native browser objects. You can verify a method is being called by your test and still have the original method action invoked.
|
||||
The main difference between `cy.spy()` and [`cy.stub()`](https://on.cypress.io/api/stub) is that `cy.spy()` does not replace the method, it only wraps it. So, while invocations are recorded, the original method is still called. This can be very useful when testing methods on native browser objects. You can verify a method is being called by your test and still have the original method action invoked.
|
||||
|
||||
**Assertion Support**
|
||||
|
||||
@@ -115,7 +115,8 @@ When clicking on the `spy-1` event within the command log, the console outputs t
|
||||
|
||||
# See also
|
||||
|
||||
- [as](https://on.cypress.io/api/as)
|
||||
- [clock](https://on.cypress.io/api/clock)
|
||||
- [Guide: Stubs, Spies and Clocks ](https://on.cypress.io/guides/stubs-spies-clocks)
|
||||
- [Recipe: Controlling Behavior with Spies, Stubs, and Clocks](https://github.com/cypress-io/cypress-example-recipes#controlling-behavior-with-spies-stubs-and-clocks)
|
||||
- [stub](https://on.cypress.io/api/stub)
|
||||
- [clock](https://on.cypress.io/api/clock)
|
||||
|
||||
@@ -16,7 +16,7 @@ cy.stub(object, method, replacerFn)
|
||||
|
||||
## Usage
|
||||
|
||||
`.stub()` cannot be chained off any other cy commands, so should be chained off of `cy` for clarity.
|
||||
`cy.stub()` cannot be chained off any other cy commands, so should be chained off of `cy` for clarity.
|
||||
|
||||
**{% fa fa-check-circle green %} Valid Usage**
|
||||
|
||||
@@ -28,7 +28,7 @@ cy.stub(user, 'addFriend')
|
||||
|
||||
**{% fa fa-angle-right %} object** ***(Object)***
|
||||
|
||||
The object that has the `method` to be replaced.
|
||||
The `object` that has the `method` to be replaced.
|
||||
|
||||
**{% fa fa-angle-right %} method** ***(String)***
|
||||
|
||||
@@ -36,14 +36,13 @@ The name of the `method` on the `object` to be wrapped.
|
||||
|
||||
**{% fa fa-angle-right %} replacerFn** ***(Function)***
|
||||
|
||||
The function used to replaces the `method` on the `object`.
|
||||
|
||||
The function used to replace the `method` on the `object`.
|
||||
|
||||
## Yields
|
||||
|
||||
Unlike most Cypress commands, `cy.stub` is *synchronous* and returns a value (the stub) instead of a Promise-like chain-able object.
|
||||
Unlike most Cypress commands, `cy.stub()` is *synchronous* and returns a value (the stub) instead of a Promise-like chain-able object.
|
||||
|
||||
`cy.stub` returns a [Sinon.js stub](http://sinonjs.org/docs/#stubs). All methods found on Sinon.JS [spies](http://sinonjs.org/docs/#spies-api) and [stubs](http://sinonjs.org/docs/#stubs-api) are supported.
|
||||
`cy.stub()` returns a [Sinon.js stub](http://sinonjs.org/docs/#stubs). All methods found on Sinon.JS [spies](http://sinonjs.org/docs/#spies-api) and [stubs](http://sinonjs.org/docs/#stubs-api) are supported.
|
||||
|
||||
## Timeout
|
||||
|
||||
@@ -129,15 +128,15 @@ You will see the following in the command log:
|
||||
|
||||
**Automatic reset/restore between tests**
|
||||
|
||||
`cy.stub` creates stubs in a [sandbox](http://sinonjs.org/docs/#sandbox), so all stubs created are automatically reset/restored between tests without you having to explicitly reset/restore them.
|
||||
`cy.stub()` creates stubs in a [sandbox](http://sinonjs.org/docs/#sandbox), so all stubs created are automatically reset/restored between tests without you having to explicitly reset/restore them.
|
||||
|
||||
**Difference between cy.spy() and cy.stub()**
|
||||
|
||||
The main difference between `cy.spy` and [`cy.stub`](https://on.cypress.io/api/stub) is that `cy.spy` does not replace the method, it only wraps it. So, while invocations are recorded, the original method is still called. This can be very useful when testing methods on native browser objects. You can verify a method is being called by your test and still have the original method action invoked.
|
||||
The main difference between `cy.spy()` and [`cy.stub()`](https://on.cypress.io/api/stub) is that `cy.spy()` does not replace the method, it only wraps it. So, while invocations are recorded, the original method is still called. This can be very useful when testing methods on native browser objects. You can verify a method is being called by your test and still have the original method action invoked.
|
||||
|
||||
**Assertion Support**
|
||||
|
||||
Cypress has built-in [sinon-as-promised](https://github.com/bendrucker/sinon-as-promised) support, so the stubs returned by `cy.stub` supports the `.resolves` and `.rejects` API provided by `sinon-as-promised`.
|
||||
Cypress has built-in [sinon-as-promised](https://github.com/bendrucker/sinon-as-promised) support, so the stubs returned by `cy.stub()` supports the `.resolves` and `.rejects` API provided by `sinon-as-promised`.
|
||||
|
||||
# Command Log
|
||||
|
||||
@@ -162,8 +161,9 @@ When clicking on the `(stub-1)` event within the command log, the console output
|
||||
|
||||
# See also
|
||||
|
||||
- [as](https://on.cypress.io/api/as)
|
||||
- [clock](https://on.cypress.io/api/clock)
|
||||
- [Guide: Stubs, Spies and Clocks ](https://on.cypress.io/guides/stubs-spies-clocks)
|
||||
- [Recipe: Controlling Behavior with Spies, Stubs, and Clocks](https://github.com/cypress-io/cypress-example-recipes#controlling-behavior-with-spies-stubs-and-clocks)
|
||||
- [Recipe: Unit Test - Stubbing Dependencies](https://github.com/cypress-io/cypress-example-recipes#unit-test---stubbing-dependencies)
|
||||
- [spy](https://on.cypress.io/api/spy)
|
||||
- [clock](https://on.cypress.io/api/clock)
|
||||
|
||||
@@ -20,7 +20,7 @@ Submit a form.
|
||||
**{% fa fa-check-circle green %} Valid Usage**
|
||||
|
||||
```javascript
|
||||
cy.get('form').submit() // Submit a form
|
||||
cy.get('form').submit() // Submit a form
|
||||
```
|
||||
|
||||
**{% fa fa-exclamation-triangle red %} Invalid Usage**
|
||||
@@ -42,7 +42,7 @@ Pass in an options object to change the default behavior of `.submit()`.
|
||||
|
||||
## Timeout
|
||||
|
||||
`.submit()` will continue to try to submit the form for the duration of the [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts)
|
||||
`.submit()` will continue to try to submit the form for the duration of the [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts).
|
||||
|
||||
# Example
|
||||
|
||||
@@ -81,3 +81,4 @@ When clicking on `submit` within the command log, the console outputs the follow
|
||||
# See also
|
||||
|
||||
- [click](https://on.cypress.io/api/click)
|
||||
- [type](https://on.cypress.io/api/type)
|
||||
|
||||
@@ -4,13 +4,13 @@ comments: true
|
||||
description: ''
|
||||
---
|
||||
|
||||
Yield the current yielded subject as the first argument of a function.
|
||||
Yield the previously yielded subject as the first argument of a function.
|
||||
|
||||
# Syntax
|
||||
|
||||
```javascript
|
||||
.spread(callbackFn)
|
||||
.spread(options, callbackFn)
|
||||
.then(callbackFn)
|
||||
.then(options, callbackFn)
|
||||
```
|
||||
|
||||
## Usage
|
||||
@@ -28,7 +28,7 @@ cy.location().then(function(loc) {}) // Yields location object as first arg
|
||||
|
||||
**{% fa fa-angle-right %} callbackFn** ***(Function)***
|
||||
|
||||
Pass a function that takes the current yielded subject as it's first argument.
|
||||
Pass a function that takes the previously yielded subject as it's first argument.
|
||||
|
||||
**{% fa fa-angle-right %} options** ***(Object)***
|
||||
|
||||
@@ -42,13 +42,13 @@ Option | Default | Notes
|
||||
|
||||
`.then()` is modeled identically to the way Promises work in JavaScript. Whatever is returned from the callback function becomes the new subject and will flow into the next command (with the exception of `null` and `undefined`).
|
||||
|
||||
When `null` or `undefined` is returned by the callback function, the subject will not be modified and will instead carry over to the next command.
|
||||
When `null` or `undefined` are returned by the callback function, the subject will not be modified and will instead carry over to the next command.
|
||||
|
||||
Just like Promises, you can return any compatible "thenable" (anything that has a `.then()` interface) and Cypress will wait for that to resolve before continuing forward through the chain of commands.
|
||||
|
||||
## Timeout
|
||||
|
||||
`.then` will retry for the duration of the [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts) or the duration of the `timeout` specified in the command's [options](#options).
|
||||
`.then()` will retry for the duration of the [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts) or the duration of the `timeout` specified in the command's [options](#options).
|
||||
|
||||
# Examples
|
||||
|
||||
@@ -56,12 +56,6 @@ Just like Promises, you can return any compatible "thenable" (anything that has
|
||||
|
||||
**The element `input` is yielded**
|
||||
|
||||
```html
|
||||
<form id="todos">
|
||||
<input type="text" class="addTodo" />
|
||||
</form>
|
||||
```
|
||||
|
||||
```javascript
|
||||
cy.get('form').find('input').then(function($input){
|
||||
// work with $input here
|
||||
@@ -81,18 +75,17 @@ cy.then(function(){
|
||||
})
|
||||
```
|
||||
|
||||
**Returning `null` or `undefined` will not modify the subject**
|
||||
**Returning `null` or `undefined` will not modify the yielded subject**
|
||||
|
||||
```javascript
|
||||
cy
|
||||
.get('form').then(function($form){
|
||||
console.log('form is:', $form)
|
||||
// undefined is returned here, therefore
|
||||
// the $form subject will automatically
|
||||
// carry over and allow for continued chaining
|
||||
// undefined is returned here, but $form will be
|
||||
// yielded to allow for continued chaining
|
||||
}).find('input').then(function($input){
|
||||
// we have our real $input element here since
|
||||
// our form element carried over and we called
|
||||
// we have our $input element here since
|
||||
// our form element was yielded and we called
|
||||
// .find("input") on it
|
||||
})
|
||||
```
|
||||
@@ -140,8 +133,8 @@ cy.get('button').click().then(function($button){
|
||||
# See also
|
||||
|
||||
- [and](https://on.cypress.io/api/and)
|
||||
- [its](https://on.cypress.io/api/its)
|
||||
- [invoke](https://on.cypress.io/api/invoke)
|
||||
- [Issuing Commands](https://on.cypress.io/guides/issuing-commands)
|
||||
- [its](https://on.cypress.io/api/its)
|
||||
- [should](https://on.cypress.io/api/should)
|
||||
- [spread](https://on.cypress.io/api/spread)
|
||||
- [Issuing Commands](https://on.cypress.io/guides/issuing-commands)
|
||||
|
||||
@@ -34,15 +34,15 @@ The number of `milliseconds` to move the clock. Any timers within the affected r
|
||||
|
||||
## Yields
|
||||
|
||||
`.tick()` yields a `clock` object with the following methods:
|
||||
`cy.tick()` yields a `clock` object with the following methods:
|
||||
|
||||
**`clock.tick(milliseconds)`**
|
||||
- **`clock.tick(milliseconds)`**
|
||||
|
||||
Move the clock a number of milliseconds. Any timers within the affected range of time will be called.
|
||||
Move the clock a number of milliseconds. Any timers within the affected range of time will be called.
|
||||
|
||||
**`clock.restore()`**
|
||||
- **`clock.restore()`**
|
||||
|
||||
Restore all overridden native functions. This is automatically called between tests, so should not generally be needed.
|
||||
Restore all overridden native functions. This is automatically called between tests, so should not generally be needed.
|
||||
|
||||
You can also access the `clock` object via `this.clock` in a [`.then()`](https://on.cypress.io/api/then) callback.
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ description: ''
|
||||
|
||||
Get the title of the document.
|
||||
|
||||
|
||||
# Syntax
|
||||
|
||||
```javascript
|
||||
@@ -28,7 +27,7 @@ cy.title()
|
||||
|
||||
**{% fa fa-angle-right %} options** ***(Object)***
|
||||
|
||||
Pass in an options object to change the default behavior of `cy.title`.
|
||||
Pass in an options object to change the default behavior of `cy.title()`.
|
||||
|
||||
Option | Default | Notes
|
||||
--- | --- | ---
|
||||
@@ -47,7 +46,7 @@ Option | Default | Notes
|
||||
|
||||
## Title
|
||||
|
||||
**Assert that the document's title eq "My Awesome Application"**
|
||||
**Assert that the document's title is "My Awesome Application"**
|
||||
|
||||
```javascript
|
||||
cy.title().should('eq', 'My Awesome Application')
|
||||
@@ -55,7 +54,7 @@ cy.title().should('eq', 'My Awesome Application')
|
||||
|
||||
# Command Log
|
||||
|
||||
**Assert that the document's title include 'New User'**
|
||||
**Assert that the document's title includes 'New User'**
|
||||
|
||||
```javascript
|
||||
cy.title().should('include', 'New User')
|
||||
|
||||
@@ -40,7 +40,6 @@ cy.location().trigger('mouseleave') // Errors, 'location' does not yield DOM el
|
||||
|
||||
The name of the `event` to be triggered on the DOM element.
|
||||
|
||||
|
||||
**{% fa fa-angle-right %} position** ***(String)***
|
||||
|
||||
The position where the event should be triggered. The `center` position is the default position. Valid positions are `topLeft`, `top`, `topRight`, `left`, `center`, `right`, `bottomLeft`, `bottom`, and `bottomRight`.
|
||||
@@ -64,8 +63,8 @@ Option | Default | Notes
|
||||
`bubbles` | `true` | Whether the event bubbles
|
||||
`cancelable` | `true` | Whether the event is cancelable
|
||||
`interval` | `16` | Interval which to retry triggering the event
|
||||
`timeout` | [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts) | Total time to retry triggering the event
|
||||
`log` | `true` | Whether to display command in Command Log
|
||||
`timeout` | [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts) | Total time to retry triggering the event
|
||||
|
||||
You can also include arbitrary event properties (e.g. `clientX`, `shiftKey`) and they will be attached to the event. Passing in coordinate arguments (`clientX`, `pageX`, etc) will override the position coordinates.
|
||||
|
||||
@@ -75,14 +74,7 @@ You can also include arbitrary event properties (e.g. `clientX`, `shiftKey`) and
|
||||
|
||||
## Timeout
|
||||
|
||||
`.trigger()` will wait until the element is in an 'interactable' state for the duration of the [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts) or the duration of the `timeout` specified in the command's options
|
||||
|
||||
|
||||
The DOM element must be in an "interactable" state prior to the triggered event happening (it must be visible and not disabled).
|
||||
|
||||
|
||||
|
||||
Cypress automatically scrolls the element into view prior to attempting to trigger the event.
|
||||
`.trigger()` will wait until the element is in an 'interactable' state for the duration of the [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts) or the duration of the `timeout` specified in the command's options.
|
||||
|
||||
# Examples
|
||||
|
||||
@@ -90,6 +82,8 @@ Cypress automatically scrolls the element into view prior to attempting to trigg
|
||||
|
||||
**Trigger a `mouseover` on the button**
|
||||
|
||||
The DOM element must be in an "interactable" state prior to the triggered event happening (it must be visible and not disabled).
|
||||
|
||||
```javascript
|
||||
cy.get('button').trigger('mouseover') // yields 'button'
|
||||
```
|
||||
@@ -114,7 +108,8 @@ Note that some implementations may rely on the `input` event instead, which is f
|
||||
```javascript
|
||||
cy.get('input[type=range]').as('range')
|
||||
.invoke('val', 25)
|
||||
.ttrigger('change')
|
||||
.trigger('change')
|
||||
|
||||
cy.get('@range').siblings('p').should('have.text', '25')
|
||||
```
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ description: ''
|
||||
|
||||
Type into a DOM element.
|
||||
|
||||
|
||||
# Syntax
|
||||
|
||||
```javascript
|
||||
@@ -44,15 +43,15 @@ Sequence | Notes
|
||||
`{% raw %}{{{% endraw %}}`| Types the literal `{` key
|
||||
`{backspace}` | Deletes character to the left of the cursor
|
||||
`{del}` | Deletes character to the right of the cursor
|
||||
`{downarrow}` | Fires down event but does **not** move the cursor
|
||||
`{enter}` | Types the Enter key
|
||||
`{esc}` | Types the Escape key
|
||||
`{leftarrow}` | Moves cursor left
|
||||
`{rightarrow}` | Moves cursor right
|
||||
`{downarrow}` | Fires down event but does **not** move the cursor
|
||||
`{uparrow}` | Fires up event but does **not** move the cursor
|
||||
`{selectall}` | Selects all text by creating a `selection range`
|
||||
`{uparrow}` | Fires up event but does **not** move the cursor
|
||||
|
||||
Text passed to `cy.type` may also include any of the these modifier character sequences:
|
||||
Text passed to `.type()` may also include any of the these modifier character sequences:
|
||||
|
||||
Sequence | Notes
|
||||
--- | ---
|
||||
@@ -69,9 +68,9 @@ Option | Default | Notes
|
||||
--- | --- | ---
|
||||
`delay` | `10` | Delay after each keypress
|
||||
`force` | `false` | Forces type, disables error checking prior to type
|
||||
`release` | `true` | Keep a modifier activated between commands
|
||||
`interval` | `16` | Interval to retry type
|
||||
`log` | `true` | Whether to display command in Command Log
|
||||
`release` | `true` | Keep a modifier activated between commands
|
||||
`timeout` | [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts) | Total time to retry the type
|
||||
|
||||
## Yields
|
||||
@@ -80,7 +79,7 @@ Option | Default | Notes
|
||||
|
||||
## Timeout
|
||||
|
||||
`.type()` will continue to retry typing for the duration of the [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts)
|
||||
`.type()` will continue to retry typing for the duration of the [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts).
|
||||
|
||||
# Examples
|
||||
|
||||
@@ -100,9 +99,9 @@ cy.get('textarea').type('Hello world') //yields <textarea>
|
||||
|
||||
**Mimic user typing behavior**
|
||||
|
||||
Each keypress is delayed 10ms by default in order to simulate how a very fast user types!
|
||||
|
||||
```javascript
|
||||
// each keypress is delayed 10ms by default
|
||||
// which simulates how a very fast user types!
|
||||
cy.get('[contenteditable]').type('some text!')
|
||||
```
|
||||
|
||||
@@ -170,7 +169,7 @@ Special characters (`{leftarrow}`, `{selectall}`, etc) are not permitted.
|
||||
|
||||
**Force a click to happen prior to type**
|
||||
|
||||
Prior to typing, if the DOM element isn't currently focused, Cypress issues a [click](https://on.cypress.io/api/click) on the element, which will cause the element to receive focus.
|
||||
Prior to typing, if the DOM element isn't currently focused, Cypress issues a [.click()](https://on.cypress.io/api/click) on the element, which causes the element to receive focus.
|
||||
|
||||
Sometimes it is useful to force the click to happen in order to disables error checking, like whether the element is currently visible.
|
||||
|
||||
@@ -184,7 +183,7 @@ Be careful with the `force` option because it allows the type to happen where it
|
||||
|
||||
## Key Combinations
|
||||
|
||||
When using special character sequences, it's possible to activate modifier keys and type key combinations, such as `CTRL + R` or `SHIFT + ALT + Q`. The modifier(s) remain activated for the duration of the `.type()` command, and are released when all subsequent characters are typed, unless [`{ release: false }`](https://on.cypress.io/api/type#options) is passed as an [option](https://on.cypress.io/api/type#release-behavior). A `keydown` event is fired when a modifier is activated and a `keyup` event is fired when it is released.
|
||||
When using special character sequences, it's possible to activate modifier keys and type key combinations, such as `CTRL + R` or `SHIFT + ALT + Q`. The modifier(s) remain activated for the duration of the `.type()` command, and are released when all subsequent characters are typed, unless [`{release: false}`](https://on.cypress.io/api/type#options) is passed as an [option](https://on.cypress.io/api/type#release-behavior). A `keydown` event is fired when a modifier is activated and a `keyup` event is fired when it is released.
|
||||
|
||||
**Type a key combination**
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ Uncheck checkbox(es).
|
||||
**{% fa fa-check-circle green %} Valid Usage**
|
||||
|
||||
```javascript
|
||||
cy.get('[type="checkbox"]').uncheck() // Yields checkbox element
|
||||
cy.get('[type="checkbox"]').uncheck() // Unchecks checkbox element
|
||||
```
|
||||
|
||||
**{% fa fa-exclamation-triangle red %} Invalid Usage**
|
||||
@@ -50,10 +50,10 @@ Pass in an options object to change the default behavior of `.uncheck()`.
|
||||
|
||||
Option | Default | Notes
|
||||
--- | --- | ---
|
||||
`interval` | `16` | Interval which to retry a check
|
||||
`timeout` | [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts) | Total time to retry the check
|
||||
`force` | `false` | Forces check, disables error checking prior to check
|
||||
`interval` | `16` | Interval which to retry a check
|
||||
`log` | `true` | Whether to display command in Command Log
|
||||
`timeout` | [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts) | Total time to retry the check
|
||||
|
||||
# Examples
|
||||
|
||||
@@ -65,7 +65,7 @@ Option | Default | Notes
|
||||
cy.get(':checkbox').uncheck()
|
||||
```
|
||||
|
||||
**Uncheck element with the id `saveUserName`**
|
||||
**Uncheck element with the id 'saveUserName'**
|
||||
|
||||
```javascript
|
||||
cy.get('#saveUserName').uncheck()
|
||||
@@ -81,7 +81,7 @@ cy.get('input[type="checkbox"]').uncheck(['ga'])
|
||||
|
||||
## Values
|
||||
|
||||
**Uncheck the checkboxes with the value of 'ga' and 'ca'**
|
||||
**Uncheck the checkboxes with the values 'ga' and 'ca'**
|
||||
|
||||
```javascript
|
||||
cy.get('[type="checkbox"]').uncheck(['ga', 'ca'])
|
||||
|
||||
@@ -7,7 +7,7 @@ description: ''
|
||||
Get the current URL.
|
||||
|
||||
{% note info %}
|
||||
This is the same as [`cy.location.href`](https://on.cypress.io/api/location)
|
||||
This is an alias of [`cy.location.href`](https://on.cypress.io/api/location)
|
||||
{% endnote %}
|
||||
|
||||
# Syntax
|
||||
@@ -24,7 +24,7 @@ cy.url(options)
|
||||
**{% fa fa-check-circle green %} Valid Usage**
|
||||
|
||||
```javascript
|
||||
cy.url()
|
||||
cy.url() // Get url
|
||||
```
|
||||
|
||||
## Arguments
|
||||
@@ -41,7 +41,7 @@ Option | Default | Notes
|
||||
|
||||
## Yields
|
||||
|
||||
`.url()` yields the current URL as a string.
|
||||
`cy.url()` yields the current URL as a string.
|
||||
|
||||
## Timeout
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ cy.viewport(preset, orientation, options)
|
||||
**{% fa fa-check-circle green %} Valid Usage**
|
||||
|
||||
```javascript
|
||||
cy.viewport(550, 750)
|
||||
cy.viewport('iphone-6')
|
||||
cy.viewport(550, 750) // Set viewport to 550px x 750px
|
||||
cy.viewport('iphone-6') // Set viewport to 357px x 667px
|
||||
```
|
||||
|
||||
## Arguments
|
||||
@@ -42,7 +42,7 @@ Height of viewport in pixels (must be between 200 and 3000).
|
||||
|
||||
**{% fa fa-angle-right %} preset** ***(String)***
|
||||
|
||||
A preset dimension (in pixels) to set the viewport. Preset supports the following options:
|
||||
A preset dimension to set the viewport. Preset supports the following options:
|
||||
|
||||
| Preset | width | height |
|
||||
| ----------- | ----- | ------ |
|
||||
@@ -63,7 +63,7 @@ The orientation of the screen. The *default orientation* is `portrait`. Pass `la
|
||||
|
||||
**{% fa fa-angle-right %} options** ***(Object)***
|
||||
|
||||
Pass in an options object to change the default behavior of `cy.viewport`.
|
||||
Pass in an options object to change the default behavior of `cy.viewport()`.
|
||||
|
||||
Option | Default | Notes
|
||||
--- | --- | ---
|
||||
@@ -71,7 +71,7 @@ Option | Default | Notes
|
||||
|
||||
## Yields
|
||||
|
||||
`.viewport()` yields `null`.
|
||||
`cy.viewport()` yields `null`.
|
||||
|
||||
## Timeout
|
||||
|
||||
@@ -125,7 +125,6 @@ describe('Nav Menus', function(){
|
||||
**Resize the viewport to iPhone 6 width and height**
|
||||
|
||||
```javascript
|
||||
|
||||
cy.viewport('iphone-6') // viewport will change to 414px x 736px
|
||||
```
|
||||
|
||||
@@ -153,7 +152,7 @@ When hovering over each command, Cypress will automatically display the snapshot
|
||||
|
||||
By default, until you issue a `cy.viewport()` command, Cypress sets the width to `1000px` and the height to `660px` by default.
|
||||
|
||||
You can [change these default dimensions](https://on.cypress.io/guides/configuration) by adding the following to your `cypress.json`
|
||||
You can [change these default dimensions](https://on.cypress.io/guides/configuration) by adding the following to your `cypress.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
|
||||
@@ -13,8 +13,6 @@ cy.visit(url)
|
||||
cy.visit(url, options)
|
||||
```
|
||||
|
||||
`cy.visit` resolves when the remote page fires its `load` event.
|
||||
|
||||
## Usage
|
||||
|
||||
`cy.visit()` cannot be chained off any other cy commands, so should be chained off of `cy` for clarity.
|
||||
@@ -37,21 +35,20 @@ Pass in an options object to change the default behavior of `cy.visit()`.
|
||||
|
||||
Option | Default | Notes
|
||||
--- | --- | ---
|
||||
`log` | `true` | Whether to display command in Command Log
|
||||
`onBeforeLoad` | `function` | Called before your page has loaded all of its resources.
|
||||
`onLoad` | `function` | Called once your page has fired its load event.
|
||||
`timeout` | [pageLoadTimeout](https://on.cypress.io/guides/configuration#timeouts) | Total time to wait until `cy.visit` resolves
|
||||
`log` | `true` | Whether to display command in Command Log
|
||||
`timeout` | [pageLoadTimeout](https://on.cypress.io/guides/configuration#timeouts) | Total time to wait until `cy.visit()` resolves
|
||||
|
||||
You can also set all `cy.visit()` commands' `pageLoadTimeout` and `baseUrl` globally in [configuration](https://on.cypress.io/guides/configuration).
|
||||
|
||||
|
||||
## Yields
|
||||
|
||||
`cy.visit()` yields the remote `window` object.
|
||||
|
||||
## Timeout
|
||||
|
||||
`cy.visit` will retry for the duration of the [pageLoadTimeout](https://on.cypress.io/guides/configuration#timeouts) or the duration of the `timeout` specified in the command's [options](#options).
|
||||
`cy.visit()` will retry for the duration of the [pageLoadTimeout](https://on.cypress.io/guides/configuration#timeouts) or the duration of the `timeout` specified in the command's [options](#options).
|
||||
|
||||
# Examples
|
||||
|
||||
@@ -59,6 +56,8 @@ You can also set all `cy.visit()` commands' `pageLoadTimeout` and `baseUrl` glob
|
||||
|
||||
**Visit a local server running on http://localhost:8000**
|
||||
|
||||
`cy.visit()` resolves when the remote page fires its `load` event.
|
||||
|
||||
```javascript
|
||||
cy.visit('http://localhost:8000')
|
||||
```
|
||||
@@ -171,9 +170,9 @@ cy.server()
|
||||
cy.route('/users/**', 'fx:users')
|
||||
```
|
||||
|
||||
But if your app makes a request upon being initialized, *the above code will not work*. `cy.visit()` will resolve once its `load` event fires. The `server` and `route` commands are not processed until *after* `cy.visit()` resolves.
|
||||
But if your app makes a request upon being initialized, *the above code will not work*. `cy.visit()` will resolve once its `load` event fires. The [`cy.server()`](https://on.cypress.io/server) and [`cy.route()`](https://on.cypress.io/route) commands are not processed until *after* `cy.visit()` resolves.
|
||||
|
||||
Many applications will have already begun routing, initialization, and requests by the time the `cy.visit()` in the above code resolves. Therefore creating a `cy.server` will happen too late, and Cypress will not process the requests.
|
||||
Many applications will have already begun routing, initialization, and requests by the time the `cy.visit()` in the above code resolves. Therefore creating a [`cy.server()`](https://on.cypress.io/server) will happen too late, and Cypress will not process the requests.
|
||||
|
||||
Luckily Cypress supports this use case. Simply reverse the order of the commands:
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ description: ''
|
||||
|
||||
Wait for a number of milliseconds or wait for an aliased resource to resolve before moving on to the next command.
|
||||
|
||||
|
||||
# Syntax
|
||||
|
||||
```javascript
|
||||
@@ -53,20 +52,20 @@ Pass in an options object to change the default behavior of `cy.wait()`.
|
||||
|
||||
Option | Default | Notes
|
||||
--- | --- | ---
|
||||
`timeout` | [requestTimeout](https://on.cypress.io/guides/configuration#timeouts), [responseTimeout](https://on.cypress.io/guides/configuration#timeouts) | Override the default requestTimeout and responseTimeout (in ms)
|
||||
`log` | `true` | Whether to display command in Command Log
|
||||
`timeout` | [requestTimeout](https://on.cypress.io/guides/configuration#timeouts), [responseTimeout](https://on.cypress.io/guides/configuration#timeouts) | Override the default requestTimeout and responseTimeout (in ms)
|
||||
|
||||
You can also change the `requestTimeout` and `responseTimeout` globally for all `cy.wait()` commands in the [configuration](https://on.cypress.io/guides/configuration).
|
||||
|
||||
## Yields
|
||||
|
||||
When given a `time` argument, `.wait()` yields the previous commands yield.
|
||||
When given a `time` argument, `cy.wait()` yields the previous commands yield.
|
||||
|
||||
When given an `alias` argument, `.wait()` yields the xhr object of the aliased route.
|
||||
When given an `alias` argument, `cy.wait()` yields the XHR object of the aliased route.
|
||||
|
||||
## Timeout
|
||||
|
||||
`cy.wait` will wait for the request the duration of the [requestTimeout](https://on.cypress.io/guides/configuration#timeouts) and wait for the response for the duration of the [responseTimeout](https://on.cypress.io/guides/configuration#timeouts) or it will wait for the duration of both the request and response for the `timeout` specified in the command's [options](#options).
|
||||
`cy.wait()` will wait for the request the duration of the [requestTimeout](https://on.cypress.io/guides/configuration#timeouts) and wait for the response for the duration of the [responseTimeout](https://on.cypress.io/guides/configuration#timeouts) or it will wait for the duration of both the request and response for the `timeout` specified in the command's [options](#options).
|
||||
|
||||
# Examples
|
||||
|
||||
@@ -76,27 +75,27 @@ In Cypress, you almost never need to use `cy.wait()` for an arbitrary amount of
|
||||
|
||||
**Let's imagine the following examples:**
|
||||
|
||||
***Unnecessary wait for `cy.request`***
|
||||
***Unnecessary wait for `cy.request()`***
|
||||
|
||||
Waiting here is unnecessary since the `cy.request` command will not resolve until it receives a response from your server. Adding the wait here only adds 5 seconds after the `cy.request()` has already resolved.
|
||||
Waiting here is unnecessary since the [`cy.request()`](https://on.cypress.io/request) command will not resolve until it receives a response from your server. Adding the wait here only adds 5 seconds after the [`cy.request()`](https://on.cypress.io/request) has already resolved.
|
||||
|
||||
```javascript
|
||||
cy.request("http://localhost:8080/db/seed")
|
||||
cy.wait(5000) // <--- this is unnecessary
|
||||
```
|
||||
|
||||
***Unnecessary wait for `cy.visit`***
|
||||
***Unnecessary wait for `cy.visit()`***
|
||||
|
||||
Waiting for this is unnecessary because the `cy.visit()` resolves once the page fires its `load` event. By that time all of your assets have been loaded including javascript, stylesheets, and html.
|
||||
Waiting for this is unnecessary because the [`cy.visit()`](https://on.cypress.io/visit) resolves once the page fires its `load` event. By that time all of your assets have been loaded including javascript, stylesheets, and html.
|
||||
|
||||
```javascript
|
||||
cy.visit("http://localhost/8080")
|
||||
cy.wait(5000) // <--- this is unnecessary
|
||||
```
|
||||
|
||||
***Unnecessary wait for `cy.get`***
|
||||
***Unnecessary wait for `cy.get()`***
|
||||
|
||||
Waiting for the `cy.get()` below is unncessary because `cy.get()` automatically retries until the table's `tr` has a length of 2.
|
||||
Waiting for the [`cy.get()`](https://on.cypress.io/get) below is unncessary because [`cy.get()`](https://on.cypress.io/get) automatically retries until the table's `tr` has a length of 2.
|
||||
|
||||
Whenever commands have an assertion they will not resolve until their associated assertions pass. This enables you to simply describe the state of your application without having to worry about when it gets there.
|
||||
|
||||
@@ -125,15 +124,14 @@ cy.get("table tr").should("have.length", 2)
|
||||
```javascript
|
||||
// Wait for the route aliased as 'getAccount' to respond
|
||||
// without changing or stubbing its response
|
||||
cy
|
||||
.server()
|
||||
.route('/accounts/*').as('getAccount')
|
||||
.visit('/accounts/123')
|
||||
.wait('@getAccount').then(function(xhr){
|
||||
// we can now access the low level xhr
|
||||
// that contains the request body,
|
||||
// response body, status, etc
|
||||
})
|
||||
cy.server()
|
||||
cy.route('/accounts/*').as('getAccount')
|
||||
cy.visit('/accounts/123')
|
||||
cy.wait('@getAccount').then(function(xhr){
|
||||
// we can now access the low level xhr
|
||||
// that contains the request body,
|
||||
// response body, status, etc
|
||||
})
|
||||
```
|
||||
|
||||
**Wait automatically increments responses**
|
||||
|
||||
@@ -39,7 +39,7 @@ Option | Default | Notes
|
||||
|
||||
## Timeout
|
||||
|
||||
`cy.window()` will retry for the duration of the [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts)
|
||||
`cy.window()` will retry for the duration of the [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts).
|
||||
|
||||
# Examples
|
||||
|
||||
@@ -57,7 +57,7 @@ cy.window().then(function(win){
|
||||
|
||||
## Options
|
||||
|
||||
**Passes timeout through to `cy.should` assertion**
|
||||
**Passes timeout through to [`.should()`](https://on.cypress.io/should) assertion**
|
||||
|
||||
```javascript
|
||||
cy.window({ timeout: 10000 }).should('have.property', 'foo')
|
||||
|
||||
@@ -6,7 +6,6 @@ description: ''
|
||||
|
||||
Set the scope of the containing commands to the previously yielded subject and pass that as an argument to the callback function.
|
||||
|
||||
|
||||
# Syntax
|
||||
|
||||
```javascript
|
||||
|
||||
@@ -67,7 +67,6 @@ Option | Default | Notes
|
||||
|
||||
`cy.writeFile()` will wait up for the duration of [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts) for the server to write to the file.
|
||||
|
||||
|
||||
# Examples
|
||||
|
||||
## Text
|
||||
|
||||
Reference in New Issue
Block a user