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

    tall-thailand-5343

    12/10/2021, 11:06 AM
    Hey, perhaps a simple one for some, storing clipboard text to context, what am I doing wrong?
    Copy code
    cy.window()
              .its("navigator.clipboard")
              .invoke("readText") // !! this sometimes fails, so a FLAKY TEST ???
              .as("authBearer") // this is not available in this.authBearer in next it() test
              .should("contain", "Bearer ");
    // this passes sometimes actually Another way to write it is:
    Copy code
    cy.window().then((win) => {
              win.navigator.clipboard.readText().then((auth) => {
                auth.should("contain", "Bearer "); // HOW TO DO THIS? + use as "authBearer" so it can be used in the next it() test
              });
            });
    When running headless there's additional error: "Error: Browser context management is not supported.". Totally lost on this now. any help appreciated!
  • f

    freezing-needle-5178

    12/13/2021, 6:52 PM
    Does anyone have a "best practice" for testing an application that has a magic-link based authentication flow? In order to log in without cookies, a user of my application needs to request a link be sent to their email. I've got a cypress test that makes sure that works, and it saves the resulting state in
    cy.session()
    , but then when the next spec test runs, it doesn't have access to any of that state. Am I supposed to send an email for every spec test? Or do I need to use both
    cy.session()
    and somehow also persist a cookie between specs? Has anyone dealt with this before?
  • g

    gray-kilobyte-89541

    12/13/2021, 9:09 PM
    you could use cy.dataSession from the plugin https://github.com/bahmutov/cypress-data-session
  • f

    freezing-needle-5178

    12/13/2021, 9:11 PM
    Thanks. I am trying it out right now. It seems quite different from
    cy.session()
    , however. I don't understand why some kind of solution isn't built into cypress itself.
  • g

    gray-kilobyte-89541

    12/13/2021, 9:12 PM
    well, it is up to the Cypress team to incorporate the solution, but they in general suggest storing any long term data as a closure variable in the spec or in the plugin file process, see https://github.com/cypress-io/cypress-example-recipes/tree/master/examples/server-communication__pass-value-between-specs - cy.dataSession just implements it all for you to make it simpler
  • f

    freezing-needle-5178

    12/13/2021, 9:14 PM
    Yes, but they created
    cy.session()
    to help store session state and automatically reset all other browser state between tests, so it seems perfect for keeping auth state, except it only works in a single spec file.
  • g

    gray-kilobyte-89541

    12/13/2021, 9:16 PM
    well, not everyone can foresee the use cases like I can 😛
  • g

    gray-kilobyte-89541

    12/13/2021, 9:17 PM
    In any case @User I did not test magic email links myself, but I did some email testing using Cypress, here is a presentation https://slides.com/bahmutov/email-testing
  • f

    freezing-needle-5178

    12/13/2021, 9:20 PM
    So far I'm using mailinator to check real emails, and that part is working okay mostly, but I just don't want to send a new email for every single spec. 😵
  • g

    gray-kilobyte-89541

    12/14/2021, 12:51 AM
    you could also get the email link before running any tests, like using
    before:run
    plugin event and store the data and share it with each spec
  • n

    narrow-optician-44716

    12/14/2021, 4:59 PM
    hi there, i'm a dev working on a web app project and am receiving negative feedback about the end-to-end tests i authored. i would appreciate this community's impressions about the point being made so i could address it from a more educated perspective. the whole system i'm working on is composed of one single web app and 5 backend services. the web component has about 11k lines of code. additionally, to the front-end coding, i've developed the end-to-end tests using cypress -- an exceptional tool, btw. the tests are distributed through 27 spec files and total up to 86 individual test cases. on my machine (i5 - 8gb ram - 512gb sdd disk) those tests take around 40min to run. the tests are executed voluntarily by devs when they feel like it (e.g. before pushing to the git remote repo). the tests are not part of our ci/cd pipelines. i'm getting this negative feedback about the tests: they take too long. since i'm new to the subject, i would be very grateful if anyone could share their point of view based on your experience with end-to-end testing: - is 40min too long for this scenario? - what criteria one would use to judge if an e2e tests suite is taking too long? - what is a reasonable threshold for the e2e suite total time? stay healthy, jm
  • g

    gray-kilobyte-89541

    12/14/2021, 6:10 PM
    Yes, 40 minutes is an eternity. I would consider 10 minutes on CI to be the absolute limit, and 5 minutes something to strive for. Locally, the dev should only run the test that they are working with. The CI should run all the tests. Here it a trick: configure your CI to run the changed specs first, before running all the tests, that would speed things up and provide meaningful fast feedback https://glebbahmutov.com/blog/faster-ci-feedback-on-circleci/
  • d

    dazzling-salesclerk-15570

    12/14/2021, 6:40 PM
    Hey guys, im facing some issues regarding writing some utils inside the plugins file. I need to return the promises as fast as possible, and they are generally filtering functions which run async, doing some requests to an API when more data is needed. I intended to use Bluebird Promise.any method so that I could get the first one that resolves, and for this filtering function, it would only resolve when the final conditional (after about 7-10 other conditionals) is passed. If any one of the previous one fails, it should reject, so using any I would be able to use the one that resolve most quickly. But doing this crashes the plugins file if any of the data I retrieve fails in the filter. Does anyone knows a workaround of a better way to do this?? Limiting the concurrency would also be good, but I don't know of any lib that works with other Promise methos other than Promise.all
  • f

    freezing-needle-5178

    12/14/2021, 7:30 PM
    Do you have any suggestions about https://github.com/bahmutov/cypress-data-session/issues/34? Does my approach there seem reasonable, or is there something simpler I could do?
  • n

    narrow-optician-44716

    12/14/2021, 8:16 PM
    that's very informative, thank you! do you think is a matter of too much test cases (27 specs with 86 test cases for a web app of 11k l.o.c) or that test cases are taking too long (40min / 86 tc = 28s per test case)?
  • f

    freezing-needle-5178

    12/14/2021, 8:39 PM
    I'm by no means an expert, but 28s per test case seems really long.
  • g

    gray-kilobyte-89541

    12/14/2021, 8:50 PM
    no, I think it is fine - but you need to understand where the test is spending its time, maybe there is an opportunity to optimize is
  • f

    fast-cpu-20763

    12/15/2021, 5:16 AM
    Hello everyone, the website under test breaks while running with Cypress while the same works perfectly otherwise. For instance, the cart is shown empty, add to cart is not functional, etc. Can Cypress break website functionality?
  • i

    important-river-75795

    12/15/2021, 9:21 AM
    Haven't had such experience yet, maybe you are intercepting and changing some requests you might not want to? E.g. Intercepting all post requests and changing something in them , so now the add to cart requests are sent wrong and then it doesn't work?
  • f

    future-gold-77198

    12/15/2021, 8:11 PM
    I'm trying to login in a beforeEach at one domain, then go do a different domain in a test, but I still get this error. Could this have to do with the newer experimental Session API, or is a beforeEach always considered part of the same test for every 'it' block?
  • f

    future-gold-77198

    12/15/2021, 8:13 PM
    The other side of the problem is that my team feels these URLs should be of the same origin, or that is the intent. So we don't understand why they aren't, if they even really are not. If anyone has had experience like this with azure hosting and can advise, that'd be great.
  • f

    future-gold-77198

    12/15/2021, 11:06 PM
    I suspect the beforeEach/Login code as when I comment that out and then visit two different super domains in two tests, it behaves as expected.
  • b

    brief-quill-91989

    12/20/2021, 4:47 AM
    Hi all, how to handle Browser permissions like camera, microphone access? Note: tried with browser launch options from plugins/index.js file and 3rd party module https://github.com/kamranayub/cypress-browser-permissions but not working, anyone faced the same issue?
  • c

    clean-london-79739

    12/20/2021, 8:32 AM
    does anybody have problems with cypress not picking up recent changes from spec file? https://github.com/cypress-io/cypress/issues/19423
  • b

    bored-church-78777

    12/20/2021, 10:34 PM
    Hi. I am trying to make a call to fixture, run a few tests and then make a second call to the same fixture, but the second call never takes place. I am wondering what I am doing wrong. This is just sample code illustrate what I am trying to do. Any help would be greatly appreciated. Thanks.
    Copy code
    describe('and the api will respond with data', () => {
      before(() => {
        cy.intercept('POST', 'test', {
          fixture: 'response',
        }).as('response');
      });
    
      describe('first call', () => {
        it('should show data', () => {
          cy.wait('@response');
          cy.get('[data-edit]').contains('word');
        });
      });
    
      describe('second call', () => {
        it('should show data', () => {
          cy.wait('@response');
          cy.get('[data-edit]').contains('word');
        });
      });
    });
  • g

    gray-kilobyte-89541

    12/20/2021, 11:21 PM
    all intercepts are reset before each test, so you intercept is done using
    before
    that runs only before the first test, and does not exist before the second test
  • b

    bored-church-78777

    12/20/2021, 11:25 PM
    Thanks @User for your response. That's what I thought, so I also tried this. This is not exactly my code and
    beforeEach
    would not work for me.
    Copy code
    describe('and the api will respond with data', () => {
      before(() => {
        cy.intercept('POST', 'test', {
          fixture: 'response',
        }).as('response');
      });
    
      describe('first call', () => {
        it('should show data', () => {
          cy.wait('@response');
          cy.get('[data-edit]').contains('word');
        });
      });
    
      describe('second call', () => {
        before(() => {
          cy.intercept('POST', 'test', {
            fixture: 'response',
          }).as('response');
        });
    
        describe('second call', () => {
          it('should show data', () => {
            cy.wait('@response');
            cy.get('[data-edit]').contains('word');
          });
        });
      });
    });
  • g

    gray-kilobyte-89541

    12/21/2021, 12:11 AM
    you are not showing the full code - for example, what is making the request? There is no visit in the code you pasted. What is the error?
  • b

    broad-potato-69393

    12/21/2021, 4:27 AM
    @User is there a way to load both feature style and spec style tests at the same time? if I remove the check for files ending in 'js' (meaning they don't come up in the lsit of tests), then I can run the feature test. If I have 'js' in there, it says it cannot detects tests in my Feature file spec implementation NOTE: I am using the cypress cucumber preprocessor for my .feature files
  • g

    gray-kilobyte-89541

    12/21/2021, 4:09 PM
    testFiles: ["**/*.feature", "**/*.features", "**/*.js"]
    is your friend
1...282930...192Latest