How to Automate Testing & Reading of QR Code in Your Ruby On Rails Application

  1. Open Google Chrome.
  2. Pick your QR_Code image and drop into google chrome.
  3. Now, the image is converted into the URL. (Please check below image)
  4. Copy URL and put into selenium script.
Import org.openqa.selenium.webdriver;import org.testng.annotation.Test;  public class QRAutomation {        @Test        public void testQRCode(){System.setProperty("webdriver.chrome.driver", "chromedriver.exe path");WebDriver driver = new chromeDriver();driver.manage().window().maximize();driver.get(" C:\\Users\\Prateek\\Desktop\\QR_Code_Updated.png");String qrCodeFileUrl =         driver.findElement(By.tagName("img")).getAttribute("src");
System.out.println("QR Code Image URL is : " +qrCodeFileUrl);URL urlOfImage = new URL(qrCodeFileUrl);BufferedImage bufferedImage = ImageIO.read(urlOfImage);LuminanceSource luminanceSource = new BufferedImageLuminanceSource(bufferedImage);BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(LuminanceSource));Result result = new MultiFormatReader().decode(binaryBitmap);String textInQrCode = result.getText();System.out.println("The Text in QR Code is : "+textInQrCode);}
  1. Bufferedimage: It is used to handle and manipulate the image data.
  2. ImageIO.read: To perform the image read-write operation we will import the ImageIO class.
  3. LuminanceSource: The examples are extracted from open source Java projects.
  4. BufferedImageLuminanceSource: Always use the returned object, and ignore the length of the array.
  5. BinayBitmap: This class is the core bitmap class used by ZXing to represent 1-bit data. Reader objects accept a BinaryBitmap and attempt to decode it.
  6. HybridBinarizer: It is designed for high scale images of QR code with black data on white backgrounds. This Binarizer is the default for the unit tests and the recommended class for library users.
  7. MultiFormatReader(): By default, it attempts to decode all QR Code formats that the library supports. Optionally, you can provide a hints object to request different behavior, for example only decoding QR codes.
  • Advantages of QR_Code testing:
  1. This is used to test that the actual data matches with expected data.
  2. Security and Authorization is the base of all applications. Hope, the above way of automated testing helps you to test security and confidentiality of data in a better way.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cryptex Technologies

Cryptex Technologies

Cryptex specializes in developing open source web applications and software solutions across all domains and verticals using Ruby on Rails (ROR) technology