Forum Discussion

fayrehouse's avatar
fayrehouse
Frequent Contributor
11 years ago
Solved

String params not treated as regex's...

Hi All,



I have a number of funtions that take a file/folder path as a parm - so for example "C:\users\steve\sample.txt" When calling the function, I have to pass this in as "C:\\users\\steve\\sample.txt"  to escape the backslashes being treated as regex control characters. 



Just to clarify - these functions are scripted functions, being called in keyword tests. 



Going forward, "less techy" types will be constructing these keyword tests. Is there a way anyone knows of that would allow these less techy types to pass in the file/folder paths, WITHOUT "double-backslashing"? Ie, force TC to stop treating strings as regex's?



  • Hi Steve.



    I think you won't face problems with passing backslahed strings into your functions from KDTs.



    I played passing KDT variable, KDT parameter and constant into JScript function: variable and KDT parameter came thru without any modifications. As for constant parameter, TC replaces single backslashes with double ones (and backwards) automatically. Just tell your less techy colleagues not to modify parameters directly in parameter string but double click on parameters section and edit them in Operation Parameters dialog.



    I think the best solution for you is in using KDT/Project/Suite variables for your path definitions.



    I wrote function which posts parameter passed into TC log:





    function getFileName( pPathAndFile )

    {

      Log.Message( pPathAndFile );

      return;

    }



     

    This function was called from KDT passing constant, KDT parameter and KDT variable.

    See attached screenshots.

3 Replies

  • Hi Steve.



    I think you won't face problems with passing backslahed strings into your functions from KDTs.



    I played passing KDT variable, KDT parameter and constant into JScript function: variable and KDT parameter came thru without any modifications. As for constant parameter, TC replaces single backslashes with double ones (and backwards) automatically. Just tell your less techy colleagues not to modify parameters directly in parameter string but double click on parameters section and edit them in Operation Parameters dialog.



    I think the best solution for you is in using KDT/Project/Suite variables for your path definitions.



    I wrote function which posts parameter passed into TC log:





    function getFileName( pPathAndFile )

    {

      Log.Message( pPathAndFile );

      return;

    }



     

    This function was called from KDT passing constant, KDT parameter and KDT variable.

    See attached screenshots.

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Steve,



    It looks like you are developing using JScript. If my guess is correct, then it is not a problem of TC, but a JScript's requirement that all backslaches must be doubled to be treated as a backslach but not as the escape symbol.

    The same is true for a lot of other languages, C\C++ for example (though there you can prepend the string with the L modifier. I never heard that the similair modifier exists in JScript, but I am not an expert with it.).
  • fayrehouse's avatar
    fayrehouse
    Frequent Contributor
    Thanks Andrey - seems TC has some clever "non-tech-proofing" going on :)