magento2-cypress-testing-suite
magento2-cypress-testing-suite copied to clipboard
Add Mailosaur to tests
For some tests like reset password nieuws, newsletter subscription, order confirmation etc mails need te be received and read. For this purpose Mailosaur can be used. A mailosaur API-key and account will be needed, the API-key needs to be added to the cypress.json "env" object or to a cypress.env.json file. And the serverId needs to be added to the tests where mailosaur is used.
// cypress.json
"env": {
"MAILOSAUR_API_KEY": "some-hash"
}
// sometest.spec.js
const serverId = 'SERVER_ID';
const testMail = `something@${serverId}.mailosaur.net`;
cy.mailodaurGetMessage(serverId, {
sentTo: testEmail
}).then(email => {
// Do stuff
})
- [ ] Install mailosaur
- [ ] Make sure cypress can read sent mails
- [ ] Make sure it is optional since it requires an extra dependency
Tests
- [ ] A confirmation email will be sent after placing the order
- [ ] If payment is made an invoice will be sent
Example:
it('can receive a confirmation mail that an order has been placed', () => {
// TODO: implement mailosaur
})
it('can receive an invoice through the mail when a payment is completed', () => {
// TODO: implement mailosaur
})
Will not work when testing locally and also not on our testing site, because of the k8s setup. Needs to use a different solution than our current testing setup.
Another interesting solution might be mailhog - it has an api and you can host it locally in a docker container.
@kolaente yes we use that locally and that works fine, but when running the tests in a CI/CD situation it's limited. Using Mailosaur will enable us to inspect the emails later when something went wrong.
@peterjaap , I currently try to set up our CI/CD integration for the tests.
And like you wrote, for the customer test, where the password is changed, an email is sent.
Unfortunately, I always get the error Unable to send mail: Unknown error in /opt/atlassian/pipelines/agent/build/vendor/laminas/laminas-mail/src/Transport/Sendmail.php:313
I assume, that is related to the fact, that in my pipeline docker container there is no way of sending out any mails.
How do you solve that currently in your CI/CD setup?
@norgeindian I haven't run in that yet, maybe because we generally use mageplaza/module-smtp to send mails with and we configure that to use some SMTP. Magento core now supports SMTP as well since a recent version. It won't rely on sendmail in that case.
@peterjaap , thanks for this amazingly fast reply. Good idea, that is surely the best way. I included mailhog now and set up a similar extension to use the mailhog SMTP port. That seems to work.