Extract and set form values through the DOM—no frameworks required! https://github.com/TheoryOfNekomata/formxtra
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

default.e2e.ts 1.9 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /// <reference types="cypress" />
  2. import getFormValues from '../../src'
  3. describe('single input template', () => {
  4. beforeEach(() => {
  5. cy.intercept({ url: '/' }, { fixture: 'templates/default.html' });
  6. cy.intercept({ url: '/?*' }, { fixture: 'templates/default.html' }).as('submitted');
  7. })
  8. it('should have a single form value', () => {
  9. let beforeValues;
  10. cy
  11. .visit('/')
  12. .then(() => {
  13. cy.get('[name="first_name"]').type('John')
  14. cy.get('[name="middle_name"]').type('Marcelo')
  15. cy.get('[name="last_name"]').type('Dela Cruz')
  16. cy.get('[name="gender"][value="m"]').check()
  17. cy.get('[name="civil_status"]').select('Married')
  18. cy.get('[name="new_registration"]').check()
  19. cy.get('[name="nationality"][value="filipino"]').check()
  20. cy.get('[name="dependent"][value="Jun"]').check()
  21. // cy.get('button.dependents').click()
  22. // cy.get('.additional-dependent [name="dependent"][type="text"]').eq(0).type('Juana')
  23. // cy.get('button.dependents').click()
  24. // cy.get('.additional-dependent [name="dependent"][type="text"]').eq(1).type('Jane')
  25. // cy.get('button.dependents').click()
  26. // cy.get('.additional-dependent [name="dependent"][type="text"]').eq(2).type('Josh')
  27. cy.get('[name="notes"]').type('Test content\n\nNew line\n\nAnother line').as('filled')
  28. })
  29. .get('form')
  30. .then((theForm) => {
  31. cy
  32. .get('[name="submit"][value="Hi"]')
  33. .then((submitterEl) => {
  34. const [submitter] = Array.from(submitterEl) as HTMLButtonElement[];
  35. beforeValues = getFormValues(theForm[0], submitter);
  36. submitterEl.trigger('click');
  37. cy.wait('@submitted')
  38. cy.location('search').then(search => {
  39. const before = JSON.stringify(new URLSearchParams(beforeValues).toString().split('&'));
  40. const after = JSON.stringify(new URLSearchParams(search).toString().split('&'));
  41. expect(before).to.equal(after);
  42. })
  43. })
  44. })
  45. })
  46. });