Forum Discussion

hannecroonen's avatar
hannecroonen
Contributor
4 years ago

Filter on tag of scenario outline example

Hello guys, 

 

A (hopefully) quick question for you:

 

I am trying to use the BDDHooks file to print the time needed for running 1 scenario into an excel file.

This is all working perfectly but the problem is I am using a couple of scenario outlines with different examples and

I split the examples into different blocks to all give them their own tag (@smoke and @happyUnhappy eg). Now my goal is to only print the timing of the one example with the tag '@smoke' but I cannot seem to find a way to filter by example tag.

 

I know there's this page https://support.smartbear.com/testcomplete/docs/bdd/tags.html which explains how to get all tags of a certain feature or scenario but there's none to get the tags from a scenario outline. I only seem to be able to retrieve the tags for the entire outline and not for 1 example.

 

eg; I only need to save the time for the example with @smoke on top:

@smoke
Examples:

|a|b|c|

|1|2|3|
@happyUnhappe
Examples:

|d|e|f|

|4|5|6|

 

I hope you guys understand and you can help me in my search 🙂

 

Thanks!

 

  • Ah, I see. This is going to be a bit tricky in any automation framework since the tag isn't necessarily part of the input data for whatever routine is executed. There is a way to capture that in TestComplete however, using the Project.TestItems.Current object. 

    Below is a way of evaluating a tag for a predetermined value and setting a temporary project variable of Boolean type, based on the tag itself;

     

     

    Given("some precondition", function (){
      Log.Message(Project.TestItems.Current.ElementToBeRun.Caption);
      Log.Message("Store The Timings? " + aqString.StrMatches("examples2", Project.TestItems.Current.ElementToBeRun.Caption)); 
      Project.Variables.Exporttimings = aqString.StrMatches("examples2", Project.TestItems.Current.ElementToBeRun.Caption);
      Log.Message("Executing First Step");
      /*
       * Calls to Project.KeywordTests tests or Script functions go here
       */
    });

     

     

      ( I used JavaScript, but the concept would be the same for any of the supported languages in TestComplete ). 

    If you're using an After Scenario Hook that can evaluate the Project Variable, then you can perform the timing export just for that particular tag;

     

     

     

    AfterScenario(function (scenario){
      // Perform some action after executing a scenario, for example:
      Log.Message("The " + scenario.Name + " scenario has been executed");
      Log.Message("Return The Timings? " + Project.Variables.Exporttimings ); 
      if (Project.Variables.ExportTimings){
        exportTimings(Project.Variables.TimingData );
      }
    })

     

     

     

    This results in a Test Log that looks like this;

    and if we use the other tag, our test log looks like this;

    Do you think that may handle your requirements? 


  • dermotcanniffe's avatar
    dermotcanniffe
    SmartBear Alumni (Retired)

    Hi, 
    This should be possible. I tried running the following Gherkin Feature file specifically with either one tag or the other;

     

    Feature: TestingTags
    
      Scenario Outline: A description of your business scenario
        Given some precondition
        When an "<action>" is performed
        Then validate "<result>"
        
    
      @examples1
      Examples:
      |action|result|
      |alice|result1|
      |bob|result2|
      |cariad|result3|  
    
      @examples2
      Examples:
      |action|result|
      |dermot|result4|
      |eve|result5|
      |fran|result6|

     

     

    I set up a Test Item for each tag in my Execution plan;

    Upon executing the Test Item for either tag, e.g. @example2, TestComplete used only the rows that corresponded with that tag. 

    So, it should work in your use case, if you create a Test Item based on a tag or tag expression. 
    Hope that helps.

    • hannecroonen's avatar
      hannecroonen
      Contributor

      Hi,

       

      First of all thanks for the response! But this is something I already knew how to do.

      Problem is I am running complete scenario's because I need them all to pass but I only need the timing from the examples using 1 specific tag.

       

      So using your script I would run all Scenario Examples (both examples1 and examples2) but I only need to save the timings from the examples using the examples1-tag. This is something that is not possible I think.

      • dermotcanniffe's avatar
        dermotcanniffe
        SmartBear Alumni (Retired)

        Ah, I see. This is going to be a bit tricky in any automation framework since the tag isn't necessarily part of the input data for whatever routine is executed. There is a way to capture that in TestComplete however, using the Project.TestItems.Current object. 

        Below is a way of evaluating a tag for a predetermined value and setting a temporary project variable of Boolean type, based on the tag itself;

         

         

        Given("some precondition", function (){
          Log.Message(Project.TestItems.Current.ElementToBeRun.Caption);
          Log.Message("Store The Timings? " + aqString.StrMatches("examples2", Project.TestItems.Current.ElementToBeRun.Caption)); 
          Project.Variables.Exporttimings = aqString.StrMatches("examples2", Project.TestItems.Current.ElementToBeRun.Caption);
          Log.Message("Executing First Step");
          /*
           * Calls to Project.KeywordTests tests or Script functions go here
           */
        });

         

         

          ( I used JavaScript, but the concept would be the same for any of the supported languages in TestComplete ). 

        If you're using an After Scenario Hook that can evaluate the Project Variable, then you can perform the timing export just for that particular tag;

         

         

         

        AfterScenario(function (scenario){
          // Perform some action after executing a scenario, for example:
          Log.Message("The " + scenario.Name + " scenario has been executed");
          Log.Message("Return The Timings? " + Project.Variables.Exporttimings ); 
          if (Project.Variables.ExportTimings){
            exportTimings(Project.Variables.TimingData );
          }
        })

         

         

         

        This results in a Test Log that looks like this;

        and if we use the other tag, our test log looks like this;

        Do you think that may handle your requirements?