Zeth
Zeth

Reputation: 2618

Checking if contact form's works (automated testing)

I have a website with a contact formular. It's vital for my business, that I get all messages, that are being sent by this formular. And I've seen SOOO many examples of contact forms breaking due to dependency-updates or script collisions.

So my plan was to make an automated test, that will fill out a contact formular every day, ensuring that there's no errors. And also (and most importantly), checking that the message is received in the other end.

I'm using WordPress Formidable forms, but it's okay, if it's something that needs to be custom made. I've previously used Contact Form 7 with Flamingo, which was good. But the downside was, that if I didn't receive an email, then it failed silently, - and then I could recover non-received messages with Flamingo. And I need to know immidiately, if messages doesn't arrive in my inbox.

Checking the front-end

In order to ensure that the form doesn't break, before the mail was sent, then I'm planning to do it using Nightwatchjs.

Checking that the message is received

This is the part that I'm not sure how to do... Verifying the sending/receiving part.

So if my main e-mail was [email protected], then I was thinking, that if I could setup an extra mail, like [email protected], and then send all mails to both emails, - and then... Ehm... Do something with that?

How do I do this? Or are there any frameworks for this, that will make it easier?

Upvotes: 3

Views: 1694

Answers (1)

Niraj Chauhan
Niraj Chauhan

Reputation: 7900

In your current scenario, there are 3 important things which you should consider while testing.

But before that, don't completely rely upon emails to alert you. Make sure whenever a form is submitted, backend persists the data in some DB and then email is triggered or both can happen parallelly.

Automating UI/functional tests can be time-consuming and also expensive. So I would suggest you break down your testing in two sections.

  1. First can be direct API testing, these tests can contain all business logic & scenarios, like sending invalid/empty fields, XSS, injections, etc. Now, using the persisted data you can assert very easily.
  2. Second can be your functional test cases, you can use puppeteer or selenium, puppeteer is more lightweight and flexible. Just write some basic form filling tests, then login to wp-admin and assert/verify the data.
  3. I would suggest running the above test cases in some UAT or different environment, this will make sure that only your test cases are creating the records in the DB and not someone else. Also using a different environment can benefit you to easily mock your email server or use mailgun API for verifying emails delivery.

Upvotes: 2

Related Questions