Add Randomness to Automated Tests

How should you automate cases that exercise functionality in a variety of ways?

Write several workflow-based functions or methods and randomly inject them in your tests.

It’s important to add an element of randomness in your automated tests. This holds true for both data and operations. For example, use data-driven techniques to switch up the data used by tests.

The example below demonstrates a data-driven approach to testing a login feature.

import { t } from 'testcafe';

fixture `login`
    .page ``;

const testCases = [
        name:     'Valid User',
        email:    'valid@example.fake',
        password: 'pass'
        name:     'Invalid User',
        email:    'invalid@example.fake',
        password: 'fail'

async function performLogin (email, password) {
    await t
        .typeText('#email', email)
        .typeText('#password', password)

for (const user of testCases) {
    test('test ' +, async t => {
        await performLogin(, user.password);

        // Confirm valid user can login.
        await t.expect('#username').eql('Valid User');

        // Confirm invalid user can't login.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s