InteractsWithPages

trait InteractsWithPages (View source)

Properties

protected Crawler $crawler The DomCrawler instance.
protected array $inputs All of the stored inputs for the current page.
protected array $uploads All of the stored uploads for the current page.

Methods

$this visit(string $uri)

Visit the given URI with a GET request.

$this makeRequest(string $method, string $uri, array $parameters = [], array $cookies = [], array $files = [])

Make a request to the application and create a Crawler instance.

$this makeRequestUsingForm(Form $form, array $uploads = [])

Make a request to the application using the given form.

array extractParametersFromForm(Form $form)

Extract the parameters from the given form.

$this followRedirects()

Follow redirects from the last response.

$this clearInputs()

Clear the inputs for the current page.

$this seePageIs(string $uri)

Assert that the current page matches a given URI.

void assertPageLoaded(string $uri, string|null $message = null)

Assert that a given page successfully loaded.

$this see(string $text, bool $negate = false)

Assert that a given string is seen on the page.

$this dontSee(string $text)

Assert that a given string is not seen on the page.

$this seeInElement(string $element, string $text, bool $negate = false)

Assert that a given string is seen inside an element.

$this dontSeeInElement(string $element, string $text)

Assert that a given string is not seen inside an element.

bool hasInElement(string $element, string $text)

Check if the page contains text within the given element.

$this seeLink(string $text, string|null $url = null)

Assert that a given link is seen on the page.

$this dontSeeLink(string $text, string|null $url = null)

Assert that a given link is not seen on the page.

bool hasLink(string $text, string|null $url = null)

Check if the page has a link with the given $text and optional $url.

string addRootToRelativeUrl(string $url)

Add a root if the URL is relative (helper method of the hasLink function).

$this seeInField(string $selector, string $expected)

Assert that an input field contains the given value.

$this dontSeeInField(string $selector, string $value)

Assert that an input field does not contain the given value.

$this seeIsChecked(string $selector)

Assert that the given checkbox is selected.

$this dontSeeIsChecked(string $selector)

Assert that the given checkbox is not selected.

$this seeIsSelected(string $selector, string $expected)

Assert that the expected value is selected.

$this dontSeeIsSelected(string $selector, string $value)

Assert that the given value is not selected.

string getInputOrTextAreaValue(string $selector)

Get the value of an input or textarea.

string|null getSelectedValue(string $selector)

Get the selected value of a select field or radio group.

string|null getSelectedValueFromSelect(Crawler $field)

Get the selected value from a select field.

string|null getCheckedValueFromRadioGroup(Crawler $radioGroup)

Get the checked value from a radio group.

bool isChecked(string $selector)

Return true if the given checkbox is checked, false otherwise.

$this click(string $name)

Click a link with the given body, name, or ID attribute.

$this type(string $text, string $element)

Fill an input field with the given text.

$this check(string $element)

Check a checkbox on the page.

$this uncheck(string $element)

Uncheck a checkbox on the page.

$this select(string $option, string $element)

Select an option from a drop-down.

$this attach(string $absolutePath, string $element)

Attach a file to a form field on the page.

$this press(string $buttonText)

Submit a form using the button with the given text value.

$this submitForm(string $buttonText, array $inputs = [], array $uploads = [])

Submit a form on the page with the given input.

Form fillForm(string $buttonText, array $inputs = [])

Fill the form with the given data.

Form getForm(string|null $buttonText = null)

Get the form from the page with the given submit button text.

$this storeInput(string $element, string $text)

Store a form input in the local array.

void assertFilterProducesResults(string $filter)

Assert that a filtered Crawler returns nodes.

Crawler filterByNameOrId(string $name, array|string $elements = '*')

Filter elements according to the given name or ID attribute.

array convertUploadsForTesting(Form $form, array $uploads)

Convert the given uploads to UploadedFile instances.

UploadedFile getUploadedFileForTesting(array $file, array $uploads, string $name)

Create an UploadedFile instance for testing.

Details

$this visit(string $uri)

Visit the given URI with a GET request.

Parameters

string $uri

Return Value

$this

protected $this makeRequest(string $method, string $uri, array $parameters = [], array $cookies = [], array $files = [])

Make a request to the application and create a Crawler instance.

Parameters

string $method
string $uri
array $parameters
array $cookies
array $files

Return Value

$this

protected $this makeRequestUsingForm(Form $form, array $uploads = [])

Make a request to the application using the given form.

Parameters

Form $form
array $uploads

Return Value

$this

protected array extractParametersFromForm(Form $form)

Extract the parameters from the given form.

Parameters

Form $form

Return Value

array

protected $this followRedirects()

Follow redirects from the last response.

Return Value

$this

protected $this clearInputs()

Clear the inputs for the current page.

Return Value

$this

protected $this seePageIs(string $uri)

Assert that the current page matches a given URI.

Parameters

string $uri

Return Value

$this

protected void assertPageLoaded(string $uri, string|null $message = null)

Assert that a given page successfully loaded.

Parameters

string $uri
string|null $message

Return Value

void

protected $this see(string $text, bool $negate = false)

Assert that a given string is seen on the page.

Parameters

string $text
bool $negate

Return Value

$this

protected $this dontSee(string $text)

Assert that a given string is not seen on the page.

Parameters

string $text

Return Value

$this

$this seeInElement(string $element, string $text, bool $negate = false)

Assert that a given string is seen inside an element.

Parameters

string $element
string $text
bool $negate

Return Value

$this

$this dontSeeInElement(string $element, string $text)

Assert that a given string is not seen inside an element.

Parameters

string $element
string $text

Return Value

$this

protected bool hasInElement(string $element, string $text)

Check if the page contains text within the given element.

Parameters

string $element
string $text

Return Value

bool

Assert that a given link is seen on the page.

Parameters

string $text
string|null $url

Return Value

$this

Assert that a given link is not seen on the page.

Parameters

string $text
string|null $url

Return Value

$this

Check if the page has a link with the given $text and optional $url.

Parameters

string $text
string|null $url

Return Value

bool

protected string addRootToRelativeUrl(string $url)

Add a root if the URL is relative (helper method of the hasLink function).

Parameters

string $url

Return Value

string

$this seeInField(string $selector, string $expected)

Assert that an input field contains the given value.

Parameters

string $selector
string $expected

Return Value

$this

$this dontSeeInField(string $selector, string $value)

Assert that an input field does not contain the given value.

Parameters

string $selector
string $value

Return Value

$this

$this seeIsChecked(string $selector)

Assert that the given checkbox is selected.

Parameters

string $selector

Return Value

$this

$this dontSeeIsChecked(string $selector)

Assert that the given checkbox is not selected.

Parameters

string $selector

Return Value

$this

$this seeIsSelected(string $selector, string $expected)

Assert that the expected value is selected.

Parameters

string $selector
string $expected

Return Value

$this

$this dontSeeIsSelected(string $selector, string $value)

Assert that the given value is not selected.

Parameters

string $selector
string $value

Return Value

$this

protected string getInputOrTextAreaValue(string $selector)

Get the value of an input or textarea.

Parameters

string $selector

Return Value

string

Exceptions

Exception

protected string|null getSelectedValue(string $selector)

Get the selected value of a select field or radio group.

Parameters

string $selector

Return Value

string|null

Exceptions

Exception

protected string|null getSelectedValueFromSelect(Crawler $field)

Get the selected value from a select field.

Parameters

Crawler $field

Return Value

string|null

Exceptions

Exception

protected string|null getCheckedValueFromRadioGroup(Crawler $radioGroup)

Get the checked value from a radio group.

Parameters

Crawler $radioGroup

Return Value

string|null

Exceptions

Exception

protected bool isChecked(string $selector)

Return true if the given checkbox is checked, false otherwise.

Parameters

string $selector

Return Value

bool

Exceptions

Exception

protected $this click(string $name)

Click a link with the given body, name, or ID attribute.

Parameters

string $name

Return Value

$this

protected $this type(string $text, string $element)

Fill an input field with the given text.

Parameters

string $text
string $element

Return Value

$this

protected $this check(string $element)

Check a checkbox on the page.

Parameters

string $element

Return Value

$this

protected $this uncheck(string $element)

Uncheck a checkbox on the page.

Parameters

string $element

Return Value

$this

protected $this select(string $option, string $element)

Select an option from a drop-down.

Parameters

string $option
string $element

Return Value

$this

protected $this attach(string $absolutePath, string $element)

Attach a file to a form field on the page.

Parameters

string $absolutePath
string $element

Return Value

$this

protected $this press(string $buttonText)

Submit a form using the button with the given text value.

Parameters

string $buttonText

Return Value

$this

protected $this submitForm(string $buttonText, array $inputs = [], array $uploads = [])

Submit a form on the page with the given input.

Parameters

string $buttonText
array $inputs
array $uploads

Return Value

$this

protected Form fillForm(string $buttonText, array $inputs = [])

Fill the form with the given data.

Parameters

string $buttonText
array $inputs

Return Value

Form

protected Form getForm(string|null $buttonText = null)

Get the form from the page with the given submit button text.

Parameters

string|null $buttonText

Return Value

Form

protected $this storeInput(string $element, string $text)

Store a form input in the local array.

Parameters

string $element
string $text

Return Value

$this

protected void assertFilterProducesResults(string $filter)

Assert that a filtered Crawler returns nodes.

Parameters

string $filter

Return Value

void

protected Crawler filterByNameOrId(string $name, array|string $elements = '*')

Filter elements according to the given name or ID attribute.

Parameters

string $name
array|string $elements

Return Value

Crawler

protected array convertUploadsForTesting(Form $form, array $uploads)

Convert the given uploads to UploadedFile instances.

Parameters

Form $form
array $uploads

Return Value

array

protected UploadedFile getUploadedFileForTesting(array $file, array $uploads, string $name)

Create an UploadedFile instance for testing.

Parameters

array $file
array $uploads
string $name

Return Value

UploadedFile

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.1/Illuminate/Foundation/Testing/InteractsWithPages.html