ivanmiranda's avatar

Laravel Dusk Example test failing - Can't load URL

Hello everyone,

Here is my problem: i'm trying to develop a piece of code with Laravel Dusk that allows me to automatize a few tasks on Chrome browser. However, despite of applying correctly all the documentation steps, ExampleTest.php file is throwing this error:

 "No se puede cargar la URL: El dominio de esta URL no está incluido en los dominios de la aplicación. Para poder cargar esta URL, añade todos los dominios y subdominios de tu a
plicación al campo de dominios de la aplicación en la configuración de tu aplicación."

It seems, according with what forums says on the internet, that Facebook security rules have become tighter and more restrictive, using only oauth URL's. One of the solutions it is supposed to be include all the domains of your app in Facebook app configuration panel, but my question is: i'm running this locally, which means my url's at the moment are http://localhost/etc.

This is really bothering me. Anybody could help, please? Thanks in advance.

Leave some pics of the code:

<?php

namespace Tests\Browser;

use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;

class ExampleTest extends DuskTestCase
{
    /**
     * A basic browser test example.
     *
     * @return void
     */
    public function testBasicExample()
    {
        $this->browse(function (Browser $browser) {
            $browser->visit('/')
                    ->assertSee('Laravel');
        });
    }
}

And in AppServiceProvider i've also included:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema; 
use Laravel\Dusk\DuskServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->register(DuskServiceProvider::class);
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);
    }
}
0 likes
11 replies
diegoaurino's avatar

Hello, @ivanmiranda !

Just to make sure: have you set the APP_URL in your .env file?

Are you using php artisan serve or a local web server?

ivanmiranda's avatar

Hey @diegoaurino, thanks for the response, in advance.

Yes, APP_URL is set to http://localhost and i'm using a local web server. I've acheived to get it work with https routes on $browser->visit() method, but it's still throwing errors with the app routes. I've checked the error screenshots and a 404 not found is thrown for practically all routes.

bobbybouwmann's avatar

I'm not really sure what your question or code that you showed has to do with Facebook.

Anyway, how does your local setup look like?

ivanmiranda's avatar

@diegoaurino Hello again,

I think I've explained myself a bit wrong. With http://localhost/etc, I just meaned that server runs only on http://localhost (main root) and etc represents the rest of routes, like for example http://localhost/public/shows/display. So APP_URL is fine as far as I know. My OS is Windows 10 Professional and the app is perfectly working for the purpose it has. Problems are just happening with Dusk. However, I managed this to work with https:// routes at least. But problems are still thrown on app local routes. I show an example:


<?php

namespace Tests\Browser;

use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;

class ExampleTest extends DuskTestCase
{
    /**
     * A basic browser test example.
     *
     * @return void
     */
    public function testBasicExample()
    {
        $this->browse(function (Browser $browser) {

            $browser->visit('/k24/public')
                    ->assertSee('Login');
            // $browser->visit('https://www.google.com/intl/es/gmail/about/#')
            //         ->assertSee('Iniciar sesión')
            //         ->clickLink('Iniciar sesión')
        });
    }
}

Here response by Artisan CLI is:


Warning: TTY mode is not supported on Windows platform.
PHPUnit 7.5.7 by Sebastian Bergmann and contributors.


DevTools listening on ws://127.0.0.1:52915/devtools/browser/53c53e40-b810-4f33-a772-1604f807e902
E                                                                   1 / 1 (100%)

Time: 33.86 seconds, Memory: 14.00 MB

There was 1 error:

1) Tests\Browser\ExampleTest::testBasicExample
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session/ec5106b07b670aff07ce240966ef166f/url with params: {"url":"http:\/\/localhost\/\/k24\/public"}

Operation timed out after 30000 milliseconds with 0 bytes received

C:\xampp\htdocs\k24\vendor\facebook\webdriver\lib\Remote\HttpCommandExecutor.php:292
C:\xampp\htdocs\k24\vendor\facebook\webdriver\lib\Remote\RemoteWebDriver.php:547
C:\xampp\htdocs\k24\vendor\facebook\webdriver\lib\Remote\RemoteExecuteMethod.php:40
C:\xampp\htdocs\k24\vendor\facebook\webdriver\lib\WebDriverNavigation.php:85
C:\xampp\htdocs\k24\vendor\laravel\dusk\src\Browser.php:138
C:\xampp\htdocs\k24\tests\Browser\ExampleTest.php:20
C:\xampp\htdocs\k24\vendor\laravel\dusk\src\Concerns\ProvidesBrowser.php:67
C:\xampp\htdocs\k24\tests\Browser\ExampleTest.php:26

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.


And on screenshots login is perfectly shown, so I'm unable to find out why local routes are not responding as they should.

Respect to your question, @bobbybouwmann, thanks in advance for answering. I had your same thought about why Facebook is appearing here, but it seems that ChromeDriver used by Laravel Dusk is related some how with Facebook. You can check that here, on vendor folder, for example:


namespace Facebook\WebDriver\Chrome;

use Facebook\WebDriver\Exception\WebDriverException;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\DriverCommand;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\Service\DriverCommandExecutor;
use Facebook\WebDriver\Remote\WebDriverCommand;

class ChromeDriver extends RemoteWebDriver

And my setup on .env file looks like this:


APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:0mia4GPUbDTzkIXMrGT2aqxP6EocNiMWlmcspoMhQ4E=
APP_DEBUG=true
APP_URL=http://localhost/

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=kontollarte_beta
DB_USERNAME=root
DB_PASSWORD=''

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=dcebf6fe5611e6
MAIL_PASSWORD=688eabce7e7d21
MAIL_ENCRYPTION=null

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

I know passwords on mysql config should be different from default, but this is just testing environment. Thanks for helping guys.

diegoaurino's avatar

@IVANMIRANDA - I believe that Dusk will not understand that it should follow this "http://localhost/public/" to access the application. If you are using Apache locally, you need to point the DocumentRootto the public folder of your app. Also check the AllowOverride directive and the mod_rewrite module are properly set.

Hope this helps.

bobbybouwmann's avatar

Yeah like @diegoaurino said, you need to make sure your url is pointed to the public directory.

The reason you see Facebook here is that the webdriver is build by Facebook. I thought you were performing some action against Facebook, but that is not the case.

ivanmiranda's avatar

@DIEGOAURINO - Hello @diegoaurino Not sure how to accomplish what you say about DocumentRoot. Do you mean that the server has to point to the public folder of my app? And in that case, how can I do that? Thanks again.

diegoaurino's avatar

@IVANMIRANDA - Considering that the full path to your public folder is C:\www\laravel\public, add the following to Apache:


  DocumentRoot "C:\www\laravel\public"

  <Directory "C:\www\laravel">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
  </Directory>
 

I don't know what local web server solution are you using; so take this as a general guide. Also, check if mod_rewrite is enabled.

ivanmiranda's avatar

Thanks for the info @diegoaurino. I didn't know these details about Apache configuration. Finally, the 404 not found was being thrown because there was some security measure that didn't allow the test to go ahead. Fixing that it's working now.

Thanks again!

Please or to participate in this conversation.