cypress

JS/Cypress.io: How to iterate over 2 corresponding sets of data

蓝咒 提交于 2021-01-29 21:03:16
问题 JS/Cypress.io: How to iterate over 2 corresponding sets of data This is what I have currently and it works, but I want to make it more DRY (do not repeat yourself): Using Cypress.io: var states1 = [ "NE", "MO", "KS", "IA", "OK", "OR", "WA", "AZ", "NM", "NC", "SC", "GA", "FL" ]; cy.get('[data-popup-text="26% to 50% of People"]').within(() => { cy.wrap(states1).each(state => { cy.get(`[data-state="${state}"]`).trigger("mouseover", { force: true }); cy.get(`[data-state="${state}"]`).click({

Passing a same random number to all tests in Cypress

左心房为你撑大大i 提交于 2021-01-29 20:41:54
问题 So I have two tests - Test1.spec.js and Test2.spec.js and I want that with every test run a random number should be generated and the same random number should be used in both the specs. I wrote a simple Math.random() function for this under support/index.js Cypress.config('UniqueNumber', `${Math.floor(Math.random() * 10000000000000)}`) And in the tests I am writing as: cy.get('locator').type(Cypress.config('UniqueNumber')) When I am trying to execute the tests using the cypress app npm

JS/Cypress.io: How to iterate over 2 corresponding sets of data

让人想犯罪 __ 提交于 2021-01-29 18:31:20
问题 JS/Cypress.io: How to iterate over 2 corresponding sets of data This is what I have currently and it works, but I want to make it more DRY (do not repeat yourself): Using Cypress.io: var states1 = [ "NE", "MO", "KS", "IA", "OK", "OR", "WA", "AZ", "NM", "NC", "SC", "GA", "FL" ]; cy.get('[data-popup-text="26% to 50% of People"]').within(() => { cy.wrap(states1).each(state => { cy.get(`[data-state="${state}"]`).trigger("mouseover", { force: true }); cy.get(`[data-state="${state}"]`).click({

how to access dropdown selection in Cypress, get error: element is detached from the DOM

拥有回忆 提交于 2021-01-29 17:02:07
问题 I am trying to select a dropdown item using Cypress. When i use the Cypress's Open Selector Playground, and point at the Web Element, i get cy.get('.Dropdown-placeholder').type('Name') I get an error: CypressError Timed out retrying: cy.type() failed because this element is detached from the DOM. <div class="Dropdown-placeholder"></div> Cypress requires elements be attached in the DOM to interact with them. The previous command that ran was: > cy.get() This DOM element likely became detached

Removing Cypress default proxy settings

*爱你&永不变心* 提交于 2021-01-29 13:48:43
问题 I'm having trouble to load the page of my application under test when running Cypress test. After long investigation I figured out that Cypress is using a corporate proxy which is retrieved from my environment variables according to documentation https://docs.cypress.io/guides/references/proxy-configuration.html#View-proxy-settings-in-Cypress This proxy is no longer active so I remove it from my environment variables but Cypress is still using it even after restarting both cypress and VsCode.

How to return a value from Cypress custom command

末鹿安然 提交于 2021-01-29 13:42:55
问题 I am polling task for async rest call, how do I return value of taskStatus from this Cypress custom function. I want to use this value in my spec file. Is this the right way? **Cypress.Commands.add("pollTask", (TASK_URI,token) => { // const regex = /Ok|Error|Warning/mg; var taskStatus ='' cy.log(" *Task_URI : " + TASK_URI) cy.log(" *X-Auth-token : " + token) cy.server() var NEWURL = Cypress.config().baseUrl + TASK_URI cy.request({ method: 'GET', url: NEWURL, failOnStatusCode: false, headers:

How to get a random item from an array in Cypress using Javascript

江枫思渺然 提交于 2021-01-29 13:03:49
问题 I am attempting to write a Cypress test that selects a random radio button answer from each group of 5 questions per page. I am trying to do this by having the code choose a number between 1-5 and clicking on one. It is possible to get a random item from an array in javascript, so how to do this in Cypress? The Javascript array example that I am using is this: var myArray = ["Apples", "Bananas", "Pears"]; var randomItem = myArray[Math.floor(Math.random()*myArray.length)]; Since Cypress is

How to continue to execution even when one check fail

大兔子大兔子 提交于 2021-01-29 11:18:02
问题 I am trying to go to different urls and compare screenshots with baseline image using matchImageSnapshot. Issue here is when one of my url fail with matchimagesnapshot -it is not continuing to next URL.NOTE:I tried to run with variable --env failOnSnapshotDiff=false -issue with this approach is -i wont get any clue which url failed unless i go manually and check diff folder. Is there any way i can achieve this Say for eg i have 3 urls in my sample - i want to continue to next url even if url1

Cypress - let test fail if console.error occurs

百般思念 提交于 2021-01-29 09:52:43
问题 We would like to let any test in Cypress fail if console.error is called. Sometimes we have errors in the console log which does not let the test fail. We always have to look into the console window to check any error messages 回答1: Just add this to your support/index.js let consoleSpy; Cypress.on('window:before:load', (win) => { consoleSpy = cy.spy(win.console, "error") }) afterEach(() => { // consoleSpy can be null if test failed already in beforeEach if (consoleSpy) { expect(consoleSpy).not

How to chain cy.get in cypress

China☆狼群 提交于 2021-01-29 08:12:40
问题 I'm trying to get to #1 element then get to #2 element to click on #3 element . but I'm having a trouble with getting the correct CSS selector in Cypress. How to write a test script for this? I've tried cy.get('.ui.active.visible.button.floating.dropdown.fr-dropdown').contains('Delete yield').click() but doesn't work. Is there a way to get #1 first, then #2 to reach #3? this is not a real code but something like this. cy.get('.yield-event__date-and-text--container').contains('10kg') cy.get('