I am attempting to create some basic tests to try out the new Cypress library. In my test I have cy.visit('http://mywebsite.com');
which is loading an AngularJS app that uses SystemJS.
If I understand Cypress correctly, I shouldn't have to do anything else and it will make sure the page is loaded before running anything else. However this doesn't seem to be working because the page is loaded, but SystemJS is still loading the modules.
How can I get Cypress to wait for all the SystemJS modules to load before running any more tests without using cy.wait(5000)
?
EDIT
Thanks to Dwelle this is the solution that works for me. I wrap the initial System.import in a promise that gets resolved once the AngularJS app has been bootstrapped.
window.APP_READY = new Promise(function(resolve, reject) {
System.import('app').then(function(app) {
angular.element(document).ready(function() {
angular.bootstrap(document, ['app']);
resolve();
});
});
});
And then in the test
cy.visit('http://mywebsite.com').its('APP_READY');
its
's 4 sec is not enough, you can render a hidden element to the<body>
with the status and check that with.get()
where you can increase the timeout with an option object as the 2nd argument:cy.get('#main-status', { timeout: 8000 }).should('have.attr', 'data-cy-status', 'ready')
– Kavita