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

    fresh-doctor-14925

    06/08/2022, 6:26 PM
    Would you mind sharing your solution? Questions tend to come up more than once on here
  • r

    red-toddler-79937

    06/08/2022, 6:27 PM
    for which one? i fixed two questions i asked here today
  • f

    fresh-doctor-14925

    06/08/2022, 6:30 PM
    In that case, both Remember this is largely run by volunteers so you won’t get answers straight away. It’s great that you figured out your problems. Maybe pay it forward and help the next person who encounters the issue?
  • r

    red-toddler-79937

    06/08/2022, 6:43 PM
    ```js
  • r

    red-toddler-79937

    06/08/2022, 6:44 PM
    Does anyone know how we can change the
  • r

    red-toddler-79937

    06/08/2022, 6:44 PM
    Hey, sure. I mean people can just ping me if they wanted to know. Like you did.
  • r

    red-toddler-79937

    06/08/2022, 6:51 PM
    Copy code
    ts
    describe('Initialization', () => {
      it('Should change viewport to desktop resolution', () => {
        initializeDesktopV2();
      });
      it('Should load the page', () => {
        cy.visitPage('/', 'landing-page');
      });
    });
    Hey is this the proper way to write this? Basically what I want is some code that applies for ALL tests in the CURRENTLY TESTED file.
  • r

    red-toddler-79937

    06/08/2022, 6:52 PM
    I cannot use
    before
    or
    beforeEach
    because it requires at least 1 test for it to work. I can put it inside a
    describe
    block where
    it
    is used but then it it doesn't really belong to all tests in the file.
  • r

    red-toddler-79937

    06/08/2022, 6:52 PM
    hope my explanation & reasoning makes sense. I hope there is a better way to do this though
  • f

    fresh-doctor-14925

    06/08/2022, 8:54 PM
    It's a bit of an anti pattern as you've got dependencies between tests. Why not use
    context()
    instead?
  • r

    red-toddler-79937

    06/08/2022, 8:56 PM
    What do you mean? Context is just an arbitrary name no?
  • f

    fresh-doctor-14925

    06/08/2022, 9:20 PM
    Yes, but
    it()
    is normally used for when you’re actually performing steps to test something. But you’re using an
    it()
    to perform setup for the second scenario, no?
  • r

    red-toddler-79937

    06/08/2022, 9:21 PM
    I edited my snippet, cuz it was a bit outdated. Well I am not allowed to use anything other than
    it
  • r

    red-toddler-79937

    06/08/2022, 9:22 PM
    "It should load the page"
  • r

    red-toddler-79937

    06/08/2022, 9:22 PM
    But anyway, I need to set some initial values for all my tests. What is the best way to go about that regardless of the naming?
  • f

    fresh-doctor-14925

    06/08/2022, 9:52 PM
    beforeEach()
  • r

    red-toddler-79937

    06/08/2022, 9:52 PM
    i dont need to load the page on each test
  • f

    fresh-doctor-14925

    06/08/2022, 9:53 PM
    Ok, but you can set the initial values in the
    beforeEach()
  • r

    red-toddler-79937

    06/08/2022, 9:54 PM
    Well yeah I know but did you see this:
  • f

    fresh-doctor-14925

    06/08/2022, 9:55 PM
    This doesn’t really make sense. If you have a test with an
    it()
    block, you can have a
    beforeEach()
  • r

    red-toddler-79937

    06/08/2022, 9:56 PM
    I know but did u also see this:
  • r

    red-toddler-79937

    06/08/2022, 9:56 PM
    I can put my init values in the before() but I want it to be applied for the entire scope of the test file, not just one testing block
  • f

    fresh-doctor-14925

    06/08/2022, 9:59 PM
    That’s not really how cypress works. As Cypress runs in the browser, a lot of the context is wiped between
    it()
    blocks, so setup steps, aliases, etc, are best placed in a
    beforeEach()
    .
  • r

    red-toddler-79937

    06/08/2022, 10:00 PM
    i mean the code already works. im still confused
  • f

    fresh-doctor-14925

    06/08/2022, 10:21 PM
    Well, your initial question was if your way was the ‘proper’ way, and I don’t believe it is. The self-imposed constraints you have around
    before
    and `beforeEach`seem unnecessary to me. There’s my thoughts on the matter. I can’t offer more than that
  • a

    adamant-beard-17074

    06/08/2022, 10:25 PM
    Thank you !
  • f

    future-vr-59131

    06/08/2022, 10:56 PM
    In that case you can write some code in before() that checks if the prerequisites (aka your testdata) is already loaded or not (by adding some boolean somewhere for example). So it will run only the first time.
  • c

    chilly-queen-22182

    06/09/2022, 12:02 AM
    Hi guys, I need help for component testing aurelia app, Is there any documentation or sample for Aurelia component testing, please guide me . Thanks
  • f

    fresh-church-72513

    06/09/2022, 12:13 AM
    i'm getting this error when migrating to version 10, can someone help me with this.
  • g

    gray-kilobyte-89541

    06/09/2022, 12:43 AM
    you can use cypress-data-session to do this. You would put it inside
    beforeEach
    but the data is cached and only initialized once (and can be recomputed if needed)
1...495051...192Latest