Search code examples
qr-codedetox

Will Detox tool scan QR codes


Can someone help me and tell me whether Detox test tool supports QR code scanning for mobile apps (Android & iOS)? I have seen in the Github page that there was some sort of bug raised and the question has been moved to stackoverflow and I couldn't find it here.


Solution

  • I don't know how your application would scan QR codes but here is how you can do to test it.

    ScanQR.jsx

    function ScanQR() {
      const [data, setData] = useState(null);
    
      function scan() {
        // here is the logic to scan
        setData(data);
      }
      ...
    }
    

    Then you will create a mock file ScanQR.2e2.jsx following this instructions

    ScanQR.2e2.jsx

    function ScanQR() {
      const [data, setData] = useState(null);
    
      function scan() {
        // replace the logic to scan with actual data results
        const data = 'some data here';
        setData(data);
      }
      ...
    }
    

    This way whenever you test you app the mock file will replace the actual file in which you really scan QR codes using camera.