Acceptance Test with URL redirection

Asked

Viewed 269 times

0

Hello I’m trying to generate a acceptance test to my login page using codeception and Yii2, only that the problem is that after the login the user is redirected to the main page and there the user, already logged in, visualizes a welcome message. I’ve tried several ways but I couldn’t go on. Someone can help me! Thank you.

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.
  • I didn’t quite understand your question, it should NOT be redirected to the index.php page after logging in, is that right? If so, is this statement $I->amOnPage('/index.php') not wrong? because you redirect it there after it clicks on login.

  • Thanks for the feedback @Pauloroberto. I need to check if a condition appears after the user login, and after this login the same is redirected to the home page. Actually I am not able to proceed post login. Because any attempt it always returns to the same login page. I don’t know if there is a need to store this/Session login cookie in some variable before, or if clicking on the login codeception should subunderstand and continue on the secure system page.

  • I do not know this framework that you are using to check some condition at least with Selenium Webdriver, I use an assertion or an implicit or explicit wait, check if it is not missing this in your script and then the treatment of Session.

  • I am deploying Selenium at the moment, I believe the problem is solved since in the current format I have no way to manipulate this waiting time. Perhaps this delay in login will be resolved. If successful, put the answer here, but thank you.

  • If you need help with Selenium, post a new question there!

  • That’s right, that’s right! Thank you.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.