Cypress fails weirdly on runtime when trying to interact with a custom dropdown

Operating System: Windows 11

Software Version: Cypress 13.9.0

Hi, im using this custom function, to use a custom dropdown input a website in my company has.
Said website is incredibly flaky, and it queries the options for the dropdown only when you click on input.

That makes it super weird to work on, because on any moment, the input can be without options, only to have options a second later. Also, the input may autocomplete itself based on what you selected on another input

I attached an screenshot of the website, if that helps.

For that kind of dropdown, i developed this function, and it worked pretty much alright for a couple months.

Cypress.Commands.add(
  "selectOptionFromDropdown",
  (dropdownSelector, optionValue, config = {}) => {
    const { exactMatch = false, waitTime = 100 } = config;

    // Convert to lowercase if its not a number
    if (isNaN(optionValue)) {
      optionValue = optionValue.toLowerCase();
    }

    // Check if the dropdown already contains the option
    cy.get(dropdownSelector).then((dropdownElement) => {
      if (dropdownElement.prop("readonly")) {
        cy.log("ELEMENT IS READONLY, SHOULD BE RETURNING");
      } else {
        // Check if the dropdown is not read-only
        cy.get(dropdownSelector).should("not.have.attr", "readonly");

        // Get the dropdown element and clear its content
        cy.get(dropdownSelector).clear();

        // Type the text passed as a parameter
        cy.get(dropdownSelector).type(optionValue);

        // Select the mat-option based on specificity
        cy.get(`mat-option`)
          .filter((index, el) => {
            const text = el.textContent.trim().toLowerCase();
            if (exactMatch) {
              return new RegExp(`^${optionValue}$`, "i").test(text);
            }
            return text.includes(optionValue);
          })
          .click();

        // Wait for the specified time
        cy.wait(waitTime);
      }
    });
  }
);

And i use it like this

        cy.selectOptionFromDropdown(
          `[data-cy="input-productor"]`,
          "UNIDAD DE NEGOCIOS DE VENTA DIRECTA"
        );
        cy.selectOptionFromDropdown(
          `[data-cy="input-provincia"]`,
          persona.provincia
        );
        cy.selectOptionFromDropdown(
          `[data-cy="input-tipoPersona"]`,
          persona.tipoPersona
        );
        cy.selectOptionFromDropdown(
          `[data-cy="input-medioPago"]`,
          persona.medioPago
        );
        cy.selectOptionFromDropdown(
          `[data-cy="input-origenPago"]`,
          persona.origenPago
        );
        cy.selectOptionFromDropdown(
          `[data-cy="input-condicionIva"]`,
          persona.condicionIVA
        );

But suddenly, this error started appearing

The following error originated from your test code, not from Cypress.

> Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.

The command that returned the promise was:

> cy.click()

The cy command you invoked inside the promise was:

> cy.task()

Because Cypress commands are already promise-like, you don't need to wrap them or return your own promise.

Cypress will resolve your command with whatever the final Cypress command yields.

The reason this is an error instead of a warning is because Cypress internally queues commands serially whereas Promises execute as soon as they are invoked. Attempting to reconcile this would prevent Cypress from ever resolving.

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.Learn more
cypress/support/commands.js:91:12
  89 |             return text.includes(optionValue);
  90 |           })
> 91 |           .click();
     |            ^
  92 | 
  93 |         // Wait for the specified time
  94 |         cy.wait(waitTime);

The line where the error occurs is not always the same.

Sometimes, it just happens outside of the function

The function was working months ago, and i dont know how to solve this issue.

Maybe i will have to get in touch with the development team, to make the inputs disabled while they are getting data from the backend?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật