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.2] Add within() method to InteractWithPages #12201

Merged
merged 1 commit into from
Feb 16, 2016

Conversation

sileence
Copy link
Contributor

@sileence sileence commented Feb 7, 2016

I have needed this several times when writing tests for complex markups.

This method allows to narrow the test assertions or actions to specific areas of the web page.

For example, you have 2 links with the same text in the same page, but you want to make sure you click the one inside the content area:

        <header>
            <a href="link1">Link</a>
        </header>
        <div class="container">
            <a href="link2">Link</a>
        </div>
    $this->within('.container', function () {
        $this->seeLink('Link')
                ->click('Link');
        });
    });

Same if you want to make sure you see several texts / elements within a certain area of the page (see tests in the commit).

@sileence sileence changed the title Add within() method to InteractWithPages [5.2] Add within() method to InteractWithPages Feb 7, 2016
@daylerees
Copy link
Contributor

Pretty cool addition. Maybe in the tests check for what happens when the container doesn't exist.

@sileence
Copy link
Contributor Author

sileence commented Feb 8, 2016

@daylerees thank you and good point, it should throw an exception.

@taylorotwell
Copy link
Member

Don't you technically need a subcrawler stack in case you have nested within calls?

@sileence sileence force-pushed the feature/5.2/within branch 2 times, most recently from 22a8b14 to d29ef82 Compare February 14, 2016 21:40
@sileence
Copy link
Contributor Author

@taylorotwell added support for nested within calls

@@ -18,7 +19,7 @@
*
* @var \Symfony\Component\DomCrawler\Crawler
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@var array maybe ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 That was fast !

@sileence sileence force-pushed the feature/5.2/within branch 2 times, most recently from e4f6fd3 to 6fb689b Compare February 14, 2016 23:16
@sileence
Copy link
Contributor Author

@lucasmichot thank you. Docblocks fixed.

@GrahamCampbell
Copy link
Member

Surely the change to that protected property is a massive breaking change for people?

@sileence
Copy link
Contributor Author

@GrahamCampbell only if they are creating their own test methods. But let me use sub crawler again.

@GrahamCampbell
Copy link
Member

Ping @crynobone.

@sileence
Copy link
Contributor Author

Ok done, if someone is using the protected property $crawler directly, it will work like before. If someone wants to use within with custom test methods, they'd need to use getCrawler() instead :)

@taylorotwell taylorotwell merged commit 9dad77c into laravel:5.2 Feb 16, 2016
@taylorotwell
Copy link
Member

Thanks. Can you PR some docs for this?

@sileence
Copy link
Contributor Author

I'll do! Thank you @taylorotwell

@nowak-ninja
Copy link

nowak-ninja commented Apr 18, 2016

Hey guys. I just noticed API says that within() method should return instance of $this but actually it doesn't so there is no way to continue with fluent interface after using within() method: https://github.com/laravel/framework/blob/5.2/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php#L213

@sileence
Copy link
Contributor Author

@Flashek I'll solve that issue, thank you.

@sileence
Copy link
Contributor Author

done #13200

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.

6 participants