Laravel5.5 Dusk 利用可能なアサーションはこれだ!

2019-12-18

Laravel Duskでは自動ブラウザテストを可能にします。
特別なものは必要ありません。ChromeDriverがあればOKです。
Laravel5.5 Duskにおいて利用可能なアサーションを簡単に分類別にまとめて解説していきます。

↓Duskのインストール、自動テストの実行等についてはこちらから
Laravel5.5 Duskのインストール/実行方法

Title/タイトル

  • assertTitle
$browser->assertTitle($title)

Assert the page title matches the given text.
ページタイトルが指定されたテキストと一致することを確認します。

  • assertTitleContains
$browser->assertTitleContains($title)

Assert the page title contains the given text.
ページタイトルにテキストが含まれているか確認します。

Urls/パス

  • assertUrlIs
$browser->assertUrlIs($url)

Assert that the current URL (without the query string) matches the given string.
現在のURL(クエリ文字列なし)が指定された文字列と一致することを確認します。

  • assertPathBeginsWith
$browser->assertPathBeginsWith($path)

Assert that the current URL path begins with given path.
現在のURLパスが指定されたパスであることを確認します。

  • assertPathIs
$browser->assertPathIs('/home')

Assert the current path matches the given path.
現在のパスが指定されたパスに一致することを確認します。

  • assertPathIsNot
$browser->assertPathIsNot('/home')

Assert the current path does not match the given path.
現在のパスが指定されたパスと一致しない事を確認します。

  • assertRouteIs
$browser->assertRouteIs($name, $parameters)

Assert the current URL matches the given named route’s URL.
現在のURLが指定されたルートのURLと一致することを確認します。


クエリ文字列

  • assertQueryStringHas
$browser->assertQueryStringHas($name, $value)

Assert the given query string parameter is present and has a given value.
指定されたクエリ文字列パラメータが存在し、指定された値を持つことを確認します。

  • assertQueryStringMissing
$browser->assertQueryStringMissing($name)

Assert the given query string parameter is missing.
指定されたクエリ文字列パラメータが存在しないことを確認します。

  • assertHasQueryStringParameter
$browser->assertHasQueryStringParameter($name)

Assert that the given query string parameter is present.
指定されたクエリ文字列パラメータが存在することを確認します。

Cookie

  • assertHasCookie
$browser->assertHasCookie($name)

Assert the given cookie is present.
指定されたクッキーが存在することを確認します。

  • assertCookieMissing
    $browser->assertCookieMissing($name)
    Assert that the given cookie is not present.
    指定されたクッキーが存在しないことを確認します。

  • assertCookieValue

$browser->assertCookieValue($name, $value)

Assert a cookie has a given value.
クッキーが値を持つことを確認します。

  • assertPlainCookieValue
$browser->assertPlainCookieValue($name, $value)

Assert an unencrypted cookie has a given value.
暗号化されていないCookieが特定の値を持つことを確認します。

表示

-assertSee

$browser->assertSee($text)

Assert the given text is present on the page.
指定されたテキストがページに存在するか確認します。

  • assertDontSee
$browser->assertDontSee($text)

Assert the given text is not present on the page.
指定されたテキストがページに存在しないことを確認します。

  • assertSeeIn
$browser->assertSeeIn($selector, $text)

Assert the given text is present within the selector.
指定されたテキストがセレクタ内に存在することを確認します。

  • assertDontSeeIn
$browser->assertDontSeeIn($selector, $text)

Assert the given text is not present within the selector.
指定されたテキストがセレクタ内に存在しないことを確認します。

Source

  • assertSourceHas
$browser->assertSourceHas($code)

Assert that the given source code is present on the page.
指定されたソースコードがページに存在することを確認します。

  • assertSourceMissing
$browser->assertSourceMissing($code)

Assert that the given source code is not present on the page.
指定されたソースコードがページに存在しないことを確認します。

Link

  • assertSeeLink
$browser->assertSeeLink($linkText)

Assert the given link is present on the page.
指定されたテキストリンクがページ内に存在するか確認します。

  • assertDontSeeLink
$browser->assertDontSeeLink($linkText)

Assert the given link is not present on the page.
指定されたテキストリンクがページ内に存在しないことを確認します。

InputValue/入力値

  • assertInputValue
$browser->assertInputValue($field, $value)

Assert the given input field has the given value.
指定された入力フィールドに指定された値があることを確認します。

  • assertInputValueIsNot
$browser->assertInputValueIsNot($field, $value)

Assert the given input field does not have the given value.
指定された入力フィールドに指定された値がないことを確認します。

checkbox

  • assertChecked
$browser->assertChecked($field)

Assert the given checkbox is checked.
指定されたチェックボックスが選択されていることを確認します。

  • assertNotChecked
$browser->assertNotChecked($field)

Assert the given checkbox is not checked.
指定されたチェックボックスが選択されていないことを確認します。

Radio

  • assertRadioSelected
$browser->assertRadioSelected($field, $value)

Assert the given radio field is selected.
指定されたラジオボタンが選択されていることを確認します。

  • assertRadioNotSelected
$browser->assertRadioNotSelected($field, $value)

Assert the given radio field is not selected.
指定されたラジオボタンが選択されていないことを確認します。

dropdown

  • assertSelected
$browser->assertSelected($field, $value)

Assert the given dropdown has the given value selected.
指定されたドロップダウンに指定された値が選択されていることを確認します。

  • assertNotSelected
$browser->assertNotSelected($field, $value)

Assert the given dropdown does not have the given value selected.
指定されたドロップダウンに指定された値が選択されていないことを確認します。

セレクト

  • assertSelectHasOptions
$browser->assertSelectHasOptions($field, $values)

Assert that the given array of values are available to be selected.
指定された配列フィールドが選択可能であると確認します。

  • assertSelectMissingOptions
$browser->assertSelectMissingOptions($field, $values)

Assert that the given array of values are not available to be selected.
指定された配列フィールドが選択不可であると確認します。

  • assertSelectHasOption
$browser->assertSelectHasOption($field, $value)

Assert that the given value is available to be selected on the given field.
指定されたフィールドで指定された値を選択できることを確認します。

  • assertValue
$browser->assertValue($selector, $value)

Assert the element matching the given selector has the given value.
指定されたセレクタに一致する要素が指定された値を持つことを確認します。

  • assertVisible
$browser->assertVisible($selector)

Assert the element matching the given selector is visible.
指定されたセレクタに一致する要素が表示状態であることを確認します。

  • assertMissing
$browser->assertMissing($selector)

Assert the element matching the given selector is not visible.
指定されたセレクタに一致する要素が非表示状態であることを確認します。

ダイアログ

  • assertDialogOpened
$browser->assertDialogOpened($message)

Assert that a JavaScript dialog with given message has been opened.
指定されたメッセージを含むJavaScriptダイアログが開かれていることを確認します。

Vue

  • assertVue
$browser->assertVue($property, $value, $component)

Assert that a given Vue component data property matches the given value.
指定されたVueコンポーネントのデータプロパティが指定された値と一致することを確認します。

  • assertVueIsNot
$browser->assertVueIsNot($property, $value, $component)

Assert that a given Vue component data property does not match the given value.
指定されたVueコンポーネントのデータプロパティが指定された値と一致しないことを確認します。

Nuxt.jsビギナーズガイド―Vue.js ベースのフレームワークによるシングルページアプリケーション開発

以上になります。
参照:
https://laravel.com/docs/5.5/dusk#available-assertions