1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Laravel Duskの小技メモ(Basic認証・存在有無で条件判定など)

Posted at

Laravel Duskに関する、公式サイトにはなかった内容の備忘録です!

1. Basic認証

例えば、ユーザー名がaaa, パスワードがbbb, ドメイン名がccc.example.comなら以下のようになります。

basiciLoginTest.php
$browser->visit('https://aaa:bbb@ccc.example.com/');

2. ある要素があるかどうかで条件分岐

xxxTest.php
if($browser->element('.class-name')){
// 処理
}

3. 実際にブラウザ上でテストの挙動を見る

DuskTestCase.php
protected function driver()
    {
        $options = (new ChromeOptions)->addArguments(collect([
            '--window-size=1920,1080',
        ])->unless($this->hasHeadlessDisabled(), function ($items) {
            return $items->merge([
                '--disable-gpu',
                // '--headless',  // この行をコメントアウトすると実際のブラウザの挙動が見られます
            ]);
        })->all());
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?