Warm tip: This article is reproduced from stackoverflow.com, please click
codeception dataprovider

How to use only nth line of DataProvider in Codeception?

发布于 2020-05-02 19:32:26

i am using Codeception for testing. I am using data providers and everything is working well. But i need to be able just say "i need to start only line 1 from data provider", how can i do it?

    protected function pageProviderTest(){
        return[
            ['version' => 1],
            ['version' => 2],
            ['version' => 3],
        ];
    }

    /**
     * @param WebdriverTester $I
     * @dataProvider pageProviderTest
     */
    public function test1(WebdriverTester $I, Example $example){
        $I->see($example['version']);
    }


So for example, now i only want to test if test see "1". Other test i dont want even start.

Questioner
Lukáš Secký
Viewed
17
Lukáš Secký 2020-03-13 18:04

So i find answer. You have to make new Example object and give him parameter which you want to use, so in this situation it will be look´s something like:

private $testingData;

public function __construct()
    {
   $this->testingData = new Example(pageProviderTest[0]); // enter the num of line in field
  }

 protected function pageProviderTest(){
        return[
            ['version' => 1],
            ['version' => 2],
            ['version' => 3],
        ];
    }

    /**
     * @param WebdriverTester $I
     * 
     */
    protected function test1(WebdriverTester $I, Example $example){
        $I->see($example['version']);
    }

  public function startTest(WebdriverTester $I){
   test1($I, $this->testingData);
  }