Setting up mail client for browser testing quickly

most people restrict their browser testing within a site. However, with a shopping cart or subscription application for example, the testing should really  end only after the user receives the email as anything could happen between the moment email is sent and received. Email testing can be tricky. How does one automate the process of checking emails and verifying the right email has been sent without too much of a hassle? Well, the trick is to setup an internal mail server and install a HTML capable email client within the test machine.

Here, I’m going to quickly set up my virtual machine to handle sending and receiving of internal mails.

1. Install dovecot bundle

sudo apt-get install dovecot-imapd dovecot-postfix

(When asked to configure postfix, choose “localhost only”. We don’t want to accidentally send email to the outside world)

2. Create a new test user for testing

adduser test

3. Install squirrelmail (Any other web-based client is fine as well). Remember to log in as the test user and set HTML email as the default first.

4. When running the browser test or BDD, use test@localhost.localdomain as user’s email. When logged into squirrelmail, you can then automate the checking and clicking of the test receipt links.


webdriver: testing file download

rather than using complicated functions to try and test file downloads, we can use simple logic like if the download is successful, we should see title A and if download fails, we should see title B. Surely, our system wouldn’t spit out the same page title even if the file doesn’t exists. So using phpwebdriver for example, say I am trying to check if the download link is working in the thankyou page:

// thankyou page
$this->assertEquals(self::$session->element('xpath', '//td[@class="product-name"]/small/a')->text(), "Download file now");
// now click on the download file link.
 self::$session->element('xpath', '//td[@class="product-name"]/small/a')->click();
// wait for a 2 secs for the download now prompt.
// if file exists, then I should see the "Order Received" as part of the page title header.
$this->assertRegExp('/Order Received/', self::$session->title());