commands.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /// <reference types="cypress" />
  2. // ***********************************************
  3. // This example commands.js shows you how to
  4. // create various custom commands and overwrite
  5. // existing commands.
  6. //
  7. // For more comprehensive examples of custom
  8. // commands please read more here:
  9. // https://on.cypress.io/custom-commands
  10. // ***********************************************
  11. //
  12. //
  13. // -- This is a parent command --
  14. // Cypress.Commands.add('login', (email, password) => { ... })
  15. //
  16. //
  17. // -- This is a child command --
  18. // Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
  19. //
  20. //
  21. // -- This is a dual command --
  22. // Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
  23. //
  24. //
  25. // -- This will overwrite an existing command --
  26. // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
  27. // eslint-disable-next-line @typescript-eslint/no-namespace
  28. declare namespace Cypress {
  29. interface Chainable {
  30. /**
  31. * Custom command to login into Atlas with a test membership.
  32. */
  33. login(): Chainable<void>
  34. /**
  35. * Custom command to make the polkadot api available and add accounts, memberships, etc.. to it.
  36. */
  37. injectPolkadot(accounts: any[]): Chainable<void>
  38. }
  39. }
  40. Cypress.Commands.add('injectPolkadot', (accounts = []) => {
  41. const enable = async () => {
  42. return {
  43. accounts: {
  44. get: () => new Promise((resolve) => resolve(accounts)),
  45. },
  46. }
  47. }
  48. cy.window().then((window) => {
  49. window['injectedWeb3'] = {
  50. 'polkadot-js': {
  51. enable,
  52. version: '0.38.3',
  53. },
  54. }
  55. })
  56. })
  57. Cypress.Commands.add('login', () => {
  58. cy.injectPolkadot(Cypress.env('accounts'))
  59. })