How to enter data in e2e test

Tags: #<Tag:0x00007efc71991d70>

I had some hard time using HOT table in Angular unit tests (asked different question). No advance with my task I decided to do e2e testing (protractor->selenium under the hood). Now I have 2 issues

  1. I dont know how to paste tabular data using copy-paste
  2. I don’t know how to insert text into selected cell

as for 1. I have tried to simulate paste event like this


function simulatePaste(data: string, pasteTarget: WebdriverWebElement) {
  const script = `
    var event=new Event('paste',{});
    console.log('arguments inner',arguments);
    event.clipboardData={getData:function(){return \`${data}\`}}
    console.log('potential data',event.clipboardData.getData());
    arguments[0].dispatchEvent(event);
  `;
  return browser.executeScript(script, pasteTarget);
}

where pasteTarget is selected table cell. Its not working obviousyly. How to paste data using selenium driver?

  1. I have tried to iterate over set of cells and sendKeys to it but it fails with Failed: element not interactable.
        const cell = this.cell(row, col);
        await cell.click();
        await cell.sendKeys(data[row][col]);

where cell is and ElementFinder pointing to td eg hot-table div.ht_master table tbody tr:nth-child(3) td:nth-child(3)
How to set cell value using selenium driver?

Hi again @sebastian.choina

I’m back with some feedback from our developers.

First of all, here are some tests in Karma that may help *.spec.js https://github.com/handsontable/handsontable/tree/master/wrappers/angular/projects/hot-table/src/lib
Tests related to data change are specified in the core of Handsontable (not in the wrappers). But those tests do not use Selenium, we use Jasmine.

Here’s an example of how we paste data into cells https://github.com/handsontable/handsontable/blob/4e8df3298bf0338b6c3ff390b419ffbef99f2a92/handsontable/test/e2e/Core_setDataAtCell.spec.js#L74 the following test uses our helper https://github.com/handsontable/handsontable/blob/54b788074cebfc548cb125041ec9540624fa7bd8/handsontable/test/helpers/common.js#L429

@aleksandra_budnik these tests are fine in terms of unit testing indeed. But now I have to automate “manual testing”.
You have wrote something about bubble events trought the DOM here Select edit in selenium which is something that I have tried to no avail, but this is more because

  1. I don’t know which native JS event should I send (eg paste action)
  2. I don’t to which DOM element (and in which state) it should be send to

Second point is hard to figure out without checking the code and understanding what sort of magic HOT is doing under the hood to eg display textarea as input field in the cell (iv seen copied tables etc)
Could you guide me on that?

The overall goal here - even putting aside Selenium - is to answer how to simulate paste event of data into the HOT table using JS events (probaly) without using HOT API directly - after all, its about simulating user input. User does not use API directly;)

Next layer of impersonating user interaction whould be moving mouse and interacting with the browser instead of using pupeteer drivers for browsers, but that would be an overkill - but that would work for sure

Maybe I could manually invoke onpaste DOM callback? but on which element? Textarea ?

If that is not a problem, I will gather feedback from my colleagues and get back to you after the weekend.

If you can, then please do so.

Sorry for keeping you waiting. I thought that I would have some answers by now but it seems like the best way to learn is to go throw our tests and check they are constructed. I’m still waiting for my colleague’s feedback so if anything comes back I will surely post it here.

Right now I am entering data cell after cell (double click cell and simulate keystroke). I can inject JS executiong into the context and probably invoke CopyPaste plugin directly, but I think this should be possible. I can guarantee that when autotesters will try to get their hands on it, they will probably dont know how to interact fully with the HOT via their test.

Fortunately, copy paste is closed HOT feature, so even in validated systems this does not have to be tested thoroughly (in my opinion) as it would be like testing OS functions only because users might use it .