首页 > 解决方案 > 在 Laravel Dusk 中使用键盘

问题描述

Laravel 版本:

关于在 Laravel Dusk 中使用键盘的文档显示了以下语法:

$browser->keys('selector', ['{shift}', 'taylor'], 'otwell');
// or
$browser->keys('.app', ['{command}', 'j']);

在我的代码中,我有:

public function test_project_can_be_created()
    {
        $this->browse(function (Browser $browser) {
            $browser
                ->loginAs($this->user)
                ->visit('/')
                ->click('a[href="'.route('projects.index').'"]')
                ->click('a[href="'.route('projects.create').'"]')
                ->keys('#app', ['{enter}']) // this is line 106
                ->type('project[name]', $this->faker->word)
                ->click('@submit');
        }); // this is line 109
    }

我想要实现的只是在浏览器中按“ENTER”键。然而...

当我运行时,php artisan dusk我收到以下错误:

There was 1 error:

1) Tests\Browser\ProjectsTest::test_project_can_be_created
ErrorException: Array to string conversion

/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebElement.php:333 // https://github.com/php-webdriver/php-webdriver/blob/master/lib/Remote/RemoteWebElement.php#L333
/vendor/laravel/dusk/src/Concerns/InteractsWithElements.php:107 // https://github.com/laravel/dusk/blob/5.0/src/Concerns/InteractsWithElements.php#L107
/tests/Browser/ProjectsTest.php:106
/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:68
/tests/Browser/ProjectsTest.php:109

我错过了什么吗?我使用了错误的语法吗?

标签: laravellaravel-6laravel-dusk

解决方案


推荐阅读