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" ?>
    <logins title="Let each test step execute in the context of an authenticated user" cookiedir="{TEMPDIR}">
        <user label="Homer Simpson">
            <notcontains><![CDATA[<div id="login_error">]]></notcontains>
        <user label="Charlie Brown">
            <notcontains><![CDATA[<div id="login_error">]]></notcontains>
    <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>
                <contains>Howdy, Homer Simpson</contains>
            <step title="Impersonate Charlie Brown">
                <user>Charlie Brown</user>
                <contains>Howdy, Charlie Brown</contains>

Warning: count(): Parameter must be an array or an object that implements Countable in /home/nemyoe7sj5jr/public_html/wp-includes/class-wp-comment-query.php on line 388