Giter Club home page Giter Club logo

dusk's Introduction

Total Downloads Latest Stable Version License

What?

Laravel Dusk is an incredibly simple to use browser automation and testing tool. However, it was made with testing in mind, and as such, was never really meant for the production environment limelight.

Not anymore. I've gone ahead and ripped out all the parts that expose routes, or interact with your users.

Why?

So we can scrape the web with an amazingly expressive API in a framework we all know and love! All the methods you know and love -- minus the ones on interacting with or acting as users -- are there. See the official docs below for more details.

Caveats and gotchas

When using this tool as a scraper, you're typically limited to making dusk tests, and then triggering them via php artisan dusk.

You can automate this process and apply them to a command bus you can schedule!

Here's how:

Make your dusk test as you have before. Then, make a new command, making sure to give it a unique signature.

In the handle method, simply new up the class of the test you just created, initialize it and run it:

/**
 * Execute the console command.
 *
 * @return mixed
 */
public function handle()
{
    $event = new \Tests\Browser\Test;
    $event->prepare();
    $event->testExample();
}

Do whatever you had planned with the data you're scraping inside the test itself and you're golden.

When you make a test for dusk, make sure you include $browser->quit(); to ensure that the browser cleans up after itself. Do this after you've processed the data you've scraped.

What's next?

I'll make a 2.0 branch in the coming days to keep pace with the official package. It brings headless operation which will really help with some serious scraping.

Just kidding! Version 1.1.0 upgrades the binary and allows for headless operation.

To run your scraping headless, check out DuskTestCase.php, make sure to add ChromeOptions to your use statements, and set the $options variable and pass it through to the RemoteWebDriver like pictured below.

use Facebook\WebDriver\Chrome\ChromeOptions;

/**
 * Create the RemoteWebDriver instance.
 *
 * @return \Facebook\WebDriver\Remote\RemoteWebDriver
 */
protected function driver()
{
    $options = (new ChromeOptions)->addArguments(['--headless']);

    return RemoteWebDriver::create(
        'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
            ChromeOptions::CAPABILITY, $options
        )
    );
}

If anyone wants to help kick in a PR.

Official Documentation

Documentation for Dusk can be found on the Laravel website.

License

Dusk-Secure is open-sourced software licensed under the MIT license

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.