Click an exact match text in Cypress

Regular Expressions will work nicely here. .contains() allows for regex So you can do a regex that matches the whole string only (use ^ and $). That way anything with extra characters won’t match (like New Navigation Label). So for example, you could do: cy.get(`[data-test=”dropdown”]`) .find(‘.item’) .contains(/^Navigation Label$/) .click(); Regex is a little tricky when … Read more

How do you check the equality of the inner text of a element using cypress?

I think you can simplify this. Assuming you have HTML that looks like this: <div data-test-id=”Skywalker,Anakin”> <div class=”.channel-name”>Skywalker,Anakin</div> </div> You can write your assert like this: cy.get(‘[data-test-id=”Skywalker,Anakin”]’).should( “have.text”, “Skywalker,Anakin” ); This passed for me and if I modified the HTML to Skywalker,Anakin 1 it failed as you would expect. Cypress uses the have.text to look … Read more

Check if an error has been written to the console

This does exactly what I needed of catching any error in the console and do an assertion of the logs count. Just add the following in cypress/support/index.js Cypress.on(‘window:before:load’, (win) => { cy.spy(win.console, ‘error’); cy.spy(win.console, ‘warn’); }); afterEach(() => { cy.window().then((win) => { expect(win.console.error).to.have.callCount(0); expect(win.console.warn).to.have.callCount(0); }); });

Cypress : How to get returned value from custom commands ? (Cypress-promise)

To do this I’m using wrap() to return a Chainable containing the value I want to return. Module function foo() { return cy.wrap(‘foo’); } Cypress.Commands.add(‘foo’, foo); Test File cy.foo().then(value => console.log(value)); // foo Since wrap() is returning a Cypress.Chainable, we can call .then() on our commands. What ever is passed into wrap() is yielded to … Read more

Cypress does not always executes click on element

For those whore are using cypress version since/after “6.x.x” You could use { force: true } like: cy.get(“YOUR_SELECTOR”).click({ force: true }); but this might not solve it ! The problem might be more complex, that’s why check below My solution: cy.get(“YOUR_SELECTOR”).trigger(“click”); Explanation: In my case, I needed to watch a bit deeper what’s going on. … Read more

Move cypress folder from the root of the project

Cypress has a few configuration options to specify custom folder structure. For that you will need to have cypress.json file in the root of your project and specify the following structure there for cypress to properly pick up the files in test/cypress/: { “fixturesFolder”: “test/cypress/fixtures”, “integrationFolder”: “test/cypress/integration”, “pluginsFile”: “test/cypress/plugins/index.js”, “screenshotsFolder”: “test/cypress/screenshots”, “videosFolder”: “test/cypress/videos”, “downloadsFolder”: “test/cypress/downloads”, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)