Home > Software engineering >  Cypress - AG-Grid table: Command type() loosing focus of the Cell
Cypress - AG-Grid table: Command type() loosing focus of the Cell

Time:04-07

I have the following problem:

I want to enter a value into the cell with 'type()'. My guess is that the focus on this cell is lost when entering the value.

Due to the fact that the focus is lost on each letter and the command 'type()' probably clicks back into the cell, the last letter is highlighted and replaced with the next letter. The result looks like this: T e s t

The attempt with the commands 'wait()' and 'focus()' failed.

Maybe there is a possibility to slow down the automated entering of the values

I am curious about your opinion and experiences.

Thanks a lot

AG-Grid Cell Code:

<div comp-id="1"  tabindex="-1" role="gridcell" aria-colindex="1" col-id="column" unselectable="on" style="left: 0px; width: 150px;">t</div>

Screenshot of Cell: enter image description here

Cypress Command:

cy.get('div[row-id="1553c463-0c87-4cc4-a672-89090c6f2cb9"]').should('exist').find('div[col-id="column"]').should('be.visible').click().type('Test{enter}');

CodePudding user response:

Could this function, with small adjustment be the solution to my problem?

function setDataIntoCell(): void {
    const rowNode = this.gridOptions.api.getRowNode('1');
    rowNode.setDataValue('column', 'Test');
}

Error: Cannot read properties of undefined (reading 'gridOptions')

CodePudding user response:

You asked about slowing down the values.

Did you look at the docs Aruments - options

delay - Delay after each keypress

.type('Test{enter}', {delay:100})

Another way to try is realType().

It takes a different approach internally to Cypress .type()

cy.get('div[row-id="1553c463-0c87-4cc4-a672-89090c6f2cb9"] div[col-id="column"]')
  .should('be.visible')
  .focus();
cy.realType("some text {enter}"); // type into focused field
  • Related