Features

Laravel Automated Testing

Let's start with making sure PHP is available on your system.

For Windows: For Linux:
Copy code
sudo apt-get install curl libcurl3 libcurl3-dev php
For macOS:

PHP should already be present on macOS by default.

Installation

  • Make sure you have Composer installed.
  • Install the Laravel Dusk Framework and other dependencies creating this composer.json file:

    Copy code
    {
        "name": "laravel/laravel",
        "type": "project",
        "description": "The Laravel Framework.",
        "keywords": [
            "framework",
            "laravel"
        ],
        "license": "MIT",
        "require": {
            "php": "^7.1.3",
            "fideloper/proxy": "^4.0",
            "laravel/framework": "5.7.*",
            "laravel/tinker": "^1.0"
        },
        "require-dev": {
            "beyondcode/laravel-dump-server": "^1.0",
            "filp/whoops": "^2.0",
            "fzaninotto/faker": "^1.4",
            "laravel/dusk": "^4.0",
            "mockery/mockery": "^1.0",
            "nunomaduro/collision": "^2.0",
            "phpunit/phpunit": "^7.0"
        },
        "config": {
            "optimize-autoloader": true,
            "preferred-install": "dist",
            "sort-packages": true
        },
        "extra": {
            "laravel": {
                "dont-discover": []
            }
        },
        "autoload": {
            "psr-4": {
                "App\\": "app/",
                "Tests\\": "tests/"
            },
            "classmap": [
                "database/seeds",
                "database/factories",
                "tests/TestCase.php"
            ]
        },
        "autoload-dev": {
            "psr-4": {
                "Tests\\": "tests/"
            }
        },
        "minimum-stability": "dev",
        "prefer-stable": true,
        "scripts": {
            "post-autoload-dump": [
                "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
                "@php artisan package:discover --ansi"
            ],
            "post-root-package-install": [
                "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
            ],
            "post-create-project-cmd": [
                "@php artisan key:generate --ansi"
            ]
        }
    }
  • Install the dependencies by running:

    Copy code
    composer install
    composer dump-autoload
  • Install the necessary Dusk files:

    Copy code
    php artisan dusk:install

Configuration

If you followed the steps above, you should now have a tests/DuskTestCase.php file.

You can now generate a sample test file, for example with:

Copy code
php artisan dusk:make LoginTest

To connect your test with TestingBot, you'll need to edit the tests/DuskTestCase.php file with the following contents:

Copy code
protected function driver()
{
    return RemoteWebDriver::create(
"https://api_key:api_secret@hub.testingbot.com/wd/hub",
array("platform"=>"WINDOWS", "browserName"=>"chrome", "version" => "latest"), 120000);
}

To run the test, please enter this command:

Copy code
php artisan dusk

Configuring capabilities

To run your existing tests on TestingBot, your tests will need to be configured to use the TestingBot remote machines. If the test was running on your local machine or network, you can simply change your existing test like this:

Before:
Copy code
$web_driver = RemoteWebDriver::create("http://localhost:4444/wd/hub",
array("platform"=>"WINDOWS", "browserName"=>"chrome"), 120000);
After:
Copy code
$web_driver = RemoteWebDriver::create(
    "https://api_key:api_secret@hub.testingbot.com/wd/hub",
array("platform"=>"WINDOWS", "browserName"=>"chrome"), 120000);

Specify Browsers & Devices

To let TestingBot know on which browser/platform/device you want to run your test on, you need to specify the browsername, version, OS and other optional options in the capabilities field.

Copy code
$web_driver = RemoteWebDriver::create(
    "http://api_key:api_secret@hub.testingbot.com/wd/hub",
$caps, 120000);

To see how to do this, please select a combination of browser, version and platform in the drop-down menus below.

Copy code

Testing Internal Websites

We've built TestingBot Tunnel, to provide you with a secure way to run tests against your staged/internal webapps.
Please see our TestingBot Tunnel documentation for more information about this easy to use tunneling solution.

The example below shows how to easily run a Laravel Dusk test with our Tunnel:

1. Download our tunnel and start the tunnel:

Copy code
java -jar testingbot-tunnel.jar key secret

2. Adjust your test: instead of pointing to 'hub.testingbot.com/wd/hub' like the example above - change it to point to your tunnel's IP address.
Assuming you run the tunnel on the same machine you run your tests, change to 'localhost:4445/wd/hub'. localhost is the machine running the tunnel, 4445 is the default port of the tunnel.

This way your test will go securely through the tunnel to TestingBot and back:

Copy code
<?php

protected function driver()
{
    return RemoteWebDriver::create("http://api_key:api_secret@localhost:4445/wd/hub",
        array('platform' => "WINDOWS", "version" => 'latest', 'browserName' => 'firefox'), 120000
    );
}

Other PHP Framework examples

  • Behat

    Behat is a BDD framework which runs on PHP.
    Mink is used for its browser emulation and works nicely together with Behat.

  • Codeception

    Codeception is a BDD-styled PHP testing framework.
    This testing framework offers good Selenium support.

  • Laravel Dusk

    Laravel Dusk provides an easy-to-use browser automation testing framework.

  • PHPUnit

    PHPUnit is the most popular unit testing framework for PHP.
    It comes with good Selenium WebDriver support and is easy to set up.

  • SimpleTest

    SimpleTest is a framework for unit testing, web site testing and mock objects for PHP.