Service Virtualization

  • 1.  Store step request of "Send email Step"

    Posted Jan 08, 2018 05:34 AM

    Scenario:

    The "Send email step" does not create a response of its own as it sends the request (Your HTML Email body) to the SMTP server and the server forwards it to the respective machine(to-List and cc-List).

     

    Requirement:

    I want to store the step request(the HTML email body) that is in the send email step (and gets forwarded to the SMTP server).

     

    Challenge:

    The content that comes in the send email step is generated dynamically and thus I can not store it before sending.

    One thing that I can do is adding a store step response just before the send email step and add a filter "Store step response" on the send email step, but, I have a lot of test cases and a total of around 200+ email steps so adding an output log message step before every send email step is a bit hectic job.

     

    Please help.



  • 2.  Re: Store step request of "Send email Step"
    Best Answer

    Posted Jan 08, 2018 12:20 PM

    I wonder if you could use a Scripted Assertion on the Send Email step to access the content of step instance in TestExec and save the value of the Message into a property?

     

    The following is an untested hack, but I wonder if your Send Mail Step Scripted Assertion could:

    // Access and Print Subject and Message of an Email
    import com.itko.lisa.glass.SendEmailStep;
    import java.util.Map;

    // Replace this with the exact name of the Send Mail Step in the Test
    String testStepName = "Send Email Step";

    // Locate the testStepName in the current Test instance
    // Access the properties that were set up on Send Mail Step
    Map m = testExec.TestCase.getNode( testStepName ).getProperties();

    // Get a property or properties from the Map. Other properties are

    // m.get("From")   m.get("To")   m.get("Cc")   m.get("Bcc")

    // use parseInState to replace {{ }} notations in the content
    String subject = testExec.parseInState( m.get("Subject") );
    String message = testExec.parseInState( m.get("Message") );

     

    // Store Step Message in a property
    testExec.setStateValue( "fl_emailMessage", message );
    testExec.setStateValue( "fl_emailSubject", subject );

     

    // Or, output a log message for the desired subject and message content
    _logger.info("Subject is: {} and Message is: {}", subject, message );

     

    // Or, Add Java file io to save the message to the file system with a unique key


    // Set the If False then Fail the Test
    // Return True so false is never executed
    return true;

     

    The [String testStepName = "Send Email Step"] above is a reference to the name of the step in your test case.

    Note: Adding a Filter on this step to perform some action on fl_emailMessage will not work since Filters are executed prior to Assertions.