Files
cypress/docs/source/api/welcome/api.md
2017-05-15 14:10:01 -04:00

8.6 KiB

title: api comments: true

{% note info New to Cypress? %} Read through our Guides first. {% endnote %}

Commands

Commands drive your tests in the browser like a real user would. They let you perform actions like typing, clicking, xhr requests, and can also assert things like "my button should be disabled".

Navigation
go Navigate back or forward to previous or next URL in the browser's history
reload Reload the page
visit Visit a remote url
Querying
contains Get a DOM element that contains specific text
get Get DOM element(s) by selector or alias
root Set the root scope to the current subject
within Set the root scope to the current subject
Assertions
and Chain multiple assertions together
should Make an assertion about the current subject
DOM Traversal
children Get the children DOM elements of the DOM elements
closest Get the closest ancestor DOM element
eq Get a DOM element at a specific index
filter Filter DOM elements by a selector
find Get descendants of DOM elements
first Get the first DOM element within a set of DOM elements
last Get the last DOM element
next Get the next sibling of the DOM elements
nextAll Get all following siblings of the DOM elements
nextUntil Get all following siblings of the DOM elements until another element
not Remove DOM elements from the set of DOM elements
parent Get the parent DOM element of the DOM elements
parents Get the parents DOM elements of the DOM elements
parentsUntil Get all ancestors of the DOM elements until another element
prev Get the previous sibling of elements
prevAll Get all previous siblings of the DOM elements
prevUntil Get all previous siblings of the DOM elements until another element
siblings Get all siblings DOM elements of the DOM elements
Actions
blur Blur a DOM element
check Select a checkbox or radio
clear Clear a value of an input or textarea
click Click a DOM element
dblclick Double-click on a DOM element
focus Focus on a DOM element
select Select an option in a select
submit Submit a form
type Type into a DOM element
uncheck Uncheck a checkbox or radio
Network Requests
request Make HTTP request
route Route responses to matching requests
server Control the behavior of network requests and responses
Connectors
each Iterate through each item in the current subject
its Get properties on the current subject
invoke Invoke the function on the current subject
spread Spread an array as individual arguments to a callback function
then Invokes a callback function with the current subject
Location (URL)
hash Get the current URL hash
location Get the window.location
url Get the current URL
Window
document Get the document
title Get the title of the document
window Get global window object
Waiting
wait Wait for a specific amount of time or resource to resolve
Aliasing
as Alias a route or DOM element for use later.
Spies, Stubs & Clocks
spy Wrap a method in a spy
stub Create a stub and/or replace a function with a stub
clock Control time in the browser
tick Move time in the browser
Files
fixture Load a fixture file to represent data
readFile Read a file's contents
writeFile Write to a file with the specified contents
Viewport
viewport Change the screen size of your application
Local Storage
clearLocalStorage Clear all data in local storage
Cookies
clearCookie Clear a browser cookie
clearCookies Clear all browser cookies
getCookie Get a browser cookie
getCookies Get all browser cookies
setCookie Set a browser cookie
Debugging
debug Set a debugger
pause Pause a command
Misc
end End the command chain
exec Execute a system command
focused Get the DOM element that is focused
log Print a message to the Command Log
screenshot Take a screenshot
wrap Wrap an object

Utilities

Utilities give you access to methods from other commonly used libraries.

Commands
_ Call any Underscore method
$ Call any jQuery method
moment Format or parse dates using moment methods
Blob Convert base64 strings to blob objects
Promise Instantiate a bluebird promise

Cypress API

The Cypress API enables you to configure the behavior of how Cypress works internally. You can do things like access Environment Variables, change configuration, create custom commands, and more.

Commands
config get and set configuration options
env get and set environment variables
Commands Commands API
Cookies Manage your application's cookies
Dom Find out whether an element is hidden
Server Permanently override default server options