1
votes

I have problem with case where my page opens new window. I have case where I put some text in text creator and I wanna check in it preview if text exists. The preview opening in new tab so I have problem with handle it. URL to this preview is generated dynamically when I open text creator.

I have this link in XHR body. But I have no idea how can I copy from it.

I decided to copy url from XHRs body to .json file and in another test ill go to that link. Don't have any better idea to solve this case.

url of page is : app/6237/content/stories/49557/edit?journalId=2455

I tried

cy.server() 
        cy.route('GET', '/app').as('getApp')
        cy.get('[name="pageselct"]').select('300');
        cy.wait('@getApp').then(function(xhr){
          const response = xhr.responseBody
          expect(response[0]).to.have.property('title', 'Untitled')
        })

and received CypressError: Timed out retrying: cy.wait() timed out waiting 5000ms for the 1st request to the route: 'getApp'. No request ever occurred.

I want to copy text from "preview_url". How can I access to this file? 49557 (its generated dynamically when I create new blog post).

enter image description here

1

1 Answers

0
votes

You might try cy.route() with a wildcard string (which uses minimatch), see cy.route#Examples.

Something like app/*/content/stories/*/edit*.

See also Cypress.minimatch#Examples for a quick way to test the wildcard without having to navigate

// returns true
Cypress.minimatch('/users/1/comments', '/users/*/comments', {
  matchBase: true
})

// returns false
Cypress.minimatch('/users/1/comments/2', '/users/*/comments', {
  matchBase: true
})

I tried a couple of the online minimatch testers, but they don't seem to be all that reliable (showing false when match is true).