Forum Discussion

jaward916's avatar
jaward916
Occasional Contributor
5 years ago

Javascript String Interpolation

Is Javascript string interpolation allowed/recognized in TestComplete (14.70 fully patched)?

The reason I ask is when I'm logging some values I much prefer interpolation to concatenation.

i.e. I would like to use:

Log.Message(`Found match, group ${i}: ${m[i]}`);

instead of:

Log.Message("Found match, group " + i + ":" + m[i]);

both are valid JS and work on online prototypers, however the former (interpolation) results in Syntax Errors on the ` (backtick).

Does anyone know if this is a limitation in TestComplete or whether there's a syntax difference I need to be aware of, I couldn't find any documentation for this!

  • Wait a minute...

    I did some digging, and it would seem this project is in fact JScript and not JavaScript (which also explains another issue I nearly put on here).

    I have just run the Javascript conversion (a great feature) and I can now write as I expect. at least I've only wasted 2 hours ğŸ™ƒ

  • Wamboo's avatar
    Wamboo
    Community Hero

    This works wery well for me:

     

    function testInterpolation() {
      var i = "i_value";
      var arr = ["value1", "value2"];
      
      Log.Message(`This string contains that two variables: first one -> ${i} and second one -> ${arr[1]}`);
    }

     

    I'm using the latest version of TestComplete.

    • jaward916's avatar
      jaward916
      Occasional Contributor

      Thanks, Wamboo, so I just pasted this straight into my test script, and straight away it has the red x with a syntax error:

       

      • jaward916's avatar
        jaward916
        Occasional Contributor

        Wait a minute...

        I did some digging, and it would seem this project is in fact JScript and not JavaScript (which also explains another issue I nearly put on here).

        I have just run the Javascript conversion (a great feature) and I can now write as I expect. at least I've only wasted 2 hours ğŸ™ƒ