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

    refined-shampoo-94690

    08/02/2022, 2:09 PM
    Hey guys, I've been banging my head in the wall with
    cy.origin
    . My use case would be to iterate through several URLs in a JSON, visit each site and do the tests.
    Copy code
    const clients = {
        "urls": [
            {
                "siteurl": "http://google.com,
                "subpage": "/"
            },
            {
                "siteurl": "http://youtube.com,
                "subpage": "/"
            }
        ]
      };
    
      // cy.visit('/')
      it('tests', () => {
        clients.urls.forEach( client => {
      
          cy.origin(client.siteurl, () => {
            cy.visit(client.subpage);
            cy.get("body");  
          })
    
        });
      });
    According to the Docs, you cannot directly pass variables into the
    cy.origin
    but is there any way of passing a url to it?
  • r

    red-toddler-79937

    08/02/2022, 7:41 PM
    Hi, I have this code:
    cy.get('@toggle').get('input').should('have.attr', 'aria-checked').and('match', /false/);
    but when I type "/false" it actually passes. But when I type random stuff like "sdifgjhsdifhjsdfse" it fails as expected. Why is that?
  • r

    red-toddler-79937

    08/02/2022, 7:42 PM
    I also tried
    Copy code
    cy.get('@toggle').get('input').should('have.attr', 'aria-checked', 'true')
    , that works. But when I type 'false' it also passes. And then when I type random data it fails as expected.
  • g

    gray-kilobyte-89541

    08/02/2022, 7:59 PM
    what is the HTML markup of the input element you are trying to check?
  • r

    red-toddler-79937

    08/02/2022, 8:00 PM
    i already fixed it 😄
  • r

    red-toddler-79937

    08/02/2022, 8:00 PM
    no need anymore
  • b

    brainy-librarian-80110

    08/03/2022, 3:48 AM
    Hellow everyone
  • b

    brainy-librarian-80110

    08/03/2022, 3:48 AM
    I need your help...I am facing one issue in cypress
  • b

    brainy-librarian-80110

    08/03/2022, 3:49 AM
    I am trying to login into SAP Fiori launchpad based library but cypress is giving error and not allowing me to redirect on the application home page
  • b

    brainy-librarian-80110

    08/03/2022, 3:50 AM
    I have attached screenshot of the issue so can anyone please help me out with this?
  • s

    stale-optician-85950

    08/03/2022, 7:26 AM
    You were missing the args parameters https://docs.cypress.io/api/commands/origin#Usage
    Copy code
    describe('helping', () => {
      const clients = {
        urls: [
          {
            siteurl: 'https://www.acme.com',
            subpage: '/updates/',
          },
          {
            siteurl: 'https://www.google.co.uk',
            subpage: '/search?q=cypress+io',
          },
        ],
      };
    
      it('tests', () => {
        clients.urls.forEach(client => {
          cy.origin(client.siteurl, { args: { client } }, ({ client }) => {
            cy.visit(client.subpage);
          });
        })
      });
    });
  • r

    refined-shampoo-94690

    08/03/2022, 7:41 AM
    Yeah that made it 💪 feels just like a weird syntax. I already generated 300 lines of harcoded testing script but this will clean it up quite a bit 🙂 Thanks!
  • b

    billions-lizard-8925

    08/03/2022, 10:09 AM
    Hi, is there a way to bypass the {force:true} in click({force:true}), with a Promise for example, to only have a simple click() ?. For example, i created this command to force a click() event with a Promise via then.... Sometimes it works, somoetimes no. Thanks :). Cypress.Commands.add('forceClickOnTab', (tab, selector) => { cy.getBySel(selector) .should('be.visible') .invoke('attr', 'href') .should('include', tab) .then(($el) => { cy.wrap($el) .invoke('click') .then(() => { $el.click() }) }) })
  • f

    flaky-airport-12178

    08/03/2022, 10:16 AM
    Hi team
  • f

    flaky-airport-12178

    08/03/2022, 10:17 AM
    Do you know to get all css attribute of element: return array (key:value)?
  • w

    wide-hospital-71307

    08/03/2022, 11:07 AM
    it seems that stuff from helper files, like vars, are not regenerated when a retry occurs. Is there any way to do that?
    • 1
    • 3
  • g

    gray-kilobyte-89541

    08/03/2022, 1:31 PM
    you can call
    window.getComputedStyles
    to get all of them. For more, search https://glebbahmutov.com/cypress-examples
  • f

    flaky-airport-12178

    08/03/2022, 3:47 PM
    Many thanka
  • g

    glamorous-country-57678

    08/03/2022, 7:07 PM
    Hi all, I am e2e testing and want to mock server requests using cy.intercept(). I am confused as to why the CommandLog displays the route *not stubbed. Here is the test:
    Copy code
    describe('visit and interact with home page', () => {
        beforeEach(() => {
            cy.intercept('GET', 'http://localhost:3001/api/post?*').as('getPosts')
        })
    
        it('visit homepage', () => {
            cy.visit('/')
        })
    })
    And here is what the CommandLog displays:
  • c

    chilly-magician-64042

    08/03/2022, 7:24 PM
    example: > beforeEach(() => { > cy.intercept('GET', 'http://localhost:3001/api/post?').as('getPosts') > cy.visit('/') > cy.wait('@getPosts') > }) > you must wait for this intercept https://docs.cypress.io/api/commands/intercept#Aliasing-individual-requests
  • c

    chilly-magician-64042

    08/03/2022, 7:26 PM
    @glamorous-country-57678 https://egghead.io/blog/intercepting-network-requests-in-cypress
  • g

    glamorous-country-57678

    08/03/2022, 7:45 PM
    @chilly-magician-64042 thx for the response. I am trying a different implementation with cy.wait() but still receiving errors. Here is the code I have with the CommandLog.
    Copy code
    describe('visit and interact with home page', () => {
        beforeEach(() => {
            cy.intercept('GET', 'http://localhost:3001/api/*').as('getApi')
        })
    
        it('visit and interact with home page', () => {
            cy.visit('/')
            cy.wait('@getApi')
        })
    })
  • c

    chilly-magician-64042

    08/03/2022, 7:56 PM
    @glamorous-country-57678 put your visit and wait in beforeEach and its worked
  • c

    chilly-magician-64042

    08/03/2022, 7:56 PM
    or put your intercept in your it
  • g

    gray-kilobyte-89541

    08/03/2022, 7:58 PM
    you are only spying on the intercept, you are not mocking it. Cypress network requests guide is your best bet, and if you want to learn more, get my course "Cypress Network Testing Exercises" https://cypress.tips/courses
  • g

    glamorous-country-57678

    08/03/2022, 8:14 PM
    This still does not work, maybe for the reason @gray-kilobyte-89541 mentioned ?
  • c

    chilly-magician-64042

    08/03/2022, 8:16 PM
    @glamorous-country-57678 my intercept calls are all in their it functions
  • g

    glamorous-country-57678

    08/03/2022, 8:18 PM
    Yes I moved the intercept in the it
  • f

    fierce-lion-2381

    08/04/2022, 10:51 AM
    Hey everyone is there any way in cypress not to repeat passing the header authorization token in every single test ( create something like default header )
  • g

    glamorous-country-57678

    08/04/2022, 7:55 PM
    So it looks like @gray-kilobyte-89541 was correct in pointed out I was only spying on the url and not stubbing the response. And thanks for the course: @gray-kilobyte-89541 , I went through everything and it has some good content. I now have this code which does not seem to need the
    cy.wait()
    command I was using in an earlier implementation: `describe('visit and interact with home page', () => { const apiURL =
    ${Cypress.env('apiUrl')}
    it('visit and interact with home page', () => { cy.intercept('GET',
    ${apiURL}/*
    , { statusCode: 200, body: { data: { id: '1', }, }, }).as('getApi') cy.intercept('POST',
    http://localhost:8545*
    , { statusCode: 200, body: { data: { id: '1', }, }, }).as('post8545') // cy.wait('@getApi') cy.visit('/') }) })` Still refactoring this, but the test is passing and the routes display that they are stubbed like they should.
1...767778...192Latest