Adding counter that increments automatically in BDD scripts
Hi all,
My bdd test structure is as below:
Scenario
Given ...
When ..
Then ...
Scenario
Given ...
When ..
Then ...
and so on...
In every 'Then' in the Gherkin above, I have an attached function that includes Assertion (Checkpoints and Errors) for that particular scenario.
I need to add Test Case number with each checkpoint but looking for the way that increments the count automatically in each checkpoint. For example, Scenario 1 should have a checkpoint message ("Test Case 1 Passed") and similarly, the other scenarios will have 2, 3, 4 till the last scenario. Finally, the test log will have all the checkpoint with the sequence of test case numbers.
The BDD style lets you reuse any Gherkin step which is same for 'Then' as well. If I have Test Case 1 in one 'Then' function then if that function is reused by any other scenario the Test Case count conflict. Is there any way we can implement dynamic counter or something that will help me store test case numbers in the test log? I am using JavaScript.
Thanks in advance!
Hi TestQA1
Could you create a Project Variable, then write a basic increment method to increment and log the count each time it is called in the Then step?
For example :
function counter(){ Project.Variables.TestCount= Project.Variables.TestCount++ Log.Message("TestCase " + Project.Variables.TestCount+" has completed") }