Warm tip: This article is reproduced from stackoverflow.com, please click
cypress javascript node.js reactjs

How to simulate event of barcode scanning

发布于 2020-04-20 11:06:53

I have to write automation tests for an application that listens to events of a USB barcode scanner, and does some functionality on the event of a scan. The application uses react-barcode-reader. I want to simulate a scan event (i.e. triggering the functionality without physical scanner).

Any idea how to do this?

Questioner
yael berman
Viewed
74
188 2020-02-05 23:20

Thanks for all the comments. Here is the cypress code that worked for me:

   cy.get('body').type("MY BARCODE").trigger('keydown', { keyCode: 13, which: 13 })

This code creates an event of scan. Thanks!!!