commands.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // ***********************************************
  2. // This example commands.js shows you how to
  3. // create various custom commands and overwrite
  4. // existing commands.
  5. //
  6. // For more comprehensive examples of custom
  7. // commands please read more here:
  8. // https://on.cypress.io/custom-commands
  9. // ***********************************************
  10. //
  11. //
  12. // -- This is a parent command --
  13. // Cypress.Commands.add('login', (email, password) => { ... })
  14. //
  15. //
  16. // -- This is a child command --
  17. // Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
  18. //
  19. //
  20. // -- This is a dual command --
  21. // Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
  22. //
  23. //
  24. // -- This will overwrite an existing command --
  25. // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
  26. Cypress.Commands.add('clearIndexedDB', async () => {
  27. const databases = await window.indexedDB.databases();
  28. await Promise.all(
  29. databases.map(
  30. ({ name }) =>
  31. new Promise((resolve, reject) => {
  32. const request = window.indexedDB.deleteDatabase(name);
  33. request.addEventListener('success', resolve);
  34. // Note: we need to also listen to the "blocked" event
  35. // (and resolve the promise) due to https://stackoverflow.com/a/35141818
  36. request.addEventListener('blocked', resolve);
  37. request.addEventListener('error', reject);
  38. }),
  39. ),
  40. );
  41. });