Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing inside Laravel Dusk #51

Open
divix1988 opened this issue Feb 15, 2024 · 3 comments
Open

Testing inside Laravel Dusk #51

divix1988 opened this issue Feb 15, 2024 · 3 comments

Comments

@divix1988
Copy link

divix1988 commented Feb 15, 2024

I am running Dusk automation tests and none of this seem to work:

   public function createApplication(): Application
    {
        ...
        $app['validator']->extend('captcha', function() {
            fwrite(STDOUT, print_r("Bypassing captcha validation and returning explicit true!\n", TRUE));
            return true;
        });

        CaptchaFacade::shouldReceive('verify')->andReturn(true);
        CaptchaFacade::shouldReceive('display')
            ->andReturn('<input type="hidden" name="g-recaptcha-response" value="1" />');

        return $app;
    }

The error message is Failed to validate the captcha. How to sort it?
image

@thinhbuzz
Copy link
Owner

What method do you use to display captcha in the template?
by the way can you reproduce it with a sample repo?

@divix1988
Copy link
Author

@thinhbuzz I use a simple usage of: {!! app('captcha')->display() !!} to display captcha.
Dusk is an automative test so it can be repped with any code, it's not related to environment.

I found this "partial" solution:

class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        if (isset($_SERVER['DB_HOST_DUSK']) && $_SERVER['DB_HOST_DUSK'] === 'localhost') {
            $this->app['validator']->extend('captcha', function() {
                _log("Bypassing captcha validation for Dusk automation tests!");
                return true;
            });
        }
    }

The above works but it required injecting test specific code into app codebase, which I am not a big fan.
It would be great if plugin would detect some kind of ENV flag, which Dusk has and can define inside: .env.dusk to bypass captcha checking. That's what I've done above.

@thinhbuzz
Copy link
Owner

Sorry for the late reply.
Can you create a sample repository of the problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants