https://cypress.io logo
Join Discord
Powered by
# e2e-testing
  • l

    lively-balloon-98986

    01/15/2023, 1:27 PM
    thank you, and in case i just want to verify that TAB was opened?
  • g

    green-controller-97889

    01/15/2023, 10:11 PM
    I've got a number of title elements on a page in a random order. I know the text for each title, but I don't know their order. Every title element can contain any title text.
    Copy code
    js
    const titles = [
      "title 0",
      "title 1",
      "title 2",
    ];
    Copy code
    js
        cy.get("[data-cy='subheader']").each((item, index) => {
          cy.wrap(item).should("contain.text", titles[index]);      
        });
    or
    Copy code
    js
      cy
        .get('.todo').should( items => {
    
          expect(items[0]).to.contain.text('wash dishes')
          expect(items[1]).to.contain.text('buy milk')
            
        })
    How can I make this work for any number of elements ?
  • g

    gray-kilobyte-89541

    01/15/2023, 10:37 PM

    https://www.youtube.com/watch?v=KSlJYjIn_AM▾

  • g

    green-controller-97889

    01/15/2023, 11:03 PM
    @gray-kilobyte-89541 thank you. But this examples shows only the first or the last element being questioned. I need to check all of the elements.
  • r

    red-smartphone-84750

    01/15/2023, 11:04 PM
    Hello. How can I intercept an api to return a json file with cypress?
  • g

    gray-kilobyte-89541

    01/15/2023, 11:08 PM
    I would see if you can adapt the example to your needs
  • g

    gray-kilobyte-89541

    01/15/2023, 11:08 PM
    network call? using
    cy.intercept
    see https://on.cypress.io/intercept or my paid cause https://cypress.tips/courses/network-testing
  • g

    green-controller-97889

    01/15/2023, 11:09 PM
    I can only think of using
    .some
    :
    Copy code
    js
    cy.get('.list-item').then(($listItems) => {
      let matched = $listItems.toArray().some((item) => item.textContent.includes('example'));
      expect(matched).to.be.true;
    });
    But if the last title is correct then matched is true, disregarding the iterations before it. I've also tried:
    Copy code
    js
        cy.get("[data-cy='subheader']").should(items => {
          expect((items[0]).to.contain.text(titles[0]))
          expect((items[1]).to.contain.text(titles[1]))
          expect((items[2]).to.contain.text(titles[2]))
        });
    But this returns
    Cannot read properties of undefined (reading 'contain')
  • g

    green-controller-97889

    01/15/2023, 11:21 PM
    @gray-kilobyte-89541 What do you think of the following solution ? Seems to work.
    Copy code
    js
        cy.get("[data-cy='subheader']").each(subheader => {
          cy.wrap(subheader).invoke("text").should("be.oneOf", titles);
        })
  • r

    red-smartphone-84750

    01/15/2023, 11:44 PM
    I am doing this:
    Copy code
    describe("template spec", () => {
      it("test", () => {
        cy.intercept("GET", "http://localhost:3001/countries", {
          fixture: "../../../src/mocks/countries.json",
        });
        cy.visit("http://localhost:3000/");
      });
    });
    That info should populate a dropdown that appear on localhost:3000 form. But I am getting this error.
  • r

    red-smartphone-84750

    01/16/2023, 12:37 AM
    Ok, I found to solved in this way, but I am not clear about:
    Copy code
    const genders = require("../../../src/mocks/genders.json");
    const countries = require("../../../src/mocks/countries.json");
    const jockeys = require("../../../src/mocks/jockeys.json");
    
    describe("template spec", () => {
      beforeEach("before", () => {
        cy.intercept("GET", "http://localhost:3001/genders", {
          body: genders,
        }).as("getGenders");
        cy.intercept("GET", "http://localhost:3001/countries", {
          body: countries,
        }).as("getCountries");
        cy.intercept("GET", "http://localhost:3001/jockeys", {
          body: jockeys,
        }).as("getJockeys");
      });
    
      it("Llenar formulario", () => {
        cy.visit("http://localhost:3000/");
      });
    });
    Using
    require
    . What do you think guys?
  • c

    colossal-table-38461

    01/16/2023, 5:20 AM
    Hello All Good Morning!!! I need help or work-around for 1 scenario. Scenario : I am visiting the URL for Backend Application using cy.visit('/'), after executing the spec file on Runner, I can see URL of Log in Page of Microsoft Online (Microsoft Dynamics 365). But also in Runner it is showing Blank Screen. so No Action is performed in runner side. Can someone help me into this ? Also I tried to get that MicrosoftOnline URL & try to hit that but in that case also nothing is happened. (Also that URL is very huge)
  • b

    broad-analyst-94821

    01/16/2023, 10:26 AM
    Is there a way to configure this globally? I've got a large project, and refactoring all files to add this would not be fun...
  • c

    colossal-mouse-44047

    01/16/2023, 10:37 AM
    Hi. I understand that you can add the setting in the cypress config as well. https://docs.cypress.io/guides/references/configuration#e2e
  • b

    broad-analyst-94821

    01/16/2023, 10:38 AM
    thx just figured it out -- cypress.config.ts > e2e >
    testIsolation:false
  • h

    hallowed-autumn-34625

    01/16/2023, 12:29 PM
    is there any doc/example showing how to use handlebars.js or squirrelly.js with cypress.
  • i

    important-smartphone-8814

    01/16/2023, 2:57 PM
    Hello All, I downloaded my company's project which was created using mac os and I am trying to use it to write on windows I get error running the scripts like "yarn open cypress" can someone help me on this? Thank you much appreciated Error: ENOENT: no such file or directory, open 'C:\Users\win10\Desktop\BuildOps\cypressProjects\buildhero-webapp-tests\.env' at Object.openSync (node:fs:595:3) at Object.readFileSync (node:fs:463:35) at Object.config (C:\Users\win10\Desktop\BuildOps\cypressProjects\buildhero-webapp-tests\node_modules\dotenv\lib\main.js:75:42) at setupNodeEvents (C:\Users\win10\Desktop\BuildOps\cypressProjects\buildhero-webapp-tests\cypress.config.ts:18:50) at C:\Users\win10\AppData\Local\Cypress\Cache\12.3.0\Cypress\resources\app\node_modules\@packages\server\lib\plugins\child\run_plugins.js:118:14 at tryCatcher (C:\Users\win10\AppData\Local\Cypress\Cache\12.3.0\Cypress\resources\app\node_modules\bluebird\js\release\util.js:16:23) at Function.Promise.attempt.Promise.try (C:\Users\win10\AppData\Local\Cypress\Cache\12.3.0\Cypress\resources\app\node_modules\bluebird\js\release\method.js:39:29) at RunPlugins.load
  • g

    gray-kilobyte-89541

    01/16/2023, 3:49 PM
    well, without a reproducible example I cannot say for sure. But I would not use cy.wrap and instead do immediately
    expect
  • g

    gray-kilobyte-89541

    01/16/2023, 3:50 PM
    https://glebbahmutov.com/blog/import-cypress-fixtures/
  • f

    future-glass-89764

    01/16/2023, 4:17 PM
    Hi
  • h

    helpful-truck-53930

    01/16/2023, 4:33 PM
    Hello community, I have a problem with the latest version 12.3.0 of cypress and I get a Webpack Compilation Error. After a migration from old version to the new version of cypress the cypress.json would changed. I the scope of the project i have installed the Ntlm Plugin. Now iam getting this error ( see pic). It's a bit frustrating. I tried some things but it's doest work. Who have a hint for me? Maybe I can't see the wood because of all the trees. Thanks 🙏
  • d

    dazzling-salesclerk-15570

    01/16/2023, 6:34 PM
    Hi all... On CI, what are the best strategies for handling temporarily unavailable environments? eg. 503 errors, specially on an API test suite. Do you hold execution until it's available? Fail the test job?
  • g

    gray-kilobyte-89541

    01/16/2023, 7:26 PM
    I use cypress-recurse to retry
  • m

    modern-dawn-86006

    01/16/2023, 7:37 PM
    hey, did u find a work around? because i am interested in the approach of solving this
  • m

    modern-dawn-86006

    01/16/2023, 7:51 PM
    instead of using first and last, can't you use eq and provide index?
  • m

    modern-dawn-86006

    01/16/2023, 7:52 PM
    if eq works then you can write a for loop and make index iterate, that way you can match all the items
  • m

    modern-dawn-86006

    01/16/2023, 7:54 PM
    Copy code
    cy.get('items').eq(0).invoke('text').should('be.oneOf', ["title 0", "title 1", "title 2"])
  • m

    modern-dawn-86006

    01/16/2023, 7:56 PM
    if this works, you can do this afterwards
    Copy code
    for (let i = 0; i < index; i++) {
      cy.get('items').eq(index).invoke('text').should('be.oneOf', ["title 0", "title 1", "title 2"])
    }
  • m

    modern-dawn-86006

    01/16/2023, 8:36 PM
    @green-controller-97889
  • g

    gray-kilobyte-89541

    01/16/2023, 8:40 PM
    I like your solution
1...188189190191192Latest