cancel
Showing results for 
Search instead for 
Did you mean: 

Testcomplete BDD Step definitions script dropping leading zero parameter

SOLVED
New Contributor

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

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Testcomplete BDD Step definitions script dropping leading zero parameter

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)
});

4 REPLIES 4
Community Hero

Re: Testcomplete BDD Step definitions script dropping leading zero parameter

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.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
New Contributor

Re: Testcomplete BDD Step definitions script dropping leading zero parameter

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.

Re: Testcomplete BDD Step definitions script dropping leading zero parameter

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)
});

Highlighted
Community Hero

Re: Testcomplete BDD Step definitions script dropping leading zero parameter

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


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
New Here?
Join us and watch the welcome video: