0
  1. I have an API that generates Base64 text that can be converted to a QR code. Using https://base64.guru/converter/decode/image (or any other similar tool).

  2. Once it is generated we are getting a QR code.

  3. using the phone or https://4qrcode.com/scan-qr-code.php we can decrypt the QR code back to text so I can use this text for the next API.

  4. Example of the text to be converted to QR: https://www.dropbox.com/s/hiz3mckw1ynqxn4/QR-CodeSnippet.txt?dl=0

  5. Here is the text example from QR:

  • 0$cUYpeMdDiAHe&z+-o7C1ljDr8N<Hr=gG8pfqHni8sAUpGyUpA+,EbpH=M7vK[NfifD}kQ?Did8K5zBkr5jSd9s5>iw]wj&t$lE+::W[}1{asu@6UMNdRwu1F]2dmj,cMJ/FlQAlaHXe-u/VBk4&xY>dVVD7)ZeO@QMvi)uv

I was advised to use the libraries below but I'm not sure where to start, so I would appreciate any explanations https://mvnrepository.com/artifact/com.google.zxing/core/3.4.1

https://mvnrepository.com/artifact/com.github.jai-imageio/jai-imageio-core/1.4.0

https://mvnrepository.com/artifact/com.google.zxing/javase/3.4.1

https://mvnrepository.com/artifact/com.beust/jcommander/1.78

FeelGood
  • 11
  • 3

1 Answers1

0
  1. Take all the jar files and drop them to JMeter Classpath

  2. Restart JMeter to pick them up

  3. Add a suitable JSR223 Test Element and use the following Groovy code there:

    def text  = new File('c:/temp/QR-CodeSnippet.txt').text
    def image = text.substring(text.indexOf(',') + 1)
    
    
    byte[] imageBytes = image.decodeBase64()
    
    def bis = new ByteArrayInputStream(imageBytes)
    def bufferedImage = javax.imageio.ImageIO.read(bis)
    
    def imageSource = new com.google.zxing.client.j2se.BufferedImageLuminanceSource(bufferedImage)
    
    def binarizer = new com.google.zxing.common.HybridBinarizer(imageSource)
    def bitmap = new com.google.zxing.BinaryBitmap(binarizer)
    def multiFormatReader = new com.google.zxing.MultiFormatReader()
    
    def result = multiFormatReader.decode(bitmap)
    def content = result.getText()
    
    log.info('Content from the QR code: ' + content)
    
  4. .....

  5. Profit?

enter image description here

Dmitri T
  • 159,985
  • 5
  • 83
  • 133