Last active
April 14, 2022 05:24
-
-
Save nottyo/d65a654ff288a148ace82ae1a4c24c8e to your computer and use it in GitHub Desktop.
cypress - qrcode reader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BrowserMultiFormatReader } from '@zxing/browser'; | |
const reader = new BrowserMultiFormatReader(); | |
Cypress.Commands.add('readCode', { prevSubject: true }, (subject) => { | |
const img = subject[0]; | |
const image = new Image(); | |
image.width = img.width; | |
image.height = img.height; | |
image.src = img.src; | |
image.crossOrigin = 'Anonymous'; | |
return reader.decodeFromImageElement(image); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('QR Code', () => { | |
it('can read barcode with zxing-js', () => { | |
cy.visit('./qrcode.html'); | |
cy.get('[data-testid="barcode"]') | |
.readCode() | |
.should('have.property', 'text', 'https://medium.com/@nottyo'); | |
}); | |
it('can read qrcode with zxing-js', () => { | |
cy.visit('./qrcode.html'); | |
cy.get('[data-testid="qr-code-img"]') | |
.readCode() | |
.should('have.property', 'text', 'https://www.cypress.io'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment