PHPackages                             michielgerritsen/dusk-for-magento2 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. michielgerritsen/dusk-for-magento2

AbandonedArchivedLibrary[Testing &amp; Quality](/categories/testing)

michielgerritsen/dusk-for-magento2
==================================

Ready to go Laravel Dusk components for your Magento 2 store to automated tests against them

12205PHP

Since Apr 17Pushed 7y ago1 watchersCompare

[ Source](https://github.com/michielgerritsen/dusk-for-magento2)[ Packagist](https://packagist.org/packages/michielgerritsen/dusk-for-magento2)[ RSS](/packages/michielgerritsen-dusk-for-magento2/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Dusk components for Magento 2
=====================================

[](#laravel-dusk-components-for-magento-2)

**Q: What is Laravel Dusk?**

A: Laravel Dusk is created to write end-to-end tests for your application. This means that when running your test, an actual Chrome browser is started which you can give instructions. Click on a link, fill in fields and submit a form.

**Q: Huh, Laravel is a framework, what has it to do with Magento?**

A: Nothing, but Laravel Dusk is capable to visit any site that is accessible from the machine it runs on.

**Q: So how do i use this?**

A: You need a full Laravel setup. But where do you install this? There are a few options:

- **Install it in a seperate directory next to Magento**

    Your folder structure would look like this:

    Websites

    - `my-magento2-store`
    - `my-laravel-dusk-project`

    This is the cleanest way, but it may be a bit hard to maintain the code as it typically requires 2 code bases.
- **Install it into the Magento directory**

    Go to your Magento folder and run `laravel new end-to-end-tests`.
- **Install a standalone Laravel Dusk version in Magento 2**

    I haven't tried this, but in theory it could work:

**Q: So how does the test looks like?**

A: When your Laravel install is ready to go, the next thing to do is install Laravel Dusk in your Laravel project:

`composer require laravel/dusk`

Create the file `test/Browser/OrderTest.php` with this contents:

```
namespace Tests\Browser;

use ControlAltDelete\DuskForMagento2\DataObjects\Address;
use ControlAltDelete\DuskForMagento2\Actions\AddSimpleProductToCart;
use ControlAltDelete\DuskForMagento2\Actions\FillShippingAddress;
use ControlAltDelete\DuskForMagento2\PaymentMethod\MoneyOrder;
use Tests\DuskTestCase;
use Laravel\Dusk\Browser;

class OrderProductsTest extends DuskTestCase
{
    protected function baseUrl()
    {
        return 'http://my-super-cool-project.test';
    }

    public function testOrderProducts()
    {
        $this->browse(function (Browser $browser) {
            $browser->visit('/');

            $browser->visit(new AddSimpleProductToCart('/fusion-backpack.html', 'Fusion Backpack'))->addToCart(2);
            $browser->visit(new AddSimpleProductToCart('/push-it-messenger-bag.html', 'Push It Messenger Bag'))->addToCart(3);

            $browser->visit('/checkout/');

            $address = new Address(
                'michiel@controlaltdelete.nl', // E-mail
                'Michiel', // Firstname
                'Gerritsen', // Lastname
                ['Simonszand 69'], // Array of streetlines
                'Hoofddorp', // City
                '2134ZX', // Postcode
                'NL', // Country id
                '0031623925470' // Postcode
            );

            $browser->visit(new FillShippingAddress())->fillShippingAddress($address);

            $browser->press('Next');

            $browser->waitUntilMissing('.loading-mask');
            $browser->waitFor('.payment-method');

            $browser->on(new MoneyOrder())->placeOrder();

            $browser->assertSee('Thank you for your purchase!');
        });
    }
}

```

And run:

`php artisan dusk`

When there is a successful test, check your orders. There should be a new one.

**Q: My test fails, what to do?**

A: There are a few thing:

- For starters, try it a few times. There are a few functions in there that might have a smaller timeout than the average Magento installation requires to warm up it's caches. So it might well be the case that when you try it a few times all caches get warmed up and your test succeeds.
- If that doesn't help, check the screenshot. Everytime a test fails, Dusk will create a screenshot in tests/Browser/screenshots. It also tries to give you a hint on wat went wrong, a missing element for example.
- This code is written on a stock Magento 2 installation, so there might be some changes in your installation, elements with a different name for example. Try to tweak it here and there.

**Note**

This is mainly created as a proof of concept. It works in my environment, but there is a decent change it doesn't work right away in yours. Feel free to open an issue or pull request to improve these components. This code is tested on a stock Magento 2.2.6 and 2.3.0 with sample data.

Components overview
-------------------

[](#components-overview)

`Actions\AddSimpleProductToCart`

Add a simple product to you shopping cart with the optional given quantity. It verifies that the product is added to the cart.

**Usage**

```
$browser->visit(new AddSimpleProductToCart($relativeUrl, $name))->addToCart($quantity = null);
$browser->visit(new AddSimpleProductToCart('/fusion-backpack.html', 'Fusion Backpack'))->addToCart(2);

```

When you enter a quantity it is required to have the quantity field enable on the product page. You can repeat this with different products to create shopping cart with differen items in them.

---

`Actions\AddBundleProductToCart`

Add a bundle product to you shopping cart with the optional given quantity. It verifies that the product is added to the cart.

**Usage**

```
$optionList = new BundleOptionList([
    new BundleOption(5, 9),
    new BundleOption(6, 13),
]);

$browser->visit(new AddBundleProductToCart($relativeUrl, $name))->addToCart($optionList, $quantity = null);
$browser->visit(new AddBundleProductToCart('/fusion-backpack.html', 'Fusion Backpack'))->addToCart($optionList, 2);

```

The IDs refer to the ID of the dropdown, and the ID of the option in the dropdown.

---

`Actions\FillShippingAddress`

Navigate to the checkout and fill the shipping address. It is required to provide an `\ControlAltDelete\DuskForMagento2\DataObjects\Address` object.

**Usage**

```
$browser->visit(new FillShippingAddress())->fillShippingAddress($address);

```

---

`PaymentMethod\MoneyOrder`

This selects the moneyorder payment method and clicks the *Place order* button.

**Usage**

`$browser->on(new MoneyOrder())->placeOrder();`

---

`Actions\AdminLogin`

Login on the admin panel.

**Usage**

```
$browser->visit(new AdminLogin($frontName))->fillForm($username, $password);
$browser->visit(new AdminLogin('my-custom-frontname'))->fillForm('my-username', 'my-password');

```

---

`Actions\NavigateToConfigurationGroup`

Navigate to a configuration group. Note: The capitalization is important here. *Payment methods* will fail, while *Payment Methods* will succeed.

**Usage**

```
$browser->on(new NavigateToConfigurationGroup)->open($tab', $name);
$browser->on(new NavigateToConfigurationGroup)->open('Sales', 'Payment Methods');

```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/ea5f9f50d4d50caa56065f4b55b1dd5aa3f1030402d0487a093200fdefa40f70?d=identicon)[michielgerritsen](/maintainers/michielgerritsen)

---

Top Contributors

[![michielgerritsen](https://avatars.githubusercontent.com/u/5858697?v=4)](https://github.com/michielgerritsen "michielgerritsen (10 commits)")

### Embed Badge

![Health badge](/badges/michielgerritsen-dusk-for-magento2/health.svg)

```
[![Health](https://phpackages.com/badges/michielgerritsen-dusk-for-magento2/health.svg)](https://phpackages.com/packages/michielgerritsen-dusk-for-magento2)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
