commands.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. Cypress.Commands.add('actionStart', () => {
  27. cy.server();
  28. cy.route({
  29. method: 'POST',
  30. url: '/*',
  31. }).as('formAction');
  32. });
  33. Cypress.Commands.add('actionWait', () => {
  34. cy.wait('@formAction');
  35. });
  36. Cypress.Commands.add('resetCMS', () => {
  37. cy.request({
  38. method: 'POST',
  39. url: 'http://localhost:8080/',
  40. form: true,
  41. body: {
  42. action: 'index-cypress-reset',
  43. }
  44. }).then((response) => {
  45. expect(response.body).to.eq('OK');
  46. });
  47. });
  48. Cypress.Commands.add('installCMS', () => {
  49. cy.actionStart();
  50. cy.resetCMS();
  51. cy.visit('http://localhost:8080/cp/');
  52. cy.get('.form-signin input[name=name]').type('fave');
  53. cy.get('.form-signin input[name=user]').type('root');
  54. cy.get('.form-signin input[name=password]').type('root');
  55. cy.get('.form-signin button').click();
  56. cy.actionWait();
  57. cy.visit('http://localhost:8080/cp/');
  58. cy.get('.form-signin input[name=first_name]').type('First');
  59. cy.get('.form-signin input[name=last_name]').type('Last');
  60. cy.get('.form-signin input[name=email]').type('example@example.com');
  61. cy.get('.form-signin input[name=password]').type('example@example.com');
  62. cy.get('.form-signin button').click();
  63. cy.actionWait();
  64. });
  65. Cypress.Commands.add('loginCMS', () => {
  66. cy.actionStart();
  67. cy.visit('http://localhost:8080/cp/');
  68. cy.get('.form-signin input[name=email]').type('example@example.com');
  69. cy.get('.form-signin input[name=password]').type('example@example.com');
  70. cy.get('.form-signin button').click();
  71. cy.actionWait();
  72. });