Forum Discussion

nmoro's avatar
nmoro
Occasional Contributor
14 years ago

BarCode Scanner Capability with Keys?

Is it possible to imitate a barcode scanner?



For example .Keys("^T)?T8C4NWcPj*8iMC$D*")

I know that to make the "^" sign you need two of them -- ^^

Please help (:

5 Replies

  • nmoro's avatar
    nmoro
    Occasional Contributor
    Hi David,



    Here is a sample of barcodes. We would just need to give focus to the panel we would normally use to scan our barcodes into and all I need the application to do is enter the barcode with a method like keys (there could be a better way??) Some samples of barcodes are:



    ^-TSIT/.3OfP7"c]9r2q\

    ^?lh16-i.mMYp/Mv&J?/%

    ^Z-Mi+Sv0bjTY/EJUQ#<[

    ^T)?T8C4NWcPj*8iMC$D*





    How would I tell the program to enter something like above without throwing errors with all the special characters?

    Here is what I tried to do:



    var barcode = ^^T)?T8C4NWcPj*8iMC$D*

    Aliases.SoftwareName.frmConsumable.62d223ac-0224-425c-a9b5-8640f2d13173TopLevelControl.m_BarcodesPanel.DockPanel();



    Aliases.SoftwareName.frmConsumable.z2d223ac_0224_425c_a9b5_8640f2d13173.d9c6e1ea-c1c8-4458-b47e-c82f201c6f52.d9c6e1ea-c1c8-4458-b47e-c82f201c6f52Container.ucBarcodeMultiple.grpBackground.grdBarcodes.Keys(barcode);



    Hope this helps solve my issue (:

  • Hi Nancy,





    TestComplete does not have special features for emulating such devices. As for using the Keys method, it seems that this approach is specific to your application, and without seeing it, I cannot suggest anything. Does TestComplete record a test which involves the scanner? Can this test be executed?

  • Hi Nancy,





    First of all, you can just assign the value to the field using its 'Text', 'wText' or another property that contains the values of the text box:



    var barcode = "^T)?T8C4NWcPj*8iMC$D*";

    var textBox = Aliases.SoftwareName.frmConsumable.z2d223ac_0224_425c_a9b5_8640f2d13173.d9c6e1ea-c1c8-4458-b47e-c82f201c6f52.d9c6e1ea-c1c8-4458-b47e-c82f201c6f52Container.ucBarcodeMultiple.grpBackground.grdBarcodes;

    textBox.Text = barcode;







    Another way is to prepare code by doubling all the special characters before calling the Keys method. The following script demonstrates this approach:



    function Test1()

    {

      var codes = new Array();

      codes.push('^-TSIT/.3OfP7"c]9r2q\\');  // The '\' character should be doubled manually

      codes.push('^?lh16-i.mMYp/Mv&J?/%');

      codes.push('^Z-Mi+Sv0bjTY/EJUQ#<[');

      codes.push('^T)?T8C4NWcPj*8iMC$D*');





      for (var i = 0; i < codes.length; i++) {

        TestNotepad(prepareBarcodeForKeys(codes));

      }

    }





    function TestNotepad(str)

    {

      var  edit;

      edit = Sys.Process("notepad").Window("Notepad", "*").Window("Edit");

      edit.Keys(str);

      edit.Keys("[Enter]");

    }





    function prepareBarcodeForKeys(code)

    {

      code = code.replace(/\^/ig, '^^');

      code = code.replace(/\[/ig, '[[');

      code = code.replace(/~/ig, '~~');

      code = code.replace(/!/ig, '!!');

      return code;

    }






    Please note that you can read code from an external file during your test. Please see the Data-Driven Testing help topic for more information.
  • nmoro's avatar
    nmoro
    Occasional Contributor
    Thank you, David, for your help! Really appreciate your time to help me
    with this hurdle. Looks like no one else has had a similar question
    regarding barcodes. I have been switched off of Automation for the short
    time being as our company needs to get a software patch out but when I
    am back on automation I will let you know if this solved my problem.



    Again, really really appreciate how fast your support team gets back to our questions. Thank you for making my experience with Test Complete an extremely positive one!

  • Hi,


     


    I am not sure what exactly task you want to automate with TestComplete. Could you please describe it in detail?