1

Does PHPUnit have a Scriptable Web Browser and Web Test capabilities, e.g. to fetch a page from a PHP script served on localhost, and then to click on elements, fill out & submit forms and assert the returned page content?

I am familiar with SimpleTest, and it has excellent classes and assertions for this. Also, the Zend framework seems to have a PHPUnit extension. However, I cannot find docs/examples of how to do web testing with PHPUnit (out-of-the-box) to cover functionality like sessions, form handling, clicking, navigation, ajax, etc..

I am looking for a way to have PHPUnit test my server side PHP code through HTML, thus testing my application from the vantage point of a user/visitor. I am not looking for a browser extension or any other kind of record & playback test framework like Selinium.

8
  • 1
    AFAIK there isn't anything in PHPUnit to do what you are after. Commented Apr 3, 2020 at 7:11
  • What you're describing are not unit tests, but rather acceptance tests. Read about those. Commented Apr 3, 2020 at 7:12
  • 1
    You can take a look at this and before you discard it based on the title, this isn't about Selenium's record & play tool, it's about Selenium WebDriver. My previous company used it with PHP to automate acceptance test. We haven't used it with PHPUnit, scripts were done in another way. Commented Apr 3, 2020 at 16:12
  • 1
    You can use this package github.com/laravel/browser-kit-testing or laravel.com/docs/7.x/dusk . It's for browser testing. What you are looking for is browser testing. Commented Apr 12, 2020 at 12:01
  • 1
    You don't need to install Laravel, to have dusk or browser-kit-testing, they are both standalone packages, you can freely use them. You can check it from composer.json file in the repository Commented Apr 14, 2020 at 6:52

1 Answer 1

2

Sounds like what you are looking to write are acceptance tests. Codeception is a popular tool for this in PHP & is built on top of PHPUnit. It lets you write tests that can navigate your pages & look like:

class FirstCest
{
    public function frontpageWorks(AcceptanceTester $I)
    {
        $I->amOnPage('/');
        $I->click('View More');
        $I->see('Details');
    }
}

https://codeception.com/

Sign up to request clarification or add additional context in comments.

1 Comment

This is indeed nice. I haven't tried it, but will add here (for others) that according to the docs "It's PHP script that can check HTML page contents, click links, fill forms, and submit POST and GET requests. For more complex tests that require a browser use Selenium with WebDriver module."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.