Skip to content

Instantly share code, notes, and snippets.

@jonathanbossenger
Created September 19, 2019 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanbossenger/d584807e1c6b02d0d5151ab833a5158d to your computer and use it in GitHub Desktop.
Save jonathanbossenger/d584807e1c6b02d0d5151ab833a5158d to your computer and use it in GitHub Desktop.
Custom ServiceProvider to register scrollToElement macro for Dusk browser testing
<?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