Top Related Projects
Python version of the Playwright testing and automation library.
A browser automation framework and ecosystem.
Fast, easy and reliable testing for anything that runs in a browser.
JavaScript API for Chrome and Firefox
Cross-platform automation framework for all kinds of apps, built on top of the W3C WebDriver protocol
Quick Overview
Symfony Panther is a browser testing and web scraping library for PHP. It provides a high-level API to control a real browser (Chrome or Firefox) and interact with web pages, making it a powerful tool for end-to-end (E2E) testing and web automation tasks.
Pros
- Real Browser Testing: Panther uses a real browser (Chrome or Firefox) to execute tests, providing a more accurate representation of how users interact with the application.
- Powerful API: Panther offers a comprehensive API that allows developers to perform a wide range of actions, such as clicking elements, filling forms, and asserting page content.
- Compatibility with Symfony: Panther is tightly integrated with the Symfony framework, making it easy to use in Symfony-based projects.
- Cross-Browser Support: Panther supports multiple browsers, including Chrome and Firefox, allowing developers to ensure their application works across different browsers.
Cons
- Performance: Using a real browser can be slower and more resource-intensive compared to headless browser testing solutions.
- Complexity: Integrating Panther into a project may require additional setup and configuration, which can add complexity to the development process.
- Dependency on Browser Drivers: Panther relies on browser drivers (e.g., ChromeDriver, GeckoDriver) to control the browser, which can introduce additional dependencies and potential compatibility issues.
- Limited to PHP Projects: Panther is primarily designed for PHP projects and may not be the best choice for applications built with other programming languages.
Code Examples
Here are a few examples of how to use Symfony Panther:
- Navigating to a Page and Asserting Content:
use Symfony\Component\Panther\PantherTestCase;
class MyTest extends PantherTestCase
{
public function testHomepage(): void
{
$client = static::createPantherClient();
$client->request('GET', '/');
$this->assertSelectorTextContains('h1', 'Welcome to my website');
}
}
- Interacting with Form Elements:
use Symfony\Component\Panther\PantherTestCase;
class MyTest extends PantherTestCase
{
public function testContactForm(): void
{
$client = static::createPantherClient();
$client->request('GET', '/contact');
$client->fillField('name', 'John Doe');
$client->fillField('email', 'john@example.com');
$client->fillField('message', 'Hello, I would like to get in touch.');
$client->submitForm();
$this->assertSelectorTextContains('h2', 'Thank you for your message!');
}
}
- Scraping Web Content:
use Symfony\Component\Panther\PantherTestCase;
class MyTest extends PantherTestCase
{
public function testWebScraping(): void
{
$client = static::createPantherClient();
$client->request('GET', 'https://example.com');
$title = $client->getCrawler()->filter('title')->text();
$this->assertSame('Example Domain', $title);
}
}
Getting Started
To get started with Symfony Panther, follow these steps:
- Install the Panther package using Composer:
composer require symfony/panther
- Create a test case that extends
PantherTestCase
:
use Symfony\Component\Panther\PantherTestCase;
class MyTest extends PantherTestCase
{
// Your test methods go here
}
-
Write your tests using Panther's API, such as
$client->request()
,$client->fillField()
, and$this->assertSelectorTextContains()
. -
Run your tests using the PHPUnit test runner:
./vendor/bin/phpunit
For more detailed information, please refer to the Symfony Panther documentation.
Competitor Comparisons
Python version of the Playwright testing and automation library.
Pros of Playwright-Python
- Supports multiple browsers (Chromium, Firefox, WebKit) out of the box
- Offers a more comprehensive API for modern web automation and testing
- Has better cross-language support (Python, JavaScript, .NET, Java)
Cons of Playwright-Python
- Steeper learning curve for beginners compared to Panther's simpler API
- Lacks built-in integration with PHP frameworks and testing tools
Code Comparison
Panther (PHP):
$client = Client::createChromeClient();
$crawler = $client->request('GET', 'https://example.com');
$crawler->filter('.my-class')->click();
$client->waitFor('.result');
Playwright-Python:
browser = playwright.chromium.launch()
page = browser.new_page()
page.goto("https://example.com")
page.click(".my-class")
page.wait_for_selector(".result")
Both libraries provide similar functionality for web automation, but Playwright-Python offers more flexibility and cross-browser support. Panther, on the other hand, is more tightly integrated with PHP ecosystems and may be easier for PHP developers to adopt. The choice between the two depends on the specific project requirements and the development team's expertise.
A browser automation framework and ecosystem.
Pros of Selenium
- Widely adopted and supported across multiple programming languages
- Extensive documentation and large community for support
- More mature project with a longer history of development and use
Cons of Selenium
- Requires separate WebDriver installation and management
- Can be slower due to external dependencies and communication overhead
- More complex setup and configuration process
Code Comparison
Selenium (Java):
WebDriver driver = new ChromeDriver();
driver.get("https://example.com");
WebElement element = driver.findElement(By.id("search"));
element.sendKeys("test");
element.submit();
Panther (PHP):
$client = Client::createChromeClient();
$crawler = $client->request('GET', 'https://example.com');
$form = $crawler->selectButton('Search')->form();
$crawler = $client->submit($form, ['q' => 'test']);
Both Selenium and Panther are tools for browser automation and testing, but they cater to different ecosystems and have distinct approaches. Selenium is a more established and versatile solution, while Panther is designed specifically for PHP projects and integrates well with Symfony components. Panther aims to simplify the setup process and provide a more streamlined experience for PHP developers, whereas Selenium offers broader language support and a more extensive feature set at the cost of increased complexity.
Fast, easy and reliable testing for anything that runs in a browser.
Pros of Cypress
- More extensive documentation and larger community support
- Built-in time travel and debugging capabilities
- Easier setup and configuration for most web applications
Cons of Cypress
- Limited to testing in-browser JavaScript
- Slower test execution compared to Panther
- Less flexibility in terms of browser support (primarily focuses on Chrome)
Code Comparison
Cypress example:
describe('Login Test', () => {
it('should login successfully', () => {
cy.visit('/login')
cy.get('#username').type('user@example.com')
cy.get('#password').type('password123')
cy.get('button[type="submit"]').click()
cy.url().should('include', '/dashboard')
})
})
Panther example:
public function testLogin()
{
$client = static::createPantherClient();
$client->request('GET', '/login');
$client->fillField('username', 'user@example.com');
$client->fillField('password', 'password123');
$client->submitForm('Login');
$this->assertStringContainsString('/dashboard', $client->getCurrentURL());
}
Both Cypress and Panther offer powerful tools for end-to-end testing, but they cater to different ecosystems and have distinct strengths. Cypress excels in JavaScript-based applications with its user-friendly interface and robust debugging tools, while Panther provides a more versatile solution for PHP developers and supports both JavaScript and PHP testing scenarios.
JavaScript API for Chrome and Firefox
Pros of Puppeteer
- More extensive API and features for browser automation
- Larger community and ecosystem, with more resources and third-party tools
- Native support for JavaScript, making it easier for web developers to adopt
Cons of Puppeteer
- Limited to JavaScript/Node.js environment
- Requires more setup and configuration for integration with PHP projects
- May have a steeper learning curve for PHP developers
Code Comparison
Puppeteer (JavaScript):
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({path: 'screenshot.png'});
await browser.close();
Panther (PHP):
$client = Client::createChromeClient();
$crawler = $client->request('GET', 'https://example.com');
$client->takeScreenshot('screenshot.png');
$client->close();
Both Panther and Puppeteer are powerful tools for browser automation and testing. Panther is specifically designed for PHP projects and integrates well with Symfony and other PHP frameworks. It provides a more native PHP experience and easier setup for PHP developers. Puppeteer, on the other hand, offers a more comprehensive set of features and has a larger community, but may require additional effort to integrate with PHP projects. The choice between the two depends on the specific project requirements and the development team's expertise.
Cross-platform automation framework for all kinds of apps, built on top of the W3C WebDriver protocol
Pros of Appium
- Cross-platform support for mobile testing (iOS, Android) and desktop applications
- Supports multiple programming languages (Java, Python, Ruby, etc.)
- Large community and extensive documentation
Cons of Appium
- Slower test execution compared to native automation tools
- Setup and configuration can be complex, especially for beginners
- Requires separate drivers for different platforms
Code Comparison
Appium (Python):
from appium import webdriver
desired_caps = {
'platformName': 'Android',
'deviceName': 'Android Emulator',
'app': '/path/to/app.apk'
}
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
Panther (PHP):
use Symfony\Component\Panther\Client;
$client = Client::createChromeClient();
$crawler = $client->request('GET', 'https://example.com');
Key Differences
- Panther is focused on PHP and web testing, while Appium supports multiple languages and platforms
- Panther integrates seamlessly with Symfony framework, whereas Appium is framework-agnostic
- Appium is primarily for mobile testing, while Panther is designed for web applications
- Panther uses ChromeDriver by default, while Appium requires platform-specific drivers
Both tools have their strengths, with Appium offering broader platform support and Panther providing a more streamlined experience for PHP developers working on web applications.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
A browser testing and web scraping library for PHP and Symfony
Panther is a convenient standalone library to scrape websites and to run end-to-end tests using real browsers.
Panther is super powerful. It leverages the W3C's WebDriver protocol to drive native web browsers such as Google Chrome and Firefox.
Resources
Save the Panthers
Many of the wild cat species are highly threatened. If you like this software, help save the (real) panthers by donating to the Panthera organization.
Credits
Created by Kévin Dunglas. Sponsored by Les-Tilleuls.coop.
Panther is built on top of PHP WebDriver and several other FOSS libraries. It has been inspired by Nightwatch.js, a WebDriver-based testing tool for JavaScript.
Top Related Projects
Python version of the Playwright testing and automation library.
A browser automation framework and ecosystem.
Fast, easy and reliable testing for anything that runs in a browser.
JavaScript API for Chrome and Firefox
Cross-platform automation framework for all kinds of apps, built on top of the W3C WebDriver protocol
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot