Created
April 14, 2022 05:14
-
-
Save nottyo/36d121c1b1bb7fbcfedea50616b10d56 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
describe('QR Code', () => { | |
it('can read qrcode', () => { | |
cy.visit('./qrcode.html'); | |
cy.get('[data-testid="qr-code-img"]') | |
.then($el => { | |
const img = $el[0]; | |
const image = new Image(); | |
image.width = img.width; | |
image.height = img.height; | |
image.src = img.src; | |
image.crossOrigin = 'Anonymous'; | |
return image; | |
}) | |
.then(image => { | |
const reader = new BrowserMultiFormatReader(); | |
return reader.decodeFromImageElement(image[0]) | |
}) | |
.then(result => { | |
expect(result.getText()).to.equal('https://www.cypress.io'); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment