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

    kind-minister-59159

    09/10/2021, 6:53 PM
    Then at the beginning of my before each I call cy.clearSiteData()
  • t

    thankful-lunch-80439

    09/10/2021, 6:56 PM
    you dont need yo use
    Cypress.Commands.add
    to have them in the cy obj? @kind-minister-59159
  • k

    kind-minister-59159

    09/10/2021, 6:59 PM
    Yes you do I have those set up at the beginning of my test before I call the functions Cypress.Commands.add('clearSiteData', clearSiteData);
  • t

    thankful-lunch-80439

    09/10/2021, 7:10 PM
    Thank you for your help!!
  • f

    fancy-airplane-60156

    09/13/2021, 12:11 PM
    Hi all, I added lot of reusable functions as commands i commands.js file. I find sometimes it gets really slow when test are executed. I want to off load some of these functions to a different file. Please can you suggest any ideas.
  • i

    important-river-75795

    09/13/2021, 1:40 PM
    Use normal javascript functions?
  • f

    future-gold-77198

    09/13/2021, 9:19 PM
    Can anyone point me to a good comparison between Micoo and Visual Regression Tracker for visual regression testing? Google seems to be coming up pretty empty handed. Or if anyone has tips from experience using either, I'd appreciate that.
  • f

    fancy-airplane-60156

    09/14/2021, 4:53 AM
    I was thinking of the same. Probably that's the best idea that I can go with. Thanks.
  • t

    thankful-lunch-80439

    09/14/2021, 3:54 PM
    Can someone explain working with the
    Cypress.LocalStorage.clear
    ? For example, I want a certain local storage item to persist through the tests. How can I do that?
  • f

    future-gold-77198

    09/14/2021, 4:09 PM
    Have you read about the newer Session API? It might satisfy your needs the most directly and nicely. But if you also mention your use case, people might be able to help you more. So if not login related, you might start here. https://stackoverflow.com/questions/50471047/preserve-cookies-localstorage-session-across-tests-in-cypress I used essentially the code from bkucera in the thread, but I didn't do anything with the keys or any arguments, so the code causes ALL local storage items to persist. And it worked so I wouldn't have to login again. I did this until I implemented the Session API in its place. So I think the code you mentioned earlier looked kosher to me, but if that didn't work for you, I would wonder why. Here is the exact code that used to work for me:
    (Cypress as any).LocalStorage.clear = (keys, ls, rs) => {};
  • t

    thankful-lunch-80439

    09/14/2021, 7:30 PM
    And that's what's tricky! I only need 1 thing from local storage to stay
  • t

    thankful-lunch-80439

    09/14/2021, 7:30 PM
    And i noticed the Session API though I don't want to try a newer feature yet 🙂
  • t

    thankful-lunch-80439

    09/14/2021, 7:31 PM
    Basically I log in, get my JWT token, and the session doesn't persist between tests reloads since i'm using SSR O_O
  • t

    thankful-lunch-80439

    09/14/2021, 7:31 PM
    (ikr, super basic and simpile...really practicing KISS)
  • f

    future-gold-77198

    09/14/2021, 7:45 PM
    If your goal really is just to persist login state, I would reconsider using the Session API. It was simpler than I expected when I first tried it and I haven't had any problems with it for over a month. Used it in CI and locally, and we even have a rather unusual use case in that we login with Playwright, pass the cookies and LS to Cypress, and load it into the cypress owned browser. Yet it all still just works with the Session API. But if not, I think the keys are the names of the LS items. So perhaps going with what bkucera posted even more closely, I think you could to it. I think part of this might be kind of psuedo code already. I would guess that'keys' would be an array and so you might .forEach it and compare each key to the one you are looking for, and in every case but that one, use clear, else do nothing (not clear). Hopefully someone with more experience will come along and make even more certain on exactly what to do...
    Copy code
    const clear = Cypress.LocalStorage.clear
    
    Cypress.LocalStorage.clear = function (keys, ls, rs) {
      // Go through all keys and Identify which key to not clear in the condition
      if (keys) {
        return clear.apply(this, arguments)
      }
    
    }
  • t

    thankful-lunch-80439

    09/14/2021, 8:13 PM
    🤔 tricky ticket. I may have to dig into that Session API what I see above is also problematic. I think it's a good thing Cypress clears localStorage between tests, and I just don't want to do it in a certain context
  • f

    future-gold-77198

    09/14/2021, 8:22 PM
    I think it can depend a lot on your app, if it doesn't even use local storage, it may not matter much. But from what I understand, this is exactly what that API is designed for, clearing everything except what matters for login state so as to not waste time with that aspect, yet not lose anything about 'starting from a clean slate'. Aim is to handle it all very neatly and consistently as well.
  • q

    quick-gpu-68223

    09/14/2021, 8:37 PM
    Hey team quick questions for you. I would like to run a one time command before all other cypress test. What would you suggest me to do to achieve that ?
  • q

    quick-gpu-68223

    09/14/2021, 8:38 PM
    I was thinking about adding a higher level test. But as the tests are async and we want to keep that. I dont find something that match my need here
  • q

    quick-gpu-68223

    09/14/2021, 8:38 PM
    and the before hook is for the file root
  • q

    quick-gpu-68223

    09/14/2021, 8:40 PM
    actually plugins looks what i am looking for
  • q

    quick-gpu-68223

    09/14/2021, 8:59 PM
    Then having another question we can't use cy. inside those plugins ?
  • f

    fancy-airplane-60156

    09/15/2021, 9:48 AM
    Hi Team, at the end of my test, I'm verifying multiple values to see if they're correct captured in the form. I'm using expect statements. I realized if one expect fails, rest will not execute.All these verifications are part of a single test case. So I can't really seperate them. Is there an alternative ? Has someone tried soft assertions ? I looked up a lot, i could find only this option. Please help
  • f

    fancy-airplane-60156

    09/15/2021, 9:49 AM
    I think you can use Task. I'm using task to login using Playwright plugin and then running the tests (it statements) after that.
  • f

    fancy-airplane-60156

    09/15/2021, 11:58 AM
    @User @User It'd be immensely helpful if you can help me with my query
  • g

    gray-kilobyte-89541

    09/15/2021, 12:18 PM
    can you give an actual example? With code and a form you are trying to assert? There is no going to be soft assertions in Cypress
  • f

    fancy-airplane-60156

    09/15/2021, 12:33 PM
    verifyRoledetails(testobject){ cy.contains('h3','Role details').nextUntil('button') .should(($roledetails)=> { expect($roledetails.children('label').get(0).innerText).to.eq('Role title'); expect($roledetails.children('p').get(0).innerText).to.eq(testobject.role_details.title); expect($roledetails.children('label').get(1).innerText).to.eq('Where is the role based'); expect($roledetails.children('p').get(1).innerText).to.eq(testobject.role_details.role_basedat); }) }
  • f

    fancy-airplane-60156

    09/15/2021, 12:35 PM
    User selects couple of fields, radio buttons and enters text in few fields, verifies them on the final screen before submitting the request.
  • f

    fancy-airplane-60156

    09/15/2021, 12:35 PM
    testobject is the JSON object that contains users inputs. I'm comparing the user inputs with the ones presented on the screen.
  • f

    fancy-airplane-60156

    09/15/2021, 12:39 PM
    There are 8 such input fields, so there will be 16 such expect statements. Test case is a fail even if 1 expect fails or 10 . However I would like all the expects to execute before marking the test case as pass or fail.
1...222324...192Latest