Created
September 19, 2019 15:23
-
-
Save jonathanbossenger/d584807e1c6b02d0d5151ab833a5158d to your computer and use it in GitHub Desktop.
Custom ServiceProvider to register scrollToElement macro for Dusk browser testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use Laravel\Dusk\Browser; | |
use Illuminate\Support\ServiceProvider; | |
class DuskServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Register services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
// | |
} | |
/** | |
* Bootstrap services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
Browser::macro('scrollToElement', function ($element = null) { | |
$this->script("$('html, body').animate({ scrollTop: $('$element').offset().top }, 0);"); | |
return $this; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment