-1

In codeception acceptance testing, how to run/write same test case for many different set of inputs.

Here is my sample acceptance test (I am using page object oncept)

loginCept.php code

$I = new AcceptanceTester($scenario);
$I->wantTo('perform actions and see result');
$I->login($I,$m);  

Acceptance.php file

class Acceptance extends \Codeception\Module
{
    public function login($I)
    {
        $I->amOnPage(login::$loginIndex);
        $I->wait(2);
        $I->fillField(login::$userName,"test@gmail.com");
        $I->fillField(login::$password,"test");
        $I->click(login::$submitButton);
        $I->see(login::$assertionWelcome);
        $I->wait(2);
        $I->click(login::$logoutLink);
    }
}                  

How do I run same login with multiple set of inputs in acceptance test.

However, I have tried passing inputs in an array by calling the test case in for loop by passing array values as input parameter. In acceptance.php, multiple set of inputs can be passed using if loop.

This runs the test as only 1 test case with different assertions. But, it runs the test case until it fails for any inputs/assertion. If it fails for any of the assertions, then test case stops executing further & says test case failed.

Rob Forrest
  • 7,329
  • 7
  • 52
  • 69

1 Answers1

0

You can pass parameters through to your login function just as you would with any php function:

loginCept.php code

$I = new AcceptanceTester($scenario);
$I->wantTo('perform actions and see result');
$I->login($I,"test@gmail.com","test");  

Acceptance.php file

class Acceptance extends \Codeception\Module
{
    public function login($I,$username,$password)
    {
        $I->amOnPage(login::$loginIndex);
        $I->wait(2);
        $I->fillField(login::$userName,$username);
        $I->fillField(login::$password,$password);
        $I->click(login::$submitButton);
        $I->see(login::$assertionWelcome);
        $I->wait(2);
        $I->click(login::$logoutLink);
    }
}        

You'd then want to create a separate cept for each aspect of login that you are looking to test.

Edit:

What you're looking for in relation to one test running through a number of assertions, this breaks the conventions of automated testing. Each test (or cept in this case) should only ever test one aspect. For instance in logging in, you might have one for invalid username, invalid password, too many attempts, etc... Then when/if one test fails, you as the developer knows exactly what aspect has failed and which continue to pass. If all the aspects are wrapped up in one test, then you as the developer don't know the full picture until you start to debug.

Rob Forrest
  • 7,329
  • 7
  • 52
  • 69
  • Thanks Rob. But I was wondering any way without creating separate cept for each aspect of login. So I tried using login in a for loop by passing different parameters. In that case my test runs a only 1 test case with different assertions. But test runs only untill it fails for any of the assertions/inputs. If it fails for any inputs in loop, it stops executing further and says test case failed. – Bhavya Rangegowda Sep 15 '15 at 20:27
  • @BhavyaRangegowda, I've edited my answer in relation to this comment. – Rob Forrest Sep 16 '15 at 07:51