Forum Discussion

rmrosen6's avatar
rmrosen6
Occasional Contributor
2 years ago

How to Send Emails after TestComplete runs on Pipeline conditional on Pass Percentage

Hi,

 

We have TestComplete setup on our Azure Dev-Ops Pipeline.  Once TestComplete has run, we are interested in seeing if there is a way to send emails to specific email addresses but only if the TestComplete Pass Percentage is below a certain level.  What would be the best way to do this if possible?

 

Thanks

 

Robert

2 Replies

  • Kitt's avatar
    Kitt
    Regular Contributor

    I believe you can do this by tweaking one or more of the pipeline task options.  I would suggest adding a SendEmail task (from Azure marketplace) after the VS Test Task and adjusting the task settings by expanding the 'Control Options' > select Enable > then set the 'Run this task' option to your desired option - ie: if all test succeed, if pervious task fails, or you own custom condition [Azure reference] .

     

    Personally, I've only sent email alerts from within TestComplete when certain failures occur, so I can't speak to the flexibility of the Azure task settings. However using the onError event handler and the SendMail [TestComplete reference] method you can create some logic that can define when to send an email and to whom. For example, if certain 'critical' errors occur or a certain message is posted to the log, or an error occurs in a certain environment, then send an email:

     

    In this example I set a project suite variable at the start of each test case that says what area I'm testing and which environment I'm in. If an error occurs in a certain area I send out an email with basic reference info and a screenshot attached. Additionally, it handles the environment I'm in by sending an email to only me if it's in QA or to the larger distribution group if the error occurs in UAT. 

     

    ```

    function EventControls_OnLogError(Sender, LogParams)
    {

    // envt handler
    var page = Sys.Browser("*").Page("*");
    switch(ProjectSuite.Variables.Environment) {
    case "QA":
    var alertRecipient = "me@company.com";
    break;
    case "STG":
    var alertRecipient = "group@company.com";
    break;
    }

    /* Payment failure alert OR check for certain log message with: if (equal(LogParams.MessageText, "Send email when this message is written to the log")) */if (equal(ProjectSuite.Variables.ServiceType, "Payments")) {
    LogParams.Locked = false;
    LogParams.Priority = pmHighest;
    LogParams.FontStyle.Bold = true;
    LogParams.FontColor = clSilver;
    LogParams.Color = clRed;

    // send alert email w/screenshot
    if (CommonMAIN.SendEmail("noreply@sender.com", alertRecipient, "Portal Automation Failure",
    "FX Failure in " + ProjectSuite.Variables.Environment + " - " + aqTestCase.CurrentTestCase.Name
    + " ERROR: " + LogParams.MessageText, Log.Picture(Sys.Desktop.Picture(), "Image of the error"))) {
    Log.Checkpoint("| Alert Email Sent |");
    page.Refresh();
    }
    else {
    Log.Warning("WARNING: alert email unsuccessful");
    }
    }

    }

    ```