Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.0] Fix with() and page assertions #625

Merged
merged 1 commit into from
Mar 9, 2019

Conversation

staudenmeir
Copy link
Contributor

@staudenmeir staudenmeir commented Mar 8, 2019

Using with() in combination with a page can break tests:

class TestPage extends Page
{
    public function assert(Browser $browser)
    {
        $browser->assertSee('Page Title');
    }
}

$this->browse(function (Browser $browser) {
    $browser->visit(new TestPage)
        ->with('.prefix', function (Browser $browser) {
            // 
        });
});

Dusk executes the page's assertions in visit() and in with(), but the latter one doesn't always work. In this example, the page title is not available inside the .prefix scope.

on() should only execute the assertions when being called directly or from visit(), but not when being called from with().

Fixes #618.


A more elegant but breaking refactoring for Dusk 6.0 could look like this:

public function on($page, $assert = true)
{
    $this->page = $page;

    // Here we will set the page elements on the resolver instance, which will allow
    // the developer to access short-cuts for CSS selectors on the page which can
    // allow for more expressive navigation and interaction with all the pages.
    $this->resolver->pageElements(array_merge(
        $page::siteElements(), $page->elements()
    ));

    if ($assert) {
        $page->assert($this);
    }

    return $this;
}

public function onWithoutAssert($page)
{
    return $this->on($page, false);
}

@taylorotwell taylorotwell merged commit 7c19a13 into laravel:5.0 Mar 9, 2019
@staudenmeir staudenmeir deleted the page-assert branch March 9, 2019 20:06
staudenmeir added a commit to staudenmeir/dusk that referenced this pull request Mar 12, 2019
@staudenmeir staudenmeir mentioned this pull request Mar 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dusk page assertions don't seem to be working with scopes
3 participants