jeudi 25 avril 2019

How to run multiple instances of the same test with different data

What I'm using:

  • PHP
  • Codeception
  • Chromedriver

What I'm trying to achieve

I have done a single test for a web application. This test logs in with username:password and answers forms. What I want is to test how much resources this webapp takes with a heavier load of users so I need a way to run the same test multiple times with different username:password from an array.

My intention is to control everything from command line, so I looked into creating a custom commands in codeception and thought about passing a variable (integer) throught command. I'm mentioning this just to know if this is a viable approach for this.

This is the code for the test I have right now:

public function loginSuccessfully(AcceptanceTester $I)
    { 


        $I->amOnPage('');
        $I->wait(2);
        $I->fillField('username','008C108');
        $I->wait(1);
        $I->fillField('password','8706405');
        $I->wait(2);
        $I->click('Login');


        $I->wait(2);
        $I->click('//*[@id="Proceed"]');

        $I->wait(2);
        $I->click('//*[@id="pCheckbox"]/span');
        $I->wait(1);
        $I->click('//*[@id="Proceed"]');

        $I->wait(2);
        $I->click('//*[@id="Proceed"]');

        $I->wait(2);
        $I->click('//*[@id="pCheckbox"]/span');
        $I->wait(1);
        $I->click('//*[@id="Proceed"]');

        $I->wait(2);
        $I->click('//*[@id="Proceed"]');

        $I->wait(2);
        $I->click('//*[@id="pCheckbox"]/span');
        $I->wait(1);
        $I->click('//*[@id="Proceed"]');
        $I->wait(1);

        //takes the number of questions
        $numberOfQuestions = $I->grabTextFrom('//*[@id="yui-main"]/div/table/tbody/tr[3]/td[1]');



        //start exam
        $I->waitForElementNotVisible('//*[@id="oleWaitMessage"]', 200);
        $I->wait(2);



        for ($i=$numberOfQuestions; $i > 1 ; $i--) { 

            $I->wait(1);
            //Click answer
            $I->waitForElement('//*[@id="rb_0"]', 30);
            $I->wait(1);
            $I->click('//*[@id="rb_'.rand(0,2).'"]');
            $I->wait(1);


            //click next
            $I->waitForElementClickable('//*[@id="oleNextItemBtn"]', 30); // secs
            $I->click('//*[@id="oleNextItemBtn"]');
            }


            $I->wait(1);
            //Click answer
            $I->waitForElement('//*[@id="rb_0"]', 30);
            $I->wait(1);
            $I->click('//*[@id="rb_'.rand(0,2).'"]');
            $I->wait(1);

            //submits the exam
            $I->waitForElement('//*[@id="oleSubmitBtn"]', 30);
            $I->click('//*[@id="oleSubmitBtn"]');
            $I->wait(1);
            $I->waitForElement('//*[@id="yui-gen0-button"]', 30);
            $I->click('//*[@id="yui-gen0-button"]');
}

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire