How to use BrowserStack with Symfony Panther

489 Views Asked by At

In the Symfony Panther docs it states:

Even if Chrome is the default choice, Panther can control any browser supporting the WebDriver protocol. It also supports remote browser testing services such as Selenium Grid (open source), SauceLabs and Browserstack.

But, there are no other documentation on how to do this.

How do you implement BrowserStack as a remote browser for Panther?

2

There are 2 best solutions below

1
On BEST ANSWER

This is how to create a new Panther client using a BrowserStack remote browser:

use Facebook\WebDriver\Remote\DesiredCapabilities;
use Symfony\Component\Panther\Client;

$capabilities = array(
    "os"                       => "OS X",
    "os_version"               => "Monterey",
    "browser"                  => "Chrome",
    "browser_version"          => "latest",
    "name"                     => "Test",
    "build"                    => "Build 1.0",
    "browserstack.debug"       => true,
    "browserstack.console"     => "info",
    "browserstack.networkLogs" => true,
    "disableCorsRestrictions"  => true,
    "wsLocalSupport"           => true,
    "geoLocation"              => "US"
);
$caps = DesiredCapabilities::chrome();
foreach ($capabilities as $key => $value) {
    $caps->setCapability($key, $value);
}
$client = Client::createSeleniumClient('https://[YOUR_BROWSERSTACK_USERNAME]:[YOUR_BROWSERSTACK_ACCESS_KEY]@hub-cloud.browserstack.com/wd/hub', $caps);

$client->request('GET', 'https://stackoverflow.com/');

You can see a list of capabilities here: https://www.browserstack.com/automate/capabilities

0
On