Is there a way to have assertPathIs() ignore part of the url?

Charlie :

While making a Laravel Dusk test function, I am trying to check the path in my application. However the URL in my application changes, depending on the user or what they are looking at (e.g. /Test/123/testing: in this case the 123 could be any combination of numbers.)

Is it possible to ignore the middle portion?

$this->browse(function (Browser $browser) {
    $browser->loginAs('[email protected]')
            ->visit('/test')
            ->assertPathIs('/test')
            ->assertSee('LinkText')
            ->clickLink('LinkText')
            ->assertPathIs('/test/(CanBeAnything)/testing');
});
miken32 :

Taking a look at the code we can see a regular expression match is actually being performed, after the text is run through preg_quote():

$pattern = str_replace('\*', '.*', preg_quote($path, '/'));

This means that you can do a wildcard search by using *, so this should work:

$this->browse(function (Browser $browser) {
    $browser->loginAs('[email protected]')
            ->visit('/test')
            ->assertPathIs('/test')
            ->assertSee('LinkText')
            ->clickLink('LinkText')
            ->assertPathIs('/test/*/testing');
});

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=220252&siteId=1