'In Cypress, Date and Time input fields are cleared unexpectedly after other input fields are filled

I have 4 input fields that must be filled to activate a form submit button.

  1. Date
  2. Time
  3. select
  4. textarea

I created a cypress test to fill each of them by order and finally click the button to submit. But cypress unexpectedly clears out the first two input fields as soon as it fills select field. I tried deleting select field but the output did not change.

first two fields are cleared

Below is my test code.

/// <reference types="cypress" />

describe("Home Page", () => {
  beforeEach(() => {
    cy.visit("/");
    cy.get('input[name="date"]').as("date-field");
    cy.get('input[name="time"]').as("time-field");
    cy.get('select[name="alarmMode"]').as("alarmMode-field");
    cy.get('textarea[name="content"]').as("textarea-field");
  });

  it("submits user input", () => {
    cy.get("@date-field")
      .invoke("val", "2022-04-29")
      .get("@time-field")
      .invoke("val", "12:00:00")
      .get("@alarmMode-field")
      .select("NORMAL")
      .get("@textarea-field")
      .type("hello all!!!!!");

    cy.get("form button").click();
  });
});


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source