Commands Flashcards

1
Q

cy.document()

A

Get the window.document of the page that is currently active.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

.and()

A

Alias to .should().

  • Used to make a chain of .should assertions more human-readable.
Common Usages:
.and(chainers)
.and(chainers, value)
.and(chainers, method, value)
.and(callbackFn)

Example:
cy.get(‘.err’).should(‘be.empty’).and(‘be.hidden’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

.as(aliasName)

A

A command that stores an element in an alias for use later.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

.check()

A

Command used to set checkboxes or radio input elements.

.check()
.check(value)
.check(values)
.check(options)
.check(value, options)
.check(values, options)

cy. get(‘[type=”checkbox”]’).check() // Check checkbox element
cy. get(‘[type=”radio”]’).first().check() // Check first radio element

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

.children()

A

Finds all the children of a given DOM element. Similar to the jQuery.children() command.

.children()
.children(selector)
.children(options)
.children(selector, options)

https://docs.cypress.io/api/commands/children.html#Syntax

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

.clear()

A

Command used to clear the value of an input or textarea.

Yields: Same as input.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

.click()

A

Command to work with clickable DOM elements. No arguments.

.click()
.click(options)
.click(position)
.click(position, options)
.click(x, y)
.click(x, y, options)

Yields: Same as input.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

cy.clock()

A

Command used to override the global clock. cy.clock() overrides native global functions related to time allowing them to be controlled synchronously via cy.tick() or the yielded clock object.

https://docs.cypress.io/api/commands/clock.html#Syntax

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

.closed()

A

Get the first DOM element that matches the selector (whether it be itself or one of its ancestors). Worked in the same manner as the JQuery .closed() command.

Yields: the new DOM element(s) it found.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

.contains()

A

Get the DOM element containing the text.

Chained:
.contains(content)
.contains(content, options)
.contains(selector, content)
.contains(selector, content, options)

From Cy root

cy. contains(content)
cy. contains(content, options)
cy. contains(selector, content)
cy. contains(selector, content, options)

Yields: the new DOM element it found.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

.dblclick()

A

Double-click a DOM element.

Usages:

cy. get(‘button’).dblclick() // Double click on button
cy. focused().dblclick() // Double click on el with focus
cy. contains(‘Welcome’).dblclick() // Double click on first el containing ‘Welcome’

Yields: the same subject it was given from the previous command.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

.debug()

A

Set a debugger and log what the previous command yields.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

cy.document()

A

Get the window.document of the page that is currently active.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

.each(callbackFn)

A

Command that allows for an assertion to iterate through an array like structure (arrays or objects with a length property).

Yields: the same subject it was given from the previous command.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

.end()

A

Command to end a chain of commands. This command is useful when you want to end a chain of commands and force the next command to not receive what was yielded in the previous command.

Yields: Null and yields null cannot be chained further.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

.eq()

A

Get A DOM element at a specific index in an array of elements.

Usage:

cy. get(‘tbody>tr’).eq(0) // Yield first ‘tr’ in ‘tbody’
cy. get(‘ul>li’).eq(4) // Yield fifth ‘li’ in ‘ul’

Yields: the new DOM element(s) it found.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

cy.exec(command, options)

A

Cy root command to run a system command.

Usage:
cy.exec(‘npm run build’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

.filter(selector, options)

A

Get the DOM elements that match a specific selector.

Usage:
cy.get(‘ul’).find(‘>li’).filter(‘.active’)

Yields: new DOM element(s) it found.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

.find()

A

Command used in a chain to getfind the descendent DOM elements of a specific selector. Similar to the jQuery .find().

Usage:
cy.get(‘.article’).find(‘footer’)

Yields: the new DOM element(s) it found.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

.first(options)

A

Get the first DOM element within a set of DOM elements.

Usage:
cy.get(‘nav a’).first()

Yields: the new DOM elements it found.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

cy.fixture(filePath, encoding, options)

A

Cy command to access predefined fixture elements.

Usage: 
cy.fixture('users').as('usersJson')  // load data from users.json
cy.fixture('logo.png').then((logo) => {
  // load data from logo.png
})

Yields: the contents of the file. Formatting is determined by its file extension.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

.focus()

.focus(options)

A

Command used to set the focus on a specific DOM element.

Usage:
cy.get(‘[type=”input”]’).focus()

Yields: yields the same subject it was given from the previous command.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

cy. focused()

cy. focused(options)

A

A Command that gets an already selected DOM element.

Yields: the DOM element(s) it found.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

cy.get(selector’)

A

Cy root command to get a given DOM element using the selector value. Very similar to the jQuery $(…).

Usage:
cy.get(‘.list > li’) // Yield the <li>’s in .list

Yields: the DOM element(s) it found.</li>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

cy.go(direction, options)

A

Cy root command to navigate back or forward to the previous or next URL in the browser’s history.

Usage:
cy.go(‘back’)

Yields: The window object after the page finishes loading.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

cy.hash(options)

A

Cy root command to access the current URL hash of the page that is currently active. Aliases to cy.location(‘hash’).

Usage:
cy.hash().should(‘eq’, ‘#/users/1’) // => true

Yields: yields the current URL’s hash (including the # character). or when no hash it yields an empty string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

.invoke(fnName)

A

A chained command to invoke a function. Muse be passed in an element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

.its(propertyName, options)

A

Get a property’s value on the previously yielded subject.

Usage:
cy.wrap({ age: 52 }).its(‘age’).should(‘eq’, 52)

Yields: the value of the property.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

.last(options)

A

A chainable command to get the last DOM element within a set of DOM elements.

Yields: the new DOM element(s) it found.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

cy.location(key, options)

A

A Cy root command to get the global window.location object of the page that is currently active.

Usage:
cy.location().should((loc) => {
expect(loc.hash).to.eq(‘#/users/123/edit’)
expect(loc.host).to.eq(‘localhost:8000’)
expect(loc.hostname).to.eq(‘localhost’)
expect(loc.href).to.eq(‘http://localhost:8000/app/index.html?q=dan#/users/123/edit’)
expect(loc.origin).to.eq(‘http://localhost:8000’)
expect(loc.pathname).to.eq(‘/app/index.html’)
expect(loc.port).to.eq(‘8000’)
expect(loc.protocol).to.eq(‘http:’)
expect(loc.search).to.eq(‘?q=dan’)
expect(loc.toString()).to.eq(‘http://localhost:8000/app/index.html?q=brian#/users/123/edit’)
})

Yields: the location object and its properties.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

cy. log(message)

cy. log(message, args…)

A

Print a message to the Cypress Command Log.

Yields: Null and can not be chainable.

32
Q

.next()

A

A chainable commnd to et the immediately following sibling of each DOM element within a set of DOM elements. Simliar to the JQuery .next() command .

Usage: cy.get(‘nav a:first’).next()

Yields: new DOM element(s) it found.

33
Q

.nextAll()

A

A chainable command to get all following siblings of each DOM element in a set of matched DOM elements. Command use is to find an DOM element with .get(selector) and then use this command to find all the follwoing siblings.

Yields: the new DOM element(s) it found.

34
Q

.nextUntil()

A

Get all following siblings of each DOM element in a set of matched DOM elements up to, but not including, the element provided. This option allows the user to combine a selector with a filter option.

Usages:
.nextUntil(selector)
.nextUntil(selector, filter)
.nextUntil(selector, filter, options)
.nextUntil(element)
.nextUntil(element, filter)
.nextUntil(element, filter, options)

Yields: the new DOM element(s) it found.

35
Q

.not(selector)

A

A chainable command to filter DOM element(s) from a set of DOM elements. This is the opposite of the .filter() and similar to the JQuery .not().

Yields: the new DOM element(s) it found.

36
Q

.parent()

A

Get the parent DOM element of a set of DOM elements.

Usage: cy.get(‘li.active’).parent()

Yields: new DOM element(s) it found.

37
Q

.parents()

A

Get the parent DOM elements of a set of DOM elements. Unlike the .parent(), it will travel up multiple levels.

Usage(s):

cy. get(‘li.active’).parents()
cy. get(‘li.active’).parents(‘.main-nav’)

Yields: the new DOM element(s) it found.

38
Q

.parentsUntil(selector)

A

This chainable function matches up the DOM tree (ancestors) and uses a selector to limit its reach, but not including, the element provided.

39
Q

cy.pause() or .pause()

A

A cy root or chainable function, that stops cy commands from running and allows interaction with the application under test. You can then “resume” running all commands or choose to step through the “next” commands from the Command Log.

Yields: the same subject it was given from the previous command.

40
Q

.prev()

A

Chainable command that gets the immediately preceding sibling of each element in a set of the elements.

Usage:
cy.get(‘.active’).prev()

Yields: the new DOM element(s) it found.

41
Q

.prevAll()

A

Get all previous siblings of each DOM element in a set of matched DOM elements.

Yields: the new DOM element(s) it found.

42
Q

.prevUntil(selector, filter, options)

A

Get all previous siblings of each DOM element in a set of matched DOM elements up to, but not including, the element provided.

Yields: the new DOM element(s) it found.

43
Q

cy.readFile(fileName)

A

Read a file and yield its contents.

Usage:
cy.readFile(‘path/to/message.txt’).should(‘eq’, ‘Hello World’) // true

Yields: the contents of the file.

44
Q

cy.reload()

A

Cy root command to reload the current page.

Yields: the window object after the page finishes loading.

45
Q

cy.request(url)

A

Cy root command to make an HTTP request.

Yields: the response as an object literal containing properties such as: status, body, headers, duration

46
Q

.rightClick

A

Right click a DOM element.

Usage:
cy.get(‘#open-menu’).rightclick()

Yields: the same subject it was given from the previous command.

47
Q

cy.root()

A

Get the root DOM element. The root element yielded is by default. However, when calling .root() from a .within() command, the root element will point to the element you are “within”.

cy.get(‘form’).within(($form) => {
cy.get(‘input[name=”email”]’).type(‘john.doe@email.com’)
cy.get(‘input[name=”password”]’).type(‘password’)
cy.root().submit()
})

Yields: the root DOM element.

48
Q

cy.route()

A

Use cy.route() to manage the behavior of network requests.

cy.route(‘/users/**’)

Yields: yields null, can be aliased, but otherwise cannot be chained further.

49
Q

.screenshot()

A

Take a screenshot of the application under test and, optionally, the Cypress Command Log. Can be run from the .cy or as a chainable command.

Yields: the same subject it was given from the previous command.

50
Q

.scrollIntoView()

A

Scroll an element into view.

Yields: the same subject it was given from the previous command.

51
Q

.scrollTo(position)

A

Root or chainable command to scroll to a given position.

.scrollTo(position)
or
cy.scrollTo(position)

Yields: the same subject it was given from the previous command.

52
Q

.select(value)

A

Select an within a .

Yields: the same subject it was given from the previous command.

53
Q

cy.server()

A

Start a server to begin routing responses to cy.route() and cy.request().

Usage: 
cy.server({
  method: 'POST', delay: 1000,
  status: 422, response: {}
})

Yields: null, cannot be chained further.

54
Q

cy.setCookie()

A

Root command to set a browser cookie.

cy. setCookie(name, value)
cy. setCookie(name, value, options)

Yields: a cookie object literal with the following properties: name, value, path, domain, httpOnly, secure, expiry

55
Q

.should()

A

Create an assertion. Assertions are automatically retried until they pass or time out.

Usage: 
.should(chainers)
.should(chainers, value)
.should(chainers, method, value)
.should(callbackFn)

Yields: the same subject it was given from the previous command.

56
Q

.siblings()

A

Get sibling DOM elements.

Yields: new DOM element(s) it found.

57
Q

.spread(callbackFn)

A

A chainable function to expand an array into multiple arguments.

58
Q

cy.spy(object, method)

A

Wrap a method in a spy in order to record calls to and arguments of the function.

Yields: 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. All methods found on Sinon.JS spies are supported.

59
Q

cy.stub()

A

Replace a function, record its usage and control its behavior.

cy. stub()
cy. stub(object, method)
cy. stub(object, method, replacerFn)

Yields: 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. All methods found on Sinon.js spies and stubs are supported.

60
Q

.submit()

A

Chainable command to submit an HTML form.

.submit()
.submit(options)

Yields: the same subject it was given from the previous command.

61
Q

cy.task(event)

A

Execute code in Node via the task plugin event.

Yields: the value returned or resolved by the task event in the pluginsFile.

62
Q

.then(callbackFn)

A

Enables you to work with the subject yielded from the previous command.

cy.get('button').then(($btn) => {
  const cls = $btn.class()
  cy.wrap($btn).click().should('not.have.class', cls)
})
63
Q

cy.tick(milliseconds)

A

Move time after overriding a native time function with cy.clock().

Yields: a clock object with the following methods: clock.tick(milliseconds) and clock.restore().

64
Q

cy.title()

A

Get the document.title property of the page that is currently active.

cy.title().should(‘eq’, ‘My Awesome Application’)

Yields: the document.title property of the current page.

65
Q

.trigger(eventName)

A

Trigger an event on a DOM element.

.trigger(eventName)
.trigger(eventName, position)
.trigger(eventName, options)
.trigger(eventName, x, y)
.trigger(eventName, position, options)
.trigger(eventName, x, y, options)

Yields: the same subject it was given from the previous command.

66
Q

.type(string)

A

Type into a DOM element.

cy.get(‘input’).type(‘Hello, World’)

Yields: the same subject it was given from the previous command.

67
Q

.uncheck()

A

Uncheck checkbox(es).

cy.get(‘#saveUserName’).uncheck()

Yields: the same subject it was given from the previous command.

68
Q

cy.url()

A

Get the current URL of the page that is currently active. Alias of cy.location(‘href’).

Yields: the current URL as a string.

69
Q

cy.viewport(width, height)

A

Control the size and orientation of the screen for your application.

cy. viewport(width, height)
cy. viewport(preset, orientation)
cy. viewport(width, height, options)
cy. viewport(preset, orientation, options)

Yields: Null and cannot be chained further.

70
Q

cy.visit()

A

Visit a remote URL.

cy. visit(url)
cy. visit(url, options)
cy. visit(options)

71
Q

cy.wait(time)

A

Wait for a number of milliseconds or wait for an aliased resource to resolve before moving on to the next command.

cy. wait(time)
cy. wait(alias)
cy. wait(aliases)
cy. wait(time, options)
cy. wait(alias, options)
cy. wait(aliases, options)

72
Q

cy.window()

A

Get the window object of the page that is currently active.

Yields: the window object.

73
Q

.within(callbackfn)

A

Scopes all subsequent cy commands to within this element. Useful when working within a particular group of elements such as a .

cy.get(‘form’).within(($form) => {
cy.get(‘input[name=”email”]’).type(‘john.doe@email.com’)
cy.get(‘input[name=”password”]’).type(‘password’)
cy.root().submit()
})

Yields: the same subject it was given from the previous command.

74
Q

.wrap(subject)

A

Yield the object passed into .wrap().

cy.wrap({ name: ‘Jane Lane’ })

Yields: the object it was called with.

75
Q

cy.writeFile(filePath, contents)

A

Write to a file with the specified contents.

Yields: the value of the contents argument.