Can Symfony Panther work with cloud-based services like BrowserStack or Sauce Labs?

Symfony Panther is a browser testing and web scraping library for PHP that leverages the WebDriver protocol. It primarily uses ChromeDriver and GeckoDriver to control browsers like Chrome and Firefox, respectively.

BrowserStack and Sauce Labs are cloud-based cross-browser testing services that provide remote WebDriver endpoints. This means that in theory, you can use any WebDriver-compatible tool, like Symfony Panther, with these services. However, there's a bit of setup required.

Here's how you can configure Symfony Panther to work with BrowserStack or Sauce Labs:

Using Symfony Panther with BrowserStack

  1. Update Panther's .env File:

Symfony Panther uses environment variables to configure the WebDriver server. You will need to set the PANTHER_WEBDRIVER_URL environment variable to point to your BrowserStack WebDriver URL.

   PANTHER_WEBDRIVER_URL=https://<your-username>:<your-access-key>@hub-cloud.browserstack.com/wd/hub
  1. Configure Desired Capabilities:

BrowserStack allows you to specify a wide range of capabilities, such as browser version, operating system, and resolution. You should configure these capabilities within your Panther test setup.

   // tests/someTest.php
   $client = \Symfony\Component\Panther\PantherTestCase::createPantherClient([
       'capabilities' => [
           'bstack:options' => [
               'os' => 'Windows',
               'osVersion' => '10',
               'local' => 'false',
               'seleniumVersion' => '3.14.0',
               // ... other BrowserStack-specific capabilities
           ],
           'browserName' => 'chrome',
           // ... other WebDriver capabilities
       ],
   ]);
  1. Run Your Tests:

When you run your Panther tests, they should now execute against the remote BrowserStack environment.

Using Symfony Panther with Sauce Labs

  1. Update Panther's .env File:

Similar to BrowserStack, set the PANTHER_WEBDRIVER_URL environment variable to your Sauce Labs WebDriver URL.

   PANTHER_WEBDRIVER_URL=https://ondemand.saucelabs.com:443/wd/hub
  1. Configure Desired Capabilities:

Again, you'll specify the desired capabilities for Sauce Labs within your Panther test setup.

   // tests/someTest.php
   $client = \Symfony\Component\Panther\PantherTestCase::createPantherClient([
       'capabilities' => [
           'sauce:options' => [
               'screenResolution' => '1024x768',
               // ... other Sauce Labs-specific capabilities
           ],
           'browserName' => 'chrome',
           // ... other WebDriver capabilities
       ],
   ]);
  1. Run Your Tests:

Execute your tests, and they should run on Sauce Labs' remote browsers.

Notes

  • Both BrowserStack and Sauce Labs require you to have an account and provide you with the necessary credentials (username and access key) to use their services.
  • The specific capabilities you set will vary depending on the browsers and systems you want to test against. Refer to BrowserStack's and Sauce Labs' documentation for the full list of supported capabilities.
  • If you're running tests in a CI/CD pipeline, make sure you inject the credentials and any other sensitive information securely, such as through encrypted environment variables.
  • The above examples are for illustration purposes. You might need to adjust the configuration based on the version of Symfony Panther you are using and the specific details of your test cases.

Remember that while Symfony Panther can be used for web scraping, using BrowserStack or Sauce Labs for web scraping might not align with their terms of service, which are generally focused on manual and automated testing of web applications. Always ensure that you comply with the terms of service of any third-party service you are using.

Get Started Now

WebScraping.AI provides rotating proxies, Chromium rendering and built-in HTML parser for web scraping
Icon