Skip to content

teofanis/pest-plugin-browser

 
 

Repository files navigation

Pest Plugin Browser

This repository contains the Pest Plugin Browser.

If you want to start testing your application with Pest, visit the main Pest Repository.

Community & Resources

Installation (for development purposes)

  1. Install PHP dependencies using Composer:
composer install
  1. Install Node.js dependencies:
npm install
  1. Install Playwright browsers:
npx playwright install

Running Tests

To run the test suite, execute:

./vendor/bin/pest

The Playground

Playground_interacting-with-elements.png

For each Operation/Assertion, we add a corresponding Test.

We can make use of the playgroundUrl() helper, to get its URL during the test.

We can provide a URI that will be appended, e.g: playgroundUrl('/test/interactive-elements').

Attention: we can use ->visit('/foo'), using the base URL, without the helper.

The helper exists for assertion scenarios, like:

$this->visit('/test/interactive-elements') ->assertUrlIs(playgroundUrl('/test/interactive-elements'))

Routes and views for testing

Check the playground/resources/views/test-pages folder for existing views.

They are accessible by the playground route /test/{page}.

E.g.: The view resources/views/test-pages/interactive-elements.blade.php is visited on playgroundUrl('/test/interactive-elements').

The playground is standard Laravel App, where you may add a page with a feature for your test.

Just add the view, and the Nav Menu will automatically update based on the view name.

License

Pest is an open-sourced software licensed under the MIT license.

Documentation

Pest Plugin Browser brings end-to-end testing to the elegant syntax from Pest. This allows to test your application in a browser environment, enabling to test all the components, such as frontend, backend and database.

Installation

TBD

Interacting with Elements

Waiting for Elements

Waiting

Pause the test for the specified number of milliseconds.

Warning

Discouraged: Never pause in production. Tests that wait for an amount of time are inherently flaky. Use "wait for element" or "wait for an event" approaches - you can wait for an event your app dispatches.

 $this->pause(5000); // Pause for 5 seconds

Available Assertions

assertAttribute

Assert that the specified element has the expected attribute and value:

$this->visit($url) ->assertAttribute('html', 'data-theme', 'light');

assertAttributeContains

Assert that the specified element has the expected attribute and the value contains a specific value:

$this->visit($url) ->assertAttributeContains('html', 'data-theme', 'ight');

assertAttributeMissing

Assert that the specified element is missing a particular attribute :

$this->visit($url) ->assertAttributeMissing('html', 'data-missing');

assertDontSee

Assert that the given text is not present on the page:

$this->visit($url) ->assertDontSee('we are a streaming service');

assertVisible

Assert that an element with the given selector is visible:

test('assert visible', function () { $url = 'https://laravel.com'; $this->visit($url) ->assertVisible('h1:visible'); });

assertMissing

Assert that an element with the given selector is hidden:

test('assert missing', function () { $url = 'https://laravel.com'; $this->visit($url) ->assertMissing('a.hidden');

assertQueryStringHas

Assert that the given query string is present in the url:

$this->visit($url) ->assertQueryStringHas('q', 'test');

assertQueryStringMissing

Assert that the given query string is not present in the url:

$this->visit($url) ->assertQueryStringMissing('q', 'test-1');

assertScript

Assert that the given script returns the expected value:

$this->visit($url) ->assertScript('document.querySelector("title").textContent.includes("Laravel")', true);

assertPresent

Assert that the element with a given selector is present on the page:

$this->visit($url) ->assertPresent('h1:visible');

assertNotPresent

Assert that the element with a given selector is not present on the page:

$this->visit($url) ->assertNotPresent('a.non-existing-class');

About

Pest Browser Plugin

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • PHP 78.3%
  • JavaScript 15.9%
  • Blade 5.2%
  • CSS 0.6%