This repository contains the Pest Plugin Browser.
If you want to start testing your application with Pest, visit the main * *Pest Repository**.
- Explore our docs at pestphp.com »
- Follow us on Twitter at @pestphp »
- Join us at discord.gg/kaHY6p54JH » or * t.me/+kYH5G4d5MV83ODk0 »*
- Install PHP dependencies using Composer:
composer install- Install Node.js dependencies:
npm install- Install Playwright browsers:
npx playwright installTo run the test suite, execute:
./vendor/bin/pestFor 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'))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.
Pest is an open-sourced software licensed under the MIT license.
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.
TBD
- back
- click
- clickAndHold
- clickAtPoint
- clickAtXPath
- clickLink
- controlClick
- doubleClick
- forward
- pause
- refresh
- rightClick
- screenshot
- visit
Check the given element.
$this->visit($url) ->check('#checkbox-unchecked');Uncheck the given element.
$this->visit($url) ->uncheck('#checkbox-checked');Click the element at the given selector.
$this->click('.selector');Perform a mouse click and hold the mouse button down at the given selector.
$this->clickAndHold('.selector');Click the topmost element at the given pair of coordinates.
$this->clickAtPoint('//div[@class = "selector"]');Click the element at the given XPath expression.
$this->clickAtXPath('//div[@class = "selector"]');Clicks some text on the page.
$this->clickLink('Sign In');Control click the element at the given selector.
$this->controlClick('.selector');Double-click the element at the given selector.
$this->doubleClick('.selector');Go back one page from the browser history.
$this->back();Go forward one page from the browser history.
$this->forward();Pauses the execution for a 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 secondsRefreshes the current page.
$this->refresh();Right click the element at the given selector.
$this->rightClick('.selector');Takes a full-page screenshot of the current page and saves it under /Browser/screenshots.
$this->screenshot('filename');Visits the given URL, and starts a new browser test.
$this->visit('https://pestphp.com');- assertAttribute
- assertAttributeContains
- assertAttributeDoesntContain
- assertAttributeMissing
- assertDontSee
- assertHasClass
- assertQueryStringHas
- assertQueryStringMissing
- assertPathBeginsWith
- assertPathEndsWith
- assertPathContains
- assertPathIs
- assertPathIsNot
- assertPresent
- assertNotPresent
- assertScript
- assertVisible
- assertMissing
- assertChecked
- assertNotChecked
Assert that the specified element has the expected attribute and value:
$this->visit($url) ->assertAttribute('html', 'data-theme', 'light');Assert that the specified element has the expected attribute and the value contains a specific value:
$this->visit($url) ->assertAttributeContains('html', 'data-theme', 'ight');Assert that the specified element has the expected attribute, but the value does not contain a specific value:
$this->visit($url) ->assertAttributeDoesntContain('html', 'data-theme', 'not here');Assert that the specified element is missing a particular attribute :
$this->visit($url) ->assertAttributeMissing('html', 'data-missing');Assert that the given text is not present on the page:
$this->visit($url) ->assertDontSee('we are a streaming service');Assert that the element has css classes bases upon string, array, regex
Given the html
<section> <div id="div-1" class="class-1"></div> <div id="div-2" class="class-1 class-2"></div> <div id="div-3" class="class-1 selected class-3"></div> <ul> <li class="component"></li> <li class="component selected"></li> <li class="component"></li> </ul> </section>$this->visit('/test/interactive-elements') ->assertHasClass('#div-1', 'class-1'); $this->visit('/test/interactive-elements') ->assertHasClass('#div-3', 'class-1 selected class-3'); $this->visit('/test/interactive-elements') ->assertHasClass('#div-3', '/(^|\s)selected(\s|$)/'); $this->visit('/test/interactive-elements') ->assertHasClass('ul > .component', ['component', 'component selected', 'component']);Assert that an element with the given selector is visible:
test('assert visible', function () { $this->visit($url) ->assertVisible('h1:visible'); });Assert that an element with the given selector is hidden:
test('assert missing', function () { $this->visit($url) ->assertMissing('a.hidden');Assert that the given query string is present in the url:
$this->visit($url) ->assertQueryStringHas('q', 'test');Assert that the given query string is not present in the url:
$this->visit($url) ->assertQueryStringMissing('q', 'test-1');Assert that the current URL path begins with the given path:
$this->visit($url) ->assertPathBeginsWith('/test');Assert that the current URL path ends with the given path:
$this->visit($url) ->assertPathEndsWith('/test');Assert that the current URL path contains the given path:
$this->visit($url) ->assertPathContains('/test');Assert that the current URL path matches the given path:
$this->visit($url) ->assertPathIs('/test'); // Asterisk (*) can be used as a wildcard $this->visit($url) ->assertPathIs('/test/*');Assert that the current URL path does not match the given path:
$this->visit($url) ->assertPathIsNot('/test');Assert that the given script returns the expected value:
$this->visit($url) ->assertScript('document.querySelector("title").textContent.includes("Laravel")', true);Assert that the element with a given selector is present on the page:
$this->visit($url) ->assertPresent('h1:visible');Assert that the element with a given selector is not present on the page:
$this->visit($url) ->assertNotPresent('a.non-existing-class');Assert that the element with a given selector is checked:
$this->visit($url) ->assertChecked('input[type="checkbox"].checked');Assert that the element with a given selector is not checked:
$this->visit($url) ->assertNotChecked('input[type="checkbox"].checked');