Currently the $browser and Browser does not have any auto completion.
$this->browse(function (Browser $browser) {
$browser->visit('/')
->assertSee('Laravel');
});
So typing $browser-> above would not pop any suggestion.
Expecting to see suggestion for Laravel Dusk browser.
+1
@slava-vishnyakov referenced is your implementation? Submitting a pull request?
@adityapurwa I don't think I can do a pull request, since ide-helpers generates the files dynamically, this is just a way to get auto-complete before the official solution.
Actually, the problem is not in ide helpers, but in PHPStorm (see my link for PHPStorm's bug).
@slava-vishnyakov Thanks for that.
Just adding this link for a similar issue I had with wanting some collection macros to be visible to the IDE and how I managed to get that to work.
I'll be using your text in my file too, it might help someone else: https://github.com/spatie/laravel-collection-macros/issues/16#issuecomment-286467543
Hey, guys! :)
So, for now, the problem is fixed in PHPStorm 2017.3 and Browser methods do have autocompletion.
But what about custom component or page methods referenced at the same Browser's _call magic method?
if ($this->component && method_exists($this->component, $method)) {
array_unshift($parameters, $this);
$this->component->{$method}(...$parameters);
return $this;
}
if ($this->page && method_exists($this->page, $method)) {
array_unshift($parameters, $this);
$this->page->{$method}(...$parameters);
return $this;
}
Is it possible to have autocompletion for them also? For example:
$this->browse(function (Browser $browser) {
$browser->login()
->visit(new AuthorsCreatePage)
->assertOnPage() // AuthorsCreatePage custom method, no autocompletion
->assertSeeActiveMenuItem() // AuthorsCreatePage custom method, no autocompletion
->assertSeeBreadcrumbs() // AuthorsCreatePage custom method, no autocompletion
->assertSee('Create Author')
->assertSubmitDisabled(); // AuthorsCreatePage custom method, no autocompletion
});
Hey, @slava-vishnyakov, hi :) Do you have any solutions for that? :)
@dmitry-ivanov, use slava's _browser_ide_helper.php he linked to.
Works fine once you add your own functions.
The only issue I get now is a message saying multiple class definitions exist for Browser.
Use the PHPstorm setting mentioned here - https://stackoverflow.com/questions/23066665/multiple-definitions-exist-for-class
(Settings/Preferences | Editor | Inspections | Undefined | Undefined class | Don't report multiple class declaration potential problems).
I don't see any warnings, but control clicking the class will ask you which to navigate which is fine with me.
@carltondickson For my project, I've created ./tests/Browser/_ide_helper_dusk.php with the following code:
<?php
namespace Laravel\Dusk;
/**
* @method Browser assertOnPage()
* @method Browser assertElementEnabled($selector)
* @method Browser assertElementDisabled($selector)
* @method Browser assertSeeConfirm($text, $ok = 'OK', $cancel = 'Cancel')
* ... and so on ...
*/
class Browser
{
}
So, I'm just specifying which custom methods were added in my base and specific page classes.
This file is not included anywhere, it just created for IDE. And yes, you can disable "multiple class definitions" warning in PHPStorm too (just by clicking on the "lamp" icon near it).
Anyways, it would be cool to have that as a part of laravel-ide-helper.
It isn't quite laravel and means a bit of overriding, but I extend the default dusk browser and add any additional methods in there, stored as traits for tidyness.
This means that they'll be available on every test page, so I prefix each method with the page to prevent confusion
It's not the perfect solution, but works for me
namespace Tests\Browser;
use Tests\Browser\Traits\MapMethods;
class Browser extends \Laravel\Dusk\Browser
{
use MapMethods;
trait MapMethods
{
/**
* Searches for the passed item
*
* @param $search
* @param int $pauseSeconds
*
* @return $this
*/
public function mapSearch($search, $pauseSeconds = 500)
{
use Tests\Browser\Browser;
use Tests\DuskTestCase;
class MapPageTest extends DuskTestCase
{
/**
* @throws \Throwable
*/
public function testCanOpenMap()
{
$this->browse(function (Browser $browser) {
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this issue is still present on the latest version of this library on supported Laravel versions, please let us know by replying to this issue so we can investigate further.
Thank you for your contribution! Apologies for any delayed response on our side.
Most helpful comment
Hey, guys! :)
So, for now, the problem is fixed in PHPStorm 2017.3 and Browser methods do have autocompletion.
But what about custom component or page methods referenced at the same Browser's
_callmagic method?Is it possible to have autocompletion for them also? For example:
Hey, @slava-vishnyakov, hi :) Do you have any solutions for that? :)