commands.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 is will overwrite an existing command --
  25. // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
  26. function getBaseUrl() {
  27. return 'http://localhost:8080';
  28. }
  29. Cypress.Commands.add('visitCMS', (url) => {
  30. cy.visit(getBaseUrl() + url);
  31. });
  32. Cypress.Commands.add('actionStart', () => {
  33. cy.server();
  34. cy.route({
  35. method: 'POST',
  36. url: '/*',
  37. }).as('formAction');
  38. });
  39. Cypress.Commands.add('actionWait', () => {
  40. cy.wait('@formAction');
  41. });
  42. Cypress.Commands.add('resetCMS', () => {
  43. cy.request({
  44. method: 'POST',
  45. url: getBaseUrl() + '/',
  46. form: true,
  47. body: {
  48. action: 'index-cypress-reset',
  49. }
  50. }).then((response) => {
  51. expect(response.body).to.eq('OK');
  52. });
  53. });
  54. Cypress.Commands.add('installCMS', () => {
  55. cy.actionStart();
  56. cy.resetCMS();
  57. cy.visitCMS('/cp/');
  58. cy.get('.form-signin input[name=name]').type('fave');
  59. cy.get('.form-signin input[name=user]').type('root');
  60. cy.get('.form-signin input[name=password]').type('root');
  61. cy.get('.form-signin button').click();
  62. cy.actionWait();
  63. cy.visitCMS('/cp/');
  64. cy.get('.form-signin input[name=first_name]').type('First');
  65. cy.get('.form-signin input[name=last_name]').type('Last');
  66. cy.get('.form-signin input[name=email]').type('example@example.com');
  67. cy.get('.form-signin input[name=password]').type('example@example.com');
  68. cy.get('.form-signin button').click();
  69. cy.actionWait();
  70. });
  71. Cypress.Commands.add('loginCMS', () => {
  72. cy.actionStart();
  73. cy.visitCMS('/cp/');
  74. cy.get('.form-signin input[name=email]').type('example@example.com');
  75. cy.get('.form-signin input[name=password]').type('example@example.com');
  76. cy.get('.form-signin button').click();
  77. cy.actionWait();
  78. });
  79. Cypress.Commands.add('logoutCMS', () => {
  80. cy.actionStart();
  81. cy.visitCMS('/cp/');
  82. cy.get('#navbarCollapse ul.navbar-nav:nth-child(2) li.nav-item:nth-child(1) a.nav-link').click();
  83. cy.contains('#navbarCollapse ul.navbar-nav:nth-child(2) li.nav-item:nth-child(1) div.dropdown-menu a', 'Logout').click();
  84. cy.actionWait();
  85. });