Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 用Laravel黄昏测试ReCaptcha_Php_Laravel_Recaptcha_Laravel Dusk_Invisible Recaptcha - Fatal编程技术网

Php 用Laravel黄昏测试ReCaptcha

Php 用Laravel黄昏测试ReCaptcha,php,laravel,recaptcha,laravel-dusk,invisible-recaptcha,Php,Laravel,Recaptcha,Laravel Dusk,Invisible Recaptcha,我在使用Laravel Dusk在表单上测试不可见的ReCaptcha时遇到了一个小问题。在这种情况下涉及的一揽子计划是 我在/tests protected function withoutRecaptcha() : void { InvisibleReCaptcha::shouldReceive("verifyRequest") ->andReturnTrue(); InvisibleReCaptcha::shouldReceive("verifyRe

我在使用Laravel Dusk在表单上测试不可见的ReCaptcha时遇到了一个小问题。在这种情况下涉及的一揽子计划是

我在
/tests

protected function withoutRecaptcha() : void
{
    InvisibleReCaptcha::shouldReceive("verifyRequest")
        ->andReturnTrue();

    InvisibleReCaptcha::shouldReceive("verifyResponse")
        ->once()
        ->andReturnTrue();
}
这对于特性测试非常有效,因为我只需要点击API,就可以忽略来自post请求的
g-recaptcha-response
输入

但是如果我想测试表单本身,使用像Laravel Dusk这样的浏览器测试系统,当然这还不够

我目前的黄昏方法如下

 public function a_guest_can_fill_the_registration_form()
 {
     $this->withoutRecaptcha();

     $this->browse(function (Browser $browser) {
         $browser->maximize()
            ->visit(new Register())
            ->assertPresent("input[name=g-recaptcha-response]")
            ->fillFormWithRandomData()
            ->submitForm()
            ->waitForReload()
            ->assertVisible(".alert.alert-success");
    });
 }
简单的事情在这里,我打电话登记表,填写数据,提交,并检查是否有警报。目前这不起作用,我收到以下错误:

There was 1 failure:

1) Tests\Browser\RegisterTest::a_guest_can_fill_the_registration_form
Element [body input[name=g-recaptcha-response]] is not present.
Failed asserting that false is true.

/app/vendor/laravel/dusk/src/Concerns/MakesAssertions.php:806
/app/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:67
所以问题很明显:在测试期间,ReCaptcha输入没有呈现,因此不可能命中它,甚至伪造它

有没有一种方法来渲染假的ReCaptcha以使其与Laravel黄昏一起工作


谢谢您

请在iframe内重温一下。黄昏无法识别iframe中的元素。但是,您可以在Inframe('selector',function($browser){}中使用方法
->并在withinFrame闭包内断言值