Puppetry
3.2.2
3.2.2
  • Welcome Puppetry
  • Getting Started
  • Project
  • Suite
  • Group
  • Target
    • Simple Target
    • iFrame Target
    • ShadowDOM Target
    • Chained Target
    • Shared Target
  • Test Case
  • Test Step / Action
    • Page Commands
    • Page Assertions
    • Target Commands
    • Target Assertions
  • Managing Records
  • Snippets
  • Running tests
    • Interactive Mode
    • Troubleshooting
  • Test Report
  • Export
    • Exporting as Jest Project (CI-friendly)
    • Exporting as Test Specification
  • Settings
  • Template Expressions
  • Testing Techniques
    • Testing Dynamic Content
    • Exhaustive Testing
    • Performance Testing
    • Visual Regression Testing
    • Testing Shadow DOM
    • Testing Google Analytics tracking code
    • Testing Chrome Extensions
    • Testing REST API
    • Mocking HTTP/S Requests
    • Testing Transactional Emails
      • Example with Restmail.net
      • Example with Mailinator
      • Example with IMAP bridge
      • Example with Google API
    • Testing Forms with Captcha
  • Version Control
  • Tips and Tricks
    • Embrace the Power of CSS
  • Command API
  • Test Application
Powered by GitBook
On this page

Was this helpful?

  1. Testing Techniques
  2. Testing Transactional Emails

Example with Mailinator

PreviousExample with Restmail.netNextExample with IMAP bridge

Last updated 5 years ago

Was this helpful?

Similar to we need user name alias to use with the REST API. so we modify the first steps in the case case as follows:

Following we need to set URL for page.assignVarRemotely:

https://api.mailinator.com/api/inbox?token={{ env( "EID_SECRET" ) }}&to={{ TEST_USER_ALIAS }}

So we alternate the default fetch logic of page.assignVarRemotely as follows:

async ( url ) => {
   const inbox = await ( await fetch( url ) ).json(),
         msgHead = inbox.messages
           .reverse()
           .find( msg => msg.subject.includes( "Account Validation" ) ),
         fulMsg = await ( await fetch( `https://api.mailinator.com/api/message?token=YourAPIToken&id=${ msgHead.id }` ) ).json();
  return fulMsg.data.parts.map( p => p.body ).join();
}

Thus the command will read the listing and find a message with subject containing "Account Validation" string. Then it retrieves and returns the raw body of the matching mail. So the parse function may look like:

( text ) => {
    const re = /(http\:[^\"]+4567\/con[^\"]+)/g,
              res = text.match( re );
    return res ? res[ 0 ].replace( "=\r\n", "" ) : null;
}

However unlike doesn't allow to receive last message content with a single request. So we need to take advantage of optional request function command parameter:

Mailinator
Restmail.net
Restmail.net
Mailinator API
Assigning TEST_USER_ALIAS and TEST_EMAIL
page.assignVarRemotely configuration for Mailinator (part 1)
page.assignVarRemotely configuration for Mailinator (part 2)