Forum Discussion

chris2pher's avatar
chris2pher
New Contributor
6 years ago

Testcomplete BDD Step definitions script dropping leading zero parameter

I am using Testcomplete 14's BDD Scenario files to write a scenario such as..

 

Given a window is open

When the 0111 number, "name" name, and 01234 id are entered

Then the fields are populated

 

This When scenario is generated into a function:

When("the {arg} number, {arg} name, and {arg} id are entered", function (number, name,  id) {

            //code to set the inputs

            log.message(id);

 

}

 

The id variable is only being set to 1234 instead of receiving 01234. I have attempted to set the parameters to strings inside the scenario files also, there is no change. 

 

Are there any ideas on how to fix this?

 

Thanks,

Chris

  • You can use a step:
    When the "0111" number, "name" name, and "01234" id are entered

    and a step handler:
    When("the (.*) number, (.*) name, and (.*) id are entered", function (param1, param2, param3){
    param1 = param1.match(/"(.*)"/)[1];
    param2 = param2.match(/"(.*)"/)[1];
    param3 = param3.match(/"(.*)"/)[1];
    Log.Message(param1)
    Log.Message(param2)
    Log.Message(param3)
    });

  • IStaroverov's avatar
    IStaroverov
    SmartBear Alumni (Retired)

    You can use a step:
    When the "0111" number, "name" name, and "01234" id are entered

    and a step handler:
    When("the (.*) number, (.*) name, and (.*) id are entered", function (param1, param2, param3){
    param1 = param1.match(/"(.*)"/)[1];
    param2 = param2.match(/"(.*)"/)[1];
    param3 = param3.match(/"(.*)"/)[1];
    Log.Message(param1)
    Log.Message(param2)
    Log.Message(param3)
    });

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Awesome, IStaroverov  Somehow i guessed it had something to do with regular expressions to get it to work.  Thanks for the assist!

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Script code automatically tries to match the value to the proper data type.  Since it looks like a number, it's being treated like anumber and the leading zeros are being stripped.

     

    Change to

     

    Given a window is open

    When the "0111" number, "name" name, and "01234" id are entered

    Then the fields are populated

     

    This will force the values to be a string and you should be able to get the leading zero.

    • chris2pher's avatar
      chris2pher
      New Contributor

      Thanks for replying!

       

      In my first post I mentioned: " I have attempted to set the parameters to strings inside the scenario files also, there is no change." 

       

      What you have suggested I have tried =(

      I have tried it a second time as a sanity check and the parameter is still getting 1234 instead of 01234.