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
Solved! Go to Solution.
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)
});
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.
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.
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)
});
Awesome, @IStaroverov Somehow i guessed it had something to do with regular expressions to get it to work. Thanks for the assist!
Subject | Author | Latest Post |
---|---|---|