symfony / panther

A browser testing and web crawling library for PHP and Symfony
MIT License
2.91k stars 213 forks source link

Selector valid in browser but not in test #571

Open truckee opened 1 year ago

truckee commented 1 year ago

In an attempt to use assertSelectorWillNotContain in a test of a change in data value I used $this->assertSelectorWillNotContain("document.querySelector('#mealid').getAttribute('data-rte')", $rteCount); In a Firefox console the command document.querySelector('#mealid').getAttribute('data-rte') returns an integer. In a functional test, however, I get the error Given css selector expression "document.querySelector('#mealid').getAttribute('data-rte')" is invalid. Is there a syntax that will be acceptable in both a console and a test

Edit: Identical results are obtained with the equivalent selector document.querySelector('#mealid').dataset.rte. Even giving up hiding the value that changes and doing something as simple as document.querySelector('.rte') I get invalid selector. Here's the test:

use Symfony\Component\Panther\PantherTestCase;

class MealTest extends PantherTestCase
{
    public function testFood()
    {
        $client = static::createPantherClient();
        $client->followRedirects();
        $client->request('GET', 'http://diet/meal');
        $crawler = $client->clickLink('edit');
        $rteCount = $crawler->filter('.rte')->text();
        $client->executeScript("document.querySelector('#meal_pantry td').click()");
        $this->assertSelectorWillNotContain("document.querySelector('.rte').textContent", $rteCount);
    }

}