How to impersonate login users for your automation tests?

The following shows how to impersonate user logins that your website application contains for automated testing purposes.

This allows you to also test those parts of your web application that are login protected, which probably is the largest part of your website.

This also allows you to test personalised content that is different for each login <user>.

So for example, you could test for web page content that you would only expect a certain application <user> to see, but not any other login <user> or an anonymous web user.

<?xml version="1.0" encoding="UTF-8" ?>
<testsuite>
    <logins title="Let each test step execute in the context of an authenticated user" cookiedir="{TEMPDIR}">
        <user label="Homer Simpson">
            <url>http://automateyourtests.com/demo_application/wp-login.php?testcookie=1</url>
            <post><![CDATA[log=homer&pwd=doh]]></post>
            <notcontains><![CDATA[<div id="login_error">]]></notcontains>
        </user>
        <user label="Charlie Brown">
            <url>http://automateyourtests.com/demo_application/wp-login.php?testcookie=1</url>
            <post><![CDATA[log=charlie&pwd=lucy]]></post>
            <notcontains><![CDATA[<div id="login_error">]]></notcontains>
        </user>
    </logins>
    <userstory title="Impersonate distinct login users, so that each of them can view their own personalised web page content">
        <scenario title="View the Wordpress dashboard whilst impersonating TWO distinct login users">
            <step title="Impersonate Homer Simpson">
                <user>Homer Simpson</user>
                <url>http://automateyourtests.com/demo_application/wp-admin/</url>
                <contains>Howdy, Homer Simpson</contains>
            </step>
            <step title="Impersonate Charlie Brown">
                <user>Charlie Brown</user>
                <url>http://automateyourtests.com/demo_application/wp-admin/</url>
                <contains>Howdy, Charlie Brown</contains>
            </step>
        </scenario>
    </userstory>
</testsuite>