commands.js 2.4 KB

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