Cypress route function not detecting the network request












5















I'm trying to wait for a request made by my application but Cypress is not detecting it on cy.wait



    cy.server();
cy.getAuthenticatedUrl();
cy.route('POST', '/showroom/validate').as('uploadShowroom');

cy.get('[data-testid=Next]').click();

cy.uploadFile('[id=uploadArea]', 'testfile-valid.xlsx', 'application/vnd.ms-excel');

cy.wait('@uploadShowroom');

cy.contains('FILE UPLOAD DONE');


If I check my console during the tests, I can see that the request was made to my server



screenshot-console



Both my client and my server are running local but in different ports.



The error is the following:
CypressError: Timed out retrying: cy.wait() timed out waiting 5000ms for the 1st request to the route: 'uploadShowroom'. No request ever occurred.










share|improve this question























  • Does the route show up the same in the cypress command log? And does it show up before the timeout error is thrown?

    – Brendan
    Jan 3 at 18:11











  • @Brendan yes, the second screenshot is from the cypress log (logged a few seconds before the timeout)

    – Eduardo Pedroso
    Jan 3 at 19:09











  • That doesn't look like the command log. I'm talking about the command log in the test runner: docs.cypress.io/guides/core-concepts/test-runner.html . I'm guessing the request isn't an XHR as Richard Matsen mentions in his answer. If it is an XHR it'll show up in the command log, if it isn't, it won't.

    – Brendan
    Jan 4 at 18:14
















5















I'm trying to wait for a request made by my application but Cypress is not detecting it on cy.wait



    cy.server();
cy.getAuthenticatedUrl();
cy.route('POST', '/showroom/validate').as('uploadShowroom');

cy.get('[data-testid=Next]').click();

cy.uploadFile('[id=uploadArea]', 'testfile-valid.xlsx', 'application/vnd.ms-excel');

cy.wait('@uploadShowroom');

cy.contains('FILE UPLOAD DONE');


If I check my console during the tests, I can see that the request was made to my server



screenshot-console



Both my client and my server are running local but in different ports.



The error is the following:
CypressError: Timed out retrying: cy.wait() timed out waiting 5000ms for the 1st request to the route: 'uploadShowroom'. No request ever occurred.










share|improve this question























  • Does the route show up the same in the cypress command log? And does it show up before the timeout error is thrown?

    – Brendan
    Jan 3 at 18:11











  • @Brendan yes, the second screenshot is from the cypress log (logged a few seconds before the timeout)

    – Eduardo Pedroso
    Jan 3 at 19:09











  • That doesn't look like the command log. I'm talking about the command log in the test runner: docs.cypress.io/guides/core-concepts/test-runner.html . I'm guessing the request isn't an XHR as Richard Matsen mentions in his answer. If it is an XHR it'll show up in the command log, if it isn't, it won't.

    – Brendan
    Jan 4 at 18:14














5












5








5


1






I'm trying to wait for a request made by my application but Cypress is not detecting it on cy.wait



    cy.server();
cy.getAuthenticatedUrl();
cy.route('POST', '/showroom/validate').as('uploadShowroom');

cy.get('[data-testid=Next]').click();

cy.uploadFile('[id=uploadArea]', 'testfile-valid.xlsx', 'application/vnd.ms-excel');

cy.wait('@uploadShowroom');

cy.contains('FILE UPLOAD DONE');


If I check my console during the tests, I can see that the request was made to my server



screenshot-console



Both my client and my server are running local but in different ports.



The error is the following:
CypressError: Timed out retrying: cy.wait() timed out waiting 5000ms for the 1st request to the route: 'uploadShowroom'. No request ever occurred.










share|improve this question














I'm trying to wait for a request made by my application but Cypress is not detecting it on cy.wait



    cy.server();
cy.getAuthenticatedUrl();
cy.route('POST', '/showroom/validate').as('uploadShowroom');

cy.get('[data-testid=Next]').click();

cy.uploadFile('[id=uploadArea]', 'testfile-valid.xlsx', 'application/vnd.ms-excel');

cy.wait('@uploadShowroom');

cy.contains('FILE UPLOAD DONE');


If I check my console during the tests, I can see that the request was made to my server



screenshot-console



Both my client and my server are running local but in different ports.



The error is the following:
CypressError: Timed out retrying: cy.wait() timed out waiting 5000ms for the 1st request to the route: 'uploadShowroom'. No request ever occurred.







javascript reactjs e2e-testing cypress






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 11:45









Eduardo PedrosoEduardo Pedroso

160415




160415













  • Does the route show up the same in the cypress command log? And does it show up before the timeout error is thrown?

    – Brendan
    Jan 3 at 18:11











  • @Brendan yes, the second screenshot is from the cypress log (logged a few seconds before the timeout)

    – Eduardo Pedroso
    Jan 3 at 19:09











  • That doesn't look like the command log. I'm talking about the command log in the test runner: docs.cypress.io/guides/core-concepts/test-runner.html . I'm guessing the request isn't an XHR as Richard Matsen mentions in his answer. If it is an XHR it'll show up in the command log, if it isn't, it won't.

    – Brendan
    Jan 4 at 18:14



















  • Does the route show up the same in the cypress command log? And does it show up before the timeout error is thrown?

    – Brendan
    Jan 3 at 18:11











  • @Brendan yes, the second screenshot is from the cypress log (logged a few seconds before the timeout)

    – Eduardo Pedroso
    Jan 3 at 19:09











  • That doesn't look like the command log. I'm talking about the command log in the test runner: docs.cypress.io/guides/core-concepts/test-runner.html . I'm guessing the request isn't an XHR as Richard Matsen mentions in his answer. If it is an XHR it'll show up in the command log, if it isn't, it won't.

    – Brendan
    Jan 4 at 18:14

















Does the route show up the same in the cypress command log? And does it show up before the timeout error is thrown?

– Brendan
Jan 3 at 18:11





Does the route show up the same in the cypress command log? And does it show up before the timeout error is thrown?

– Brendan
Jan 3 at 18:11













@Brendan yes, the second screenshot is from the cypress log (logged a few seconds before the timeout)

– Eduardo Pedroso
Jan 3 at 19:09





@Brendan yes, the second screenshot is from the cypress log (logged a few seconds before the timeout)

– Eduardo Pedroso
Jan 3 at 19:09













That doesn't look like the command log. I'm talking about the command log in the test runner: docs.cypress.io/guides/core-concepts/test-runner.html . I'm guessing the request isn't an XHR as Richard Matsen mentions in his answer. If it is an XHR it'll show up in the command log, if it isn't, it won't.

– Brendan
Jan 4 at 18:14





That doesn't look like the command log. I'm talking about the command log in the test runner: docs.cypress.io/guides/core-concepts/test-runner.html . I'm guessing the request isn't an XHR as Richard Matsen mentions in his answer. If it is an XHR it'll show up in the command log, if it isn't, it won't.

– Brendan
Jan 4 at 18:14












2 Answers
2






active

oldest

votes


















3














I think this is because your form is using native form submit, but Cypress' cy.route() only responds to XHR calls (at the moment).



There is a big discussion in issue #170.



Gleb Bahmutov has an interesting idea in this comment, code in this repository. Essentially he 'mocks' the native submit with an XHR submit, on the fly.



I tried out a variation which gets closer to your scenario. Follow the repository READ.ME to set up the test, but first update the Cypress version in package.json. Add the file to be uploaded into /cypress/fixtures.



Then try the following spec.



The third test is an alternative which uses cy.url() instead of cy.route().



uploadFile command (or similar variation)



Cypress.Commands.add('uploadFile', (fileName, selector) =>
cy.get(selector).then(subject => {
return cy
.fixture(fileName, 'base64')
.then(Cypress.Blob.base64StringToBlob)
.then(blob => {
const el = subject[0];
const testFile = new File([blob], fileName, {
type: 'application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet',
});
const dataTransfer = new DataTransfer();
dataTransfer.items.add(testFile);
el.files = dataTransfer.files;
return subject;
});
})
);


Function to 'mock' the native submit with XHR (place at top of Spec)



const mockNativeSubmitWithXhr = (form$) => {
let win
cy.window().then(w => {
win = w
})
form$.on('submit', e => {
e.preventDefault()
const form = new FormData(e.target)
const XHR = new win.XMLHttpRequest()
XHR.onload = response => {
win.document.write(XHR.responseText)
win.history.pushState({}, '', XHR.url)
}
XHR.open(e.target.method, e.target.action)
XHR.send(form)
return true
})
}


Spec



describe('waiting for form-data post', () => {

beforeEach(() => {
cy.task('deleteFile', '../../uploads/Sample_data.xlsx')
cy.visit('localhost:3000')
cy.get('input[name="userid"]').type('foo@bar.com')
})

it('upload with native form submit (fails because of native event)', () => {
cy.server()
cy.route('POST', '/upload').as('upload');

cy.uploadFile('Sample_data.xlsx', '[id=fileToUpload]')
cy.get('input[type="submit"]').click()

cy.wait('@upload');
cy.readFile('uploads/Sample_data.xlsx') // check saved file
})

it('upload with form submit mocked to XHR send (succeeds)', () => {
cy.server()
cy.route('POST', '/upload').as('upload');

cy.uploadFile('Sample_data.xlsx', '[id=fileToUpload]')
cy.get('form').then(form => mockNativeSubmitWithXhr(form))
cy.get('input[type="submit"]').click()

cy.wait('@upload');
cy.readFile('uploads/Sample_data.xlsx')
})

it('upload with native form submit (testing url has changed)', () => {
cy.uploadFile('Sample_data.xlsx', '[id=fileToUpload]')
cy.get('input[type="submit"]').click()

cy.url().should('eq', 'http://localhost:3000/upload')
cy.readFile('uploads/Sample_data.xlsx')
})
})


Task to remove uploaded file between tests (modify '/cypress/plugins/index.js')



const fs = require('fs')

module.exports = (on, config) => {
on('task', {
deleteFile: (path) => {
if (fs.existsSync(path)) {
fs.unlinkSync(path)
}
return null
}
})
}





share|improve this answer

































    -1














    Try to override default timeout of wait:



    cy.wait('@uploadShowroom', {timeout: 10000);






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54005760%2fcypress-route-function-not-detecting-the-network-request%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3














      I think this is because your form is using native form submit, but Cypress' cy.route() only responds to XHR calls (at the moment).



      There is a big discussion in issue #170.



      Gleb Bahmutov has an interesting idea in this comment, code in this repository. Essentially he 'mocks' the native submit with an XHR submit, on the fly.



      I tried out a variation which gets closer to your scenario. Follow the repository READ.ME to set up the test, but first update the Cypress version in package.json. Add the file to be uploaded into /cypress/fixtures.



      Then try the following spec.



      The third test is an alternative which uses cy.url() instead of cy.route().



      uploadFile command (or similar variation)



      Cypress.Commands.add('uploadFile', (fileName, selector) =>
      cy.get(selector).then(subject => {
      return cy
      .fixture(fileName, 'base64')
      .then(Cypress.Blob.base64StringToBlob)
      .then(blob => {
      const el = subject[0];
      const testFile = new File([blob], fileName, {
      type: 'application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet',
      });
      const dataTransfer = new DataTransfer();
      dataTransfer.items.add(testFile);
      el.files = dataTransfer.files;
      return subject;
      });
      })
      );


      Function to 'mock' the native submit with XHR (place at top of Spec)



      const mockNativeSubmitWithXhr = (form$) => {
      let win
      cy.window().then(w => {
      win = w
      })
      form$.on('submit', e => {
      e.preventDefault()
      const form = new FormData(e.target)
      const XHR = new win.XMLHttpRequest()
      XHR.onload = response => {
      win.document.write(XHR.responseText)
      win.history.pushState({}, '', XHR.url)
      }
      XHR.open(e.target.method, e.target.action)
      XHR.send(form)
      return true
      })
      }


      Spec



      describe('waiting for form-data post', () => {

      beforeEach(() => {
      cy.task('deleteFile', '../../uploads/Sample_data.xlsx')
      cy.visit('localhost:3000')
      cy.get('input[name="userid"]').type('foo@bar.com')
      })

      it('upload with native form submit (fails because of native event)', () => {
      cy.server()
      cy.route('POST', '/upload').as('upload');

      cy.uploadFile('Sample_data.xlsx', '[id=fileToUpload]')
      cy.get('input[type="submit"]').click()

      cy.wait('@upload');
      cy.readFile('uploads/Sample_data.xlsx') // check saved file
      })

      it('upload with form submit mocked to XHR send (succeeds)', () => {
      cy.server()
      cy.route('POST', '/upload').as('upload');

      cy.uploadFile('Sample_data.xlsx', '[id=fileToUpload]')
      cy.get('form').then(form => mockNativeSubmitWithXhr(form))
      cy.get('input[type="submit"]').click()

      cy.wait('@upload');
      cy.readFile('uploads/Sample_data.xlsx')
      })

      it('upload with native form submit (testing url has changed)', () => {
      cy.uploadFile('Sample_data.xlsx', '[id=fileToUpload]')
      cy.get('input[type="submit"]').click()

      cy.url().should('eq', 'http://localhost:3000/upload')
      cy.readFile('uploads/Sample_data.xlsx')
      })
      })


      Task to remove uploaded file between tests (modify '/cypress/plugins/index.js')



      const fs = require('fs')

      module.exports = (on, config) => {
      on('task', {
      deleteFile: (path) => {
      if (fs.existsSync(path)) {
      fs.unlinkSync(path)
      }
      return null
      }
      })
      }





      share|improve this answer






























        3














        I think this is because your form is using native form submit, but Cypress' cy.route() only responds to XHR calls (at the moment).



        There is a big discussion in issue #170.



        Gleb Bahmutov has an interesting idea in this comment, code in this repository. Essentially he 'mocks' the native submit with an XHR submit, on the fly.



        I tried out a variation which gets closer to your scenario. Follow the repository READ.ME to set up the test, but first update the Cypress version in package.json. Add the file to be uploaded into /cypress/fixtures.



        Then try the following spec.



        The third test is an alternative which uses cy.url() instead of cy.route().



        uploadFile command (or similar variation)



        Cypress.Commands.add('uploadFile', (fileName, selector) =>
        cy.get(selector).then(subject => {
        return cy
        .fixture(fileName, 'base64')
        .then(Cypress.Blob.base64StringToBlob)
        .then(blob => {
        const el = subject[0];
        const testFile = new File([blob], fileName, {
        type: 'application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet',
        });
        const dataTransfer = new DataTransfer();
        dataTransfer.items.add(testFile);
        el.files = dataTransfer.files;
        return subject;
        });
        })
        );


        Function to 'mock' the native submit with XHR (place at top of Spec)



        const mockNativeSubmitWithXhr = (form$) => {
        let win
        cy.window().then(w => {
        win = w
        })
        form$.on('submit', e => {
        e.preventDefault()
        const form = new FormData(e.target)
        const XHR = new win.XMLHttpRequest()
        XHR.onload = response => {
        win.document.write(XHR.responseText)
        win.history.pushState({}, '', XHR.url)
        }
        XHR.open(e.target.method, e.target.action)
        XHR.send(form)
        return true
        })
        }


        Spec



        describe('waiting for form-data post', () => {

        beforeEach(() => {
        cy.task('deleteFile', '../../uploads/Sample_data.xlsx')
        cy.visit('localhost:3000')
        cy.get('input[name="userid"]').type('foo@bar.com')
        })

        it('upload with native form submit (fails because of native event)', () => {
        cy.server()
        cy.route('POST', '/upload').as('upload');

        cy.uploadFile('Sample_data.xlsx', '[id=fileToUpload]')
        cy.get('input[type="submit"]').click()

        cy.wait('@upload');
        cy.readFile('uploads/Sample_data.xlsx') // check saved file
        })

        it('upload with form submit mocked to XHR send (succeeds)', () => {
        cy.server()
        cy.route('POST', '/upload').as('upload');

        cy.uploadFile('Sample_data.xlsx', '[id=fileToUpload]')
        cy.get('form').then(form => mockNativeSubmitWithXhr(form))
        cy.get('input[type="submit"]').click()

        cy.wait('@upload');
        cy.readFile('uploads/Sample_data.xlsx')
        })

        it('upload with native form submit (testing url has changed)', () => {
        cy.uploadFile('Sample_data.xlsx', '[id=fileToUpload]')
        cy.get('input[type="submit"]').click()

        cy.url().should('eq', 'http://localhost:3000/upload')
        cy.readFile('uploads/Sample_data.xlsx')
        })
        })


        Task to remove uploaded file between tests (modify '/cypress/plugins/index.js')



        const fs = require('fs')

        module.exports = (on, config) => {
        on('task', {
        deleteFile: (path) => {
        if (fs.existsSync(path)) {
        fs.unlinkSync(path)
        }
        return null
        }
        })
        }





        share|improve this answer




























          3












          3








          3







          I think this is because your form is using native form submit, but Cypress' cy.route() only responds to XHR calls (at the moment).



          There is a big discussion in issue #170.



          Gleb Bahmutov has an interesting idea in this comment, code in this repository. Essentially he 'mocks' the native submit with an XHR submit, on the fly.



          I tried out a variation which gets closer to your scenario. Follow the repository READ.ME to set up the test, but first update the Cypress version in package.json. Add the file to be uploaded into /cypress/fixtures.



          Then try the following spec.



          The third test is an alternative which uses cy.url() instead of cy.route().



          uploadFile command (or similar variation)



          Cypress.Commands.add('uploadFile', (fileName, selector) =>
          cy.get(selector).then(subject => {
          return cy
          .fixture(fileName, 'base64')
          .then(Cypress.Blob.base64StringToBlob)
          .then(blob => {
          const el = subject[0];
          const testFile = new File([blob], fileName, {
          type: 'application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet',
          });
          const dataTransfer = new DataTransfer();
          dataTransfer.items.add(testFile);
          el.files = dataTransfer.files;
          return subject;
          });
          })
          );


          Function to 'mock' the native submit with XHR (place at top of Spec)



          const mockNativeSubmitWithXhr = (form$) => {
          let win
          cy.window().then(w => {
          win = w
          })
          form$.on('submit', e => {
          e.preventDefault()
          const form = new FormData(e.target)
          const XHR = new win.XMLHttpRequest()
          XHR.onload = response => {
          win.document.write(XHR.responseText)
          win.history.pushState({}, '', XHR.url)
          }
          XHR.open(e.target.method, e.target.action)
          XHR.send(form)
          return true
          })
          }


          Spec



          describe('waiting for form-data post', () => {

          beforeEach(() => {
          cy.task('deleteFile', '../../uploads/Sample_data.xlsx')
          cy.visit('localhost:3000')
          cy.get('input[name="userid"]').type('foo@bar.com')
          })

          it('upload with native form submit (fails because of native event)', () => {
          cy.server()
          cy.route('POST', '/upload').as('upload');

          cy.uploadFile('Sample_data.xlsx', '[id=fileToUpload]')
          cy.get('input[type="submit"]').click()

          cy.wait('@upload');
          cy.readFile('uploads/Sample_data.xlsx') // check saved file
          })

          it('upload with form submit mocked to XHR send (succeeds)', () => {
          cy.server()
          cy.route('POST', '/upload').as('upload');

          cy.uploadFile('Sample_data.xlsx', '[id=fileToUpload]')
          cy.get('form').then(form => mockNativeSubmitWithXhr(form))
          cy.get('input[type="submit"]').click()

          cy.wait('@upload');
          cy.readFile('uploads/Sample_data.xlsx')
          })

          it('upload with native form submit (testing url has changed)', () => {
          cy.uploadFile('Sample_data.xlsx', '[id=fileToUpload]')
          cy.get('input[type="submit"]').click()

          cy.url().should('eq', 'http://localhost:3000/upload')
          cy.readFile('uploads/Sample_data.xlsx')
          })
          })


          Task to remove uploaded file between tests (modify '/cypress/plugins/index.js')



          const fs = require('fs')

          module.exports = (on, config) => {
          on('task', {
          deleteFile: (path) => {
          if (fs.existsSync(path)) {
          fs.unlinkSync(path)
          }
          return null
          }
          })
          }





          share|improve this answer















          I think this is because your form is using native form submit, but Cypress' cy.route() only responds to XHR calls (at the moment).



          There is a big discussion in issue #170.



          Gleb Bahmutov has an interesting idea in this comment, code in this repository. Essentially he 'mocks' the native submit with an XHR submit, on the fly.



          I tried out a variation which gets closer to your scenario. Follow the repository READ.ME to set up the test, but first update the Cypress version in package.json. Add the file to be uploaded into /cypress/fixtures.



          Then try the following spec.



          The third test is an alternative which uses cy.url() instead of cy.route().



          uploadFile command (or similar variation)



          Cypress.Commands.add('uploadFile', (fileName, selector) =>
          cy.get(selector).then(subject => {
          return cy
          .fixture(fileName, 'base64')
          .then(Cypress.Blob.base64StringToBlob)
          .then(blob => {
          const el = subject[0];
          const testFile = new File([blob], fileName, {
          type: 'application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet',
          });
          const dataTransfer = new DataTransfer();
          dataTransfer.items.add(testFile);
          el.files = dataTransfer.files;
          return subject;
          });
          })
          );


          Function to 'mock' the native submit with XHR (place at top of Spec)



          const mockNativeSubmitWithXhr = (form$) => {
          let win
          cy.window().then(w => {
          win = w
          })
          form$.on('submit', e => {
          e.preventDefault()
          const form = new FormData(e.target)
          const XHR = new win.XMLHttpRequest()
          XHR.onload = response => {
          win.document.write(XHR.responseText)
          win.history.pushState({}, '', XHR.url)
          }
          XHR.open(e.target.method, e.target.action)
          XHR.send(form)
          return true
          })
          }


          Spec



          describe('waiting for form-data post', () => {

          beforeEach(() => {
          cy.task('deleteFile', '../../uploads/Sample_data.xlsx')
          cy.visit('localhost:3000')
          cy.get('input[name="userid"]').type('foo@bar.com')
          })

          it('upload with native form submit (fails because of native event)', () => {
          cy.server()
          cy.route('POST', '/upload').as('upload');

          cy.uploadFile('Sample_data.xlsx', '[id=fileToUpload]')
          cy.get('input[type="submit"]').click()

          cy.wait('@upload');
          cy.readFile('uploads/Sample_data.xlsx') // check saved file
          })

          it('upload with form submit mocked to XHR send (succeeds)', () => {
          cy.server()
          cy.route('POST', '/upload').as('upload');

          cy.uploadFile('Sample_data.xlsx', '[id=fileToUpload]')
          cy.get('form').then(form => mockNativeSubmitWithXhr(form))
          cy.get('input[type="submit"]').click()

          cy.wait('@upload');
          cy.readFile('uploads/Sample_data.xlsx')
          })

          it('upload with native form submit (testing url has changed)', () => {
          cy.uploadFile('Sample_data.xlsx', '[id=fileToUpload]')
          cy.get('input[type="submit"]').click()

          cy.url().should('eq', 'http://localhost:3000/upload')
          cy.readFile('uploads/Sample_data.xlsx')
          })
          })


          Task to remove uploaded file between tests (modify '/cypress/plugins/index.js')



          const fs = require('fs')

          module.exports = (on, config) => {
          on('task', {
          deleteFile: (path) => {
          if (fs.existsSync(path)) {
          fs.unlinkSync(path)
          }
          return null
          }
          })
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 4 at 10:52

























          answered Jan 4 at 10:45









          Richard MatsenRichard Matsen

          8,5112834




          8,5112834

























              -1














              Try to override default timeout of wait:



              cy.wait('@uploadShowroom', {timeout: 10000);






              share|improve this answer




























                -1














                Try to override default timeout of wait:



                cy.wait('@uploadShowroom', {timeout: 10000);






                share|improve this answer


























                  -1












                  -1








                  -1







                  Try to override default timeout of wait:



                  cy.wait('@uploadShowroom', {timeout: 10000);






                  share|improve this answer













                  Try to override default timeout of wait:



                  cy.wait('@uploadShowroom', {timeout: 10000);







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 2 at 20:12









                  Julia PassynkovaJulia Passynkova

                  8,77221824




                  8,77221824






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54005760%2fcypress-route-function-not-detecting-the-network-request%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Monofisismo

                      Angular Downloading a file using contenturl with Basic Authentication

                      Olmecas