laravel / dusk

Laravel Dusk provides simple end-to-end testing and browser automation.
https://laravel.com/docs/dusk
MIT License
1.87k stars 319 forks source link

Failure to run Laravel Dusk #543

Closed JenniferZhou1999 closed 6 years ago

JenniferZhou1999 commented 6 years ago

I just downloaded Laravel Dusk and when I typed php artisan dusk in my project folder, I received this error.

1) Tests\Browser\ExampleTest::testBasicExample Did not see expected text [Laravel] within element [body]. Failed asserting that false is true.

/Users/jenniferzhou/Documents/Cypress/MarketPlace/vendor/laravel/dusk/src/Concerns/MakesAssertions.php:348 /Users/jenniferzhou/Documents/Cypress/MarketPlace/vendor/laravel/dusk/src/Concerns/MakesAssertions.php:319 /Users/jenniferzhou/Documents/Cypress/MarketPlace/tests/Browser/ExampleTest.php:20 /Users/jenniferzhou/Documents/Cypress/MarketPlace/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:67 /Users/jenniferzhou/Documents/Cypress/MarketPlace/tests/Browser/ExampleTest.php:21

FAILURES! Tests: 1, Assertions: 1, Failures: 1.

I have tried everything I saw online, but cannot seem to fix my problem.

This is my DuskTestCase.php file:

`<?php

namespace Tests;

use Laravel\Dusk\TestCase as BaseTestCase; use Facebook\WebDriver\Chrome\ChromeOptions; use Facebook\WebDriver\Remote\RemoteWebDriver; use Facebook\WebDriver\Remote\DesiredCapabilities;

abstract class DuskTestCase extends BaseTestCase { use CreatesApplication;

/**
 * Prepare for Dusk test execution.
 *
 * @beforeClass
 * @return void
 */
public static function prepare()
{
    static::startChromeDriver();
}

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

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

} `

This is my .env file

`APP_NAME=Laravel APP_ENV=local APP_KEY=base64:aXlPbKtuLqJ8sRrr2i7gEyUlWWvoaED/iYdVTTujsS8= APP_DEBUG=true APP_LOG_LEVEL=debug APP_URL=http://market.test

DB_CONNECTION=mysql DB_HOST=market.test DB_PORT=3306 DB_DATABASE=market DB_USERNAME=homestead DB_PASSWORD=secret

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

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=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null

PUSHER_APP_ID= PUSHER_APP_KEY= PUSHER_APP_SECRET= PUSHER_APP_CLUSTER=mt1 `

Based on what I have read, it may be a problem with the APP_URL in my .env file. However, I do not want to change that, because I want to be able to access my project by typing in market.test in the browser. Is there any other way to fix this issue? Thank you!

staudenmeir commented 6 years ago

Does your / page actually contain "Laravel"? Does it work when you use APP_URL=http://localhost?

JenniferZhou1999 commented 6 years ago

I changed APP_URL to APP_URL=http://localhost and then typed in php artisan dusk. However, I still get the same error.

staudenmeir commented 6 years ago

What does the screenshot in tests/Browser/screenshots show?

JenniferZhou1999 commented 6 years ago

My tests/Browser/screenshots/failure-testBasicExample-0.png file only shows a blank white space.

staudenmeir commented 6 years ago

Are you running php artisan dusk in Homestead (via SSH) or on your host machine?

JenniferZhou1999 commented 6 years ago

I always cd into my MarketPlace project and then run php artisan dusk (I do not run php artisan dusk in my homestead folder), so I believe my host machine.

staudenmeir commented 6 years ago

http://market.test works in your browser? Is the screenshot also blank when you run Dusk with the original APP_URL=http://market.test?

JenniferZhou1999 commented 6 years ago

http://market.test does work in my browser(my website shows up as it should). When I run php artisan dusk with the original APP_URL=http://market.test, a screenshot of the home page of my website shows up in the file.

staudenmeir commented 6 years ago

Does your home page actually contain the word "Laravel"? The example test is meant to work with the default welcome page.

JenniferZhou1999 commented 6 years ago

My home page no longer contains the word "Laravel". I changed the words in the title tag to Cypress. (I have included my welcome.blade.php below). Does that mean the reason the test is outputting error, is because I was using a test that is testing a file that does not exist?

`

<!DOCTYPE html>

Cypress Cypress {{----}} {{----}}
@if (Auth::guard('cuser')->guest()&&Auth::guard('admin')->guest()&&Auth::guest()) {{--Explore--}} Expert Login Company Login Join the Waitlist @elseif(Auth::guard('cuser')->user()) @else @endif
{{--
--}} {{--The destination for K-12 educators to collaborate, grow, and succeed--}} {{----}} {{--
--}}
Cypress

Currently in private beta

{{--

--}} {{--Data-driven, collaborative, career management and professional learning that integrates--}} {{--seamlessly with your workflow.

--}}
`
staudenmeir commented 6 years ago

Did not see expected text [Laravel] within element [body].

As the error message says, the test fails because the given text doesn't appear on the page.

You have to change it to something like ->assertSee('Cypress').

JenniferZhou1999 commented 6 years ago

Thank you so much! I do not know how I did not figure that out! Thank you!