In my dusk test I want to firstly add and then delete news. Each news has .delete-news class but on the screen I have multiple elements. Each .delete-news class has in it's path data attribute with it's id data-newsid="id". Now the browser does not know which delete-news class it should to click. How should I manage that?
Probably I should take delete-news class with the biggest data-newsid attribute. But I don't know how I should check it.
Currently I'm deleting it like this:
public function testRemoveNews() {
    $this->browse(function ($browser) {
        $browser->visit('/')
                ->press('.delete_news')
                ->press('Yes')
                ->waitForText('News has been deleted!')
                ->press('OK')
                ->assertDontSee('Title of the news');
    });
}
                
If you sorting your news by 'id' desc, maybe you should try 
->press('.delete-news:first') // or :nth-child(1)
or add a dusk attribute to first news element, like dusk="last-news", and call it with:
->press('@last-news')
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With