dimanche 31 mars 2019

assert every selected div element

I want to test every selected div, but it only test the first select element.

This is DOM:

<div>
    <div>
        <div>
            <div class="select" [datetime="20190101"]>
                
            </div>
        </div>
    </div>

    <div>
        <div>
            <div class="select" [datetime="20190102"]>
                
            </div>
        </div>
    </div>

    <!-- and many of them -->
</div>

This is my testing:

/** @test */
public function every_data_should_match()
{
    $this->browse(function (Browser $browser) {
        $browser->visit('/page');

        $browser->whenAvailable('div.select', function ($div) {
            $datetime = $div->attribute('', 'datetime');
            $expected_data = User::where('datetime', $datetime)->first()->data;

            $data = $div->getAttribute('outerHTML');

            $this->assertSame($expected_data, $data);
        }
    }
}

There should have many assertions, but there is only one, how to fix so the testing would iterate every div.select?

Each .select belongs to different parent, so I couldn't use .select:nth-child(n).

Aucun commentaire:

Enregistrer un commentaire