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

    fresh-doctor-14925

    12/19/2022, 2:19 PM
    You can also use double quotes or backticks around the string
  • l

    lemon-wall-91819

    12/19/2022, 2:19 PM
    Cheers Liam 🙂
  • h

    happy-dinner-13480

    12/19/2022, 3:32 PM
    I want to test if a toggle is true or not:
    Copy code
    typescript
    if (cy.el('btnSyncCostCenters').children().find('input').should('not.have.attr', 'ng-reflect-model', 'true')) {
        cy.el('btnSyncCostCenters').children().find('input').click();
    }
    > assertexpected not to have attribute ng-reflect-model with the value true, but the value was true if it's true I just want to do nothing though
  • t

    thankful-wire-37848

    12/19/2022, 3:37 PM
    Cypress commands are to be considered somewhat asynchronous and return a "chainer". That should never be used within an if-condition, as it will always return true. Also an assertion throw an error (whether you use
    cy.should(...)
    or
    expect(...).to...
    ) if the condition is not met, and also never return with
    true
    or
    false
    values.
  • g

    gray-kilobyte-89541

    12/19/2022, 3:48 PM
    https://glebbahmutov.com/cypress-examples/9.7.0/recipes/conditional-testing.html
  • l

    little-kitchen-65586

    12/19/2022, 4:07 PM
    I have one problem, I want to make registration and log in after login I want to preserve the cookie to continue the test, I want my user to be logedin
  • g

    gray-kilobyte-89541

    12/19/2022, 4:10 PM
    At https://cypress.tips/search search videos for "preserve cookie"
  • l

    little-kitchen-65586

    12/19/2022, 4:12 PM
    yes, I know that, but I can't use in before, because first, I need to make a registration I can't change describe for this test.I use faker
  • l

    little-kitchen-65586

    12/19/2022, 4:14 PM
    if i put cy.preserveCookieOnce in before test wont start registration
  • h

    hallowed-wolf-18137

    12/20/2022, 2:59 AM
    hello all I just want to ask how can i get the full body response dynamically?
  • b

    bitter-fountain-36713

    12/20/2022, 5:32 AM
    !duplicate
  • n

    nutritious-analyst-96582

    12/20/2022, 5:32 AM
    Uh oh, It looks like you have posted the same question in multiple channels. Help us prevent spam by removing any duplicates of your questions, Thanks! 😀
  • b

    best-lunch-5240

    12/20/2022, 9:27 AM
    Hey guys, I am in a moment to decide the approach of interacting with the backend by http requests to feed the testing environment with the test data or set it in a preconditioned state. I know that cypress has a dedicated method for making http requests - cy.request() but I found this article: https://spin.atomicobject.com/2021/07/30/cypress-tasks-vs-commands/ where it is advised to use cy.task() for interaction with the backend - "If you need to run a promise or interact with your backend, go with a task". So I am a little bit confused. What is best practise here? What would you suggest?
  • h

    happy-dinner-13480

    12/20/2022, 9:43 AM
    ended up with
    Copy code
    typescript
    
    cy.get('[data-cy=btnSyncCostCenters]')
        .children()
        .find('input')
        .then(($toggle) => {
            if (!$toggle[0].attributes.getNamedItem('ng-reflect-model').value) {
                cy.el('btnSyncCostCenters').children().find('input').click();
            }
        });
    which seems to work
  • f

    fresh-doctor-14925

    12/20/2022, 10:36 AM
    Please don't delete and repost your question
  • b

    best-lunch-5240

    12/20/2022, 10:40 AM
    sorry, won't happen again, I think I posted it in wrong channel
  • h

    hallowed-wolf-18137

    12/20/2022, 10:54 AM
    hello. how to handle mltiple select dropdown dynamically?
  • t

    thankful-wire-37848

    12/20/2022, 11:21 AM
    What do you mean by "handle"? Do you mean a regular
    <select multiple>
    because that cannot be a dropdown? Or are you referring to a special component?
  • h

    hallowed-wolf-18137

    12/20/2022, 11:22 AM
    hello @thankful-wire-37848 already fix my problem. thank you
  • f

    fresh-doctor-14925

    12/20/2022, 12:19 PM
    No worries. I think any of the channels were fine, tbh. It's only when something is wildly wrong (eg mounting a react component and asking in the e2e channel), that someone may say you should ask in another channel Most of us on here check all the channels anyhow. Hence why delete and reposting can end up being time consuming for us
  • c

    clean-processor-42509

    12/20/2022, 12:45 PM
    Hi guys, I am using sit.json files to maintain all configurations for each test environment and reading the same file in setupNodeEvents() in cypress.config.js in order to add the values to the config.env. const text = (readFileSync(
    cypress/config/${testEnvironment}.json
    )) const values = JSON.parse(text) config.env = { ...values } Now I have implemented the code to connect the DB. I am passing all the credentials from the sit.json file except the password as I want to pass it from the CLI argument. Since all the DB configuration resides in db object of env obj as shown below, how can we set the password to it which we are passing as CLI arg env:{ baseURL:’XXXXX’, testEnv:’XXXXX’, ClientId:’XXXXX’, db:{host: }
  • p

    powerful-gigabyte-69168

    12/20/2022, 1:36 PM
    I'm having trouble with what I think is a race condition due to issues with promises. Can anyone help me untangle this? This is for a card game web app. We've got a custom command that runs in our
    beforeEach()
    hooks called
    cy.setupGameAsP0()
    and it basically initializes a game by: 1. Making an api request to wipe the database 2. Visiting the app root url 3. Signing up two accounts 4. Creating and joining the game as both players 5. Readying as both players At which point the game launches. This works ~99% of the time but fails with a forbidden error often enough to fail our CI pipeline ~50% of the time across our ~200 tests. I think the issue has something to do with the way cypress handles promises and the fact that our app logic makes api requests using a lib that has callback-style handlers rather than regular promises. Here's the command:
    Copy code
    Cypress.Commands.add('setupGameAsP0', (isRanked = false) => {
      cy.wipeDatabase();
      cy.visit('/');
      cy.signupPlayer(username, validPassword);
      cy.createGamePlayer({ gameName: 'Test Game', isRanked }).then((gameSummary) => {
        cy.window().its('cuttle.app.$store').invoke('dispatch', 'requestSubscribe', gameSummary.gameId);
        cy.log(`Subscribed to game ${gameSummary.gameId}`);
        cy.vueRoute(`/lobby/${gameSummary.gameId}`);
        cy.wrap(gameSummary).as('gameSummary');
        cy.get('[data-cy=ready-button]').click();
        if (!alreadyAuthenticated) {
          cy.signupOpponent(opponentUsername, opponentPassword);
        }
        cy.subscribeOpponent(gameSummary.gameId);
        cy.readyOpponent();
        // Asserting 5 cards in players hand confirms game has loaded
        cy.get('#player-hand-cards .player-card').should('have.length', 5);
      });
    });
    f
    • 2
    • 4
  • s

    strong-football-17493

    12/20/2022, 2:08 PM
    Hi there, I'm struggling to make
    cy.intercept()
    ending the request and then NOT reach the actual endpoint. I'm stubbing via the
    req.reply()
    by returning a staticResponse (json file fixture), there is an aliasing chained to the intercept(). Every time I try, it's always showing the real network call in network tab in console. I'm almost in the same situation as described in this old and fixed issue : https://github.com/cypress-io/cypress/issues/15841#issue-852063225 Thanks in advance & hope someone already faced this and would be able to help me 😅 Cypress version 12.1.0
  • g

    gray-kilobyte-89541

    12/20/2022, 2:50 PM
    I suspect your requests are not being intercepted. Network tab shows a regular network request because browser really sends the request (Cypress intercepts the requests outside the browser). I don't know what you are experiencing since there is not enough detail, but I do have a paid course covering these topics https://cypress.tips/courses/network-testing
  • g

    green-book-63455

    12/20/2022, 2:57 PM
    I am using cypress to test a svelte frontend with a directus backend. I am noticing that things that work manually fail with cypress and can't see why. So if I login as a user, click some links and then click logout, then manually that works with no errors in console.log either. But a script run in cypress gives an error when logout is run. (xhr)POST http://localhost:8055/auth/logout (uncaught exception)NS_ERROR_UNEXPECTED: (new url)http://localhost:3000/ (xhr)POST 400 http://localhost:8055/auth/refresh (xhr)OPTIONS 204 http://localhost:8055/auth/refresh (uncaught exception)Error: "refresh_token" is required in either the JSON payload or Cookie Now I can get round this by setting an uncaught exception but would rather not. Running manually and looking at network in F12, I do not see a 400 return code. Cypress.on('uncaught:exception', (err, runnable) => { // returning false here prevents Cypress from // failing the test return false }) The reason this is now an issue is adding a new user. Again, manually, I register a user, get an alert saying that "Fred Smith is registered". Having cleared out the user and run via cypress I instead get an alert of "Could not create user", which is my catch error. Once again there is a 400 error in the cypress output. Except .... Whilst I was writing this, I also tidied up the alert text in the svelte code (I added user IS registered) and reflected that in cypress code. And now test passes!!! But really, code wise, nothing has changed. The cypress test code is cy.on ('window:alert', (text) => { expect(text).to.contains("Fred Smith is registered"); }) near the start of the text, before entering and completing the registration code. Any ideas?
  • s

    strong-football-17493

    12/20/2022, 2:57 PM
    Hi and thanks for your answer. This is what I implemented so far:
    Copy code
    typescript
      cy.intercept(
        {
          method: 'GET',
          pathname: `/my/endpoint*`,
          query: { q: `${myVar}` },
        },
        (req) => {
          req.reply({ statusCode: 200, fixture: `my-json-file.json` });
        }
      ).as('my-alias');
    The thing is that I also have a monitoring tool (in addition with the console network) which is also showing that network calls are REALLY made. That's why I'm a little bit confused :/ I've found this issue where it seems that this person encountered same issue as I do: https://github.com/cypress-io/cypress/discussions/9320#discussion-37482 (but the callback trick with send() function does not work for me)
  • s

    strong-football-17493

    12/20/2022, 3:36 PM
    Ok so as an update, it actually works indeed. I was misled by network call from browser tabs. The internal monitoring tool is now cleary showing that call is NOT made 😌 Thanks again for your time 🙂
  • p

    plain-elephant-20908

    12/20/2022, 4:31 PM
    Hi here
  • p

    plain-elephant-20908

    12/20/2022, 4:36 PM
    Anyone please help me on passing the cypress command with different arguments? Something like
    npm run cy:open -- --arg1=1 --arg2='arg2'
    Except the options given in the Cypress Command : https://docs.cypress.io/guides/guides/command-line#Commands Reference |`https://github.com/npm/npm/pull/5518`
  • p

    polite-garage-57372

    12/20/2022, 5:00 PM
    I use $npm_config_value in the package.json script. So this example I run
    npm run cy:open --env=uat
1...171172173...192Latest