Questions tagged [cypress]
Cypress an all-in-one web testing framework and assertion library developed in JavaScript, complete with automatic waits, request mocking, and request stubbing.
cypress
9,952
questions
408
votes
16
answers
364k
views
Test if element does not exist
I want to be able to click on a check box and test that an element is no longer in the DOM in Cypress. Can someone suggest how you do it?
// This is the Test when the checkbox is clicked and the ...
282
votes
17
answers
220k
views
Cypress: run only one test
I want to toggle only running one test, so I don't have to wait for my other tests to see the result of one test.
Currently, I comment out my other tests, but this is really annoying.
Is there a way ...
217
votes
11
answers
286k
views
In Cypress how to count a selection of items and get the length?
I'm starting to learn Cypress. I have a 4 row table (with a class of datatable). I can verify the number of rows this way:
cy.get('.datatable').find('tr').each(function(row, i){
expect(i).to....
131
votes
14
answers
82k
views
ESLint: 'cy' is not defined (Cypress)
I've just started using Cypress with my React Typescript project. I've gotten some simple tests to run:
describe('settings page', () => {
beforeEach(() => {
cy.visit('http://localhost:...
124
votes
22
answers
78k
views
Cypress causing type errors in jest assertions
I had been using react-testing-library as well as @testing-library/jest-dom/extend-expect. I installed Cypress yesterday, and now I'm getting Typescript errors on all my jest matchers:
Property '...
107
votes
12
answers
177k
views
How to select nth item inside select element in cypress
say I have the HTML:
<select name="subject" data-testid="contact-us-subject-field">
<option value="What is this regarding?">What is this regarding?</...
100
votes
9
answers
272k
views
Docker-compose exit code is 137 when there is no OOM exception
When I run the following command, I expect the exit code to be 0 since my combined container runs a test that successfully exits with an exit code of 0.
docker-compose up --build --exit-code-from ...
99
votes
3
answers
54k
views
How to access the value of baseURL in Cypress
I'm just starting to learn JavaScript and have been using Cypress to automate some regression tests. The test I writing currently is meant to verify link's text and href in a header and footer.
The ...
93
votes
12
answers
195k
views
How to check if element exists using Cypress.io [duplicate]
How to check if element is present or not, so that certain steps can be performed if element is present. Else certain different steps can be performed if element is not present.
I tried something ...
89
votes
8
answers
179k
views
Cypress - how to find by text content?
In Cypress, I want to select a button from a group of buttons based on its text-content. How can I do it? Here is my approach:
export const getCustomerButton = () => getNavigationSidenav()
.find(...
89
votes
7
answers
98k
views
Cypress pipe console.log and command log to output
Is it possible to redirect or capture Cypress browser log and command log to output?
I read some Cypress github issues on this topic. But I don't know how to make it work.
Basically, I want to capture ...
85
votes
7
answers
109k
views
How can I execute code before all tests suite with Cypress?
Basically, I want to login once before all my tests in all files are executed.
Should I call my login command in each test file using the before hook or is there any way to do it once before all tests?...
83
votes
4
answers
143k
views
Cypress get href attribute
I have a test case in which I have a link which opens in a new tab. Since Cypress doesn't support multiple tabs, I want to get the href attribute of that link and then open it in the same tab. I'm ...
79
votes
5
answers
129k
views
How to get the value from an input field into a const and log it
How to get the text input field value to a 'const' variable in Cypress, so that I can log that variable using cy.log(). The below code doesn't log anything, can someone familiar with Cypress.io please ...
79
votes
6
answers
95k
views
In Cypress, set a token in localStorage before test
I want to login and set a localStorage token on the client (specifically jwt)
How can I accomplish this using cy.request, as suggested in the Cypress Documentation?