https://cypress.io logo
Join Discord
Powered by
# help
  • m

    magnificent-finland-58048

    04/25/2022, 4:50 PM
    it's 10 bonus lessons already! 😄 I gotta catch up a 3rd time
  • g

    gray-kilobyte-89541

    04/25/2022, 5:55 PM
    I know! I almost have 11th too, too many good ideas to stop making new lessons. I wonder if the bonus list will grow longer than the original list
  • m

    magnificent-finland-58048

    04/25/2022, 10:04 PM
    I don't mind free content 😄 but you should consider new classes at some point
  • l

    lemon-kite-81269

    04/25/2022, 11:11 PM
    Can someone recommend any Cypress course with e2e testing on real time project
  • a

    adorable-smartphone-87280

    04/26/2022, 3:07 AM
    what do you mean by "real time"?
  • g

    green-ram-11259

    04/26/2022, 9:39 AM
    Hey! I'm testing an application that uses camera input and gives AI responses to series of images. I used this solution for fake video https://docs.cypress.io/api/plugins/browser-launch-api#Use-fake-video-for-webcam-testing but I was wondering is there a way to use multiple videos exactly where needed?
  • g

    great-journalist-58601

    04/26/2022, 12:51 PM
    Hi guys. I am using the option --no-exit with cypress run , and when closing the browser after a test finishes the cypress process never finishes . Is that expected ? Is there a way to make cypress exit properly so other tests can run ? (9.2.0 version)
  • s

    some-salesclerk-23018

    04/26/2022, 1:25 PM
    Hi guys, I'm trying to use the new cy.origin() and having some trouble. In my test I need to click a button, and the button will do some complicated work and lead to the new domain. Is cy.origin() suitable for this case? I tried to add it but couldn't find the right timing to use it, test fails right after the button is clicked. I wonder if anyone can help with it, thanks!
  • a

    adorable-smartphone-87280

    04/26/2022, 2:47 PM
    Can you share some example code of what you're trying to do?
    c
    s
    • 3
    • 2
  • g

    gray-kilobyte-89541

    04/26/2022, 2:48 PM
    Hey, I lied, I published the solution to the rendered font as my blog post (which is #200 Cypress blog post on my personal blog, huzza) here https://glebbahmutov.com/blog/rendered-font/
  • a

    able-monkey-72947

    04/26/2022, 2:57 PM
    Hey everyone, I'm super excited to find out today that there is a Cypress Discord! Anyways, I'm pretty stuck on this
    cy
    command I'm trying to write, I'm consistently running into this error -
    Copy code
    Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.
    
    Because Cypress commands are already promise-like, you don't need to wrap them or return your own promise.
    
    Cypress will resolve your command with whatever the final Cypress command yields.
    The code triggering this looks something like this -
    Copy code
    cy.intercept({ method: method, url: url, ...cyRequestOptions }, request => {
              request.continue(response => {
                cy.log('Recording response...')
                cy.writeFile(filePath, response)
              })
            }
    I am trying to record the
    response
    here so that it can be replayed during CI/CD testing, but Cypress is unhappy that I'm trying to
    cy.anything
    inside of
    cy.intercept
    . Is there some use of
    .then
    I'm not thinking of that will solve my issue here?
  • g

    gray-kilobyte-89541

    04/26/2022, 3:21 PM
    you cannot use cy commands inside the intercept callback
  • a

    able-monkey-72947

    04/26/2022, 3:27 PM
    I didn't know that until this error message educated me. Is there another way you can think of to do this? This idea is to intercept the request and determine if we've saved that response to a file. If it has not been saved we want to save it, if it has already been saved we want to give that response in place of what the network would reply with.
  • g

    gray-kilobyte-89541

    04/26/2022, 3:56 PM
    I will need to think about it
  • a

    able-monkey-72947

    04/26/2022, 3:59 PM
    Thanks for taking time to think about this!
  • i

    icy-exabyte-68383

    04/26/2022, 4:45 PM
    Hello, I´ve added Cypress to my trusted applications on Kaspersky, but still everytime cypress opens the browser, kaspersky blocks it fully. "Certificate chain isn´t complete". anyone encountered this problem?
  • a

    able-monkey-72947

    04/26/2022, 7:20 PM
    Copy code
    on('task', {
        doesSavedMockExist(filename) {
          if (fs.existsSync(filename)) {
            return {
              exists: true,
              mock: fs.readFileSync(filename, { encoding: 'utf8' }),
              save: null
            }
          } else {
            return {
              exists: false,
              mock: null,
              save: (path, data) => fs.writeFileSync(path, data, { encoding: 'utf8' })
            }
          }
        }
      })
    I'm curious why I'm not able to pass a function to
    save
    in my
    else
    block here... when I get into that code path I only get
    {exists: false, mock: null}
    , I'm not seeing any reason in the docs why this should be the case?
  • s

    some-salesclerk-23018

    04/26/2022, 11:41 PM
    Can you share some example code of what
  • s

    some-salesclerk-23018

    04/27/2022, 12:00 AM
    Oh maybe I shouldn't start the thread. Sorry about that 🙇‍♀️
  • s

    some-salesclerk-23018

    04/27/2022, 12:00 AM
    Hi Awesame! This is what I'm trying to do:
    Copy code
    /**
     * (under domain 1)
     * cy.findByRole('button', { name: 'example' }).click();
     *
     * (the button is doing something complicated)
     *
     * (now we are under domain 2)
     * cy.get('#example').should('be.visible')
     */
  • a

    adorable-smartphone-87280

    04/27/2022, 12:46 AM
    Have you read this blog post with notes on the feature? https://cypress.io/blog/2022/04/25/cypress-9-6-0-easily-test-multi-domain-workflows-with-cy-origin/
  • s

    some-salesclerk-23018

    04/27/2022, 12:48 AM
    Yes I did, and I couldn't make it work since it is not simply visiting a different domain by url.
  • a

    adorable-smartphone-87280

    04/27/2022, 12:51 AM
    so the button click causes a page redirect to occur?
  • a

    adorable-smartphone-87280

    04/27/2022, 12:52 AM
    ^^ this use case might not be supported by the
    .origin
    feature. I think it's intended to do things like open a login page to get a cookie and then return to another context/page. I'm not sure that a page redirect that happens from the app itself would be supported by Cypress still.
  • s

    some-salesclerk-23018

    04/27/2022, 1:23 AM
    I see, thanks! Hope Cypress can cover this part in the future ❤️
  • a

    adorable-smartphone-87280

    04/27/2022, 1:23 AM
    I think it's unlikely to ever support that. Pretty sure it's a CORS thing.
  • s

    some-salesclerk-23018

    04/27/2022, 1:26 AM
    Will try to find other ways then. Thanks
  • a

    able-monkey-72947

    04/27/2022, 6:47 PM
    It took some hours, but I figured this out and wanted to share...
    Copy code
    export default function(method, url, options = {}) {
      if (!method) throw new Error('You must pass a valid http method')
      if (!url) throw new Error('You must pass a valid url')
    
      const recordingsDirectory = Cypress.config('recordingsDirectory')
      const requestName = `${method}__${url.replace(/(\.|\/)/g, '_')}`.toLowerCase()
      const fileTreePath = Cypress.currentTest.titlePath.join('/')
      const filePath = `${recordingsDirectory}/${fileTreePath}/${requestName}.json`
      const cyRequestOptions = options?.cyRequestOptions || {}
    
      cy.task('doesFileExist', filePath)
        .then(fileExists => {
          return {
            shouldRecord: !!(!fileExists || options.record), // coerce to a single boolean here
            recordReason: options.record ? '`record` option explicitly set' : 'matching recording did not exist'
          }
        })
        .then(file => {
          if (file.shouldRecord) {
            cy.log(`${file.recordReason}, saving recorded response...`)
          } else {
            cy.log(`there was already a recording for ${url}, playing that back...`)
          }
    
          const cyInterceptArgs = { method: method, url: url, ...cyRequestOptions }
    
          if (file.shouldRecord) {
            cy.intercept(cyInterceptArgs, request => {
              request.on('before:response', response => {
                Cypress.env('response', response)
              })
    
              request.continue()
            }).as(url)
          } else {
            cy.readFile(filePath).then((mock) => {
              cy.intercept(cyInterceptArgs, request => {
                request.continue(response => {
                  response.send({...mock})
                })
              }).as(url)
            })
          }
    
          // wrap and pass this data into the next .then block
          cy.wrap(file)
        })
        .then((file) => {
          if (file.shouldRecord && Cypress.env('response')) {
            cy.writeFile(filePath, Cypress.env('response'))
          }
        })
    }
  • a

    able-monkey-72947

    04/27/2022, 6:48 PM
    Long story short, as @gray-kilobyte-89541 said, you can't
    cy.
    (or do anything async, really) inside the
    cy.intercept
    request
    callback... so instead I stashed the data I wanted to write to a file in
    Cypress.env
    then grabbed that in a final
    .then
    call like
    cy.writeFile(filePath, Cypress.env('response'))
    . Running tests right now but in my manual testing its looking like this works 🙌
  • r

    rough-nightfall-90576

    04/27/2022, 7:13 PM
    Does anyone have any experience running cypress coverage on a typescript project where the the source is outside of the root project directory? I have a /src and /test directory and running the nyc/babel/coverage instructions doesn't seem to be scanning the /src files, but it does look at /test. I"m sure there is a way to set the scan directory to /src but I'm not sure which config that is in.
1...575859...252Latest