0

I am trying to validate and post login action. But the problem occur after login, when the user is redirected to the index page. There is a welcome message shown only for authenticated users. Can someone help me out. I'm using Yii 2 Framework!

use \AcceptanceTester;

class LoginCest
{
    public function login(AcceptanceTester $I)
    {
        $I->am('Login Page');
        $I->wantTo('Login Exists?');
        $I->amOnPage('/index.php?r=site/login');
        $I->see('Title');
        $I->see('User');
        $I->see('Password');
    }

    /**
    * @after login
    */
    public function validLogin(AcceptanceTester $I)
    {
        $I->amOnPage('/index.php?r=site/login');
        $I->fillField('LoginForm[username]', 'username');
        $I->fillField('LoginForm[password]', 'password');
        $I->click('Login');
        $I->amOnPage('/index.php');
        $I->see('Welcome {UserName}!', 'h1');
    }
}

Scenario Steps:
6. I see "Welcome!","h1" <<< FAIL
5. I am on page "/index.php"
4. I click "Login"
3. I fill field "LoginForm[password]","username"
2. I fill field "LoginForm[username]","password"
1. I am on page "/index.php?r=site/login"

FAILURES! Tests: 2, Assertions: 4, Failures: 1.

1 Answers1

1

I think you don't need this "$I->amOnPage('/index.php');" because this does not check current url (for that purpose you should use "$I->seeInCurrentUrl(...)"), but leads you to that url. So what you are actually doing here is refreshing your index page and losing the welcome flash message. I believe all you need is just remove this command, as after clicking on Login button you are already being redirected to main page.

Pavel Bariev
  • 2,546
  • 1
  • 18
  • 21