Skip to main content

PHP Automated Testing: Run PHP Web Automation Scripts On Online Selenium Grid

Execute your automation test scripts with Selenium WebDriver instantly through LambdaTest which is a cloud-based, cross browser testing tool offering a Selenium Grid consisting 2000+ browsers and browser versions running on real operating systems to pace up automation testing of your web-app or website. In this topic, you will learn how to automate your website testing using Selenium with PHP Web Automation on LambdaTest.

By the end of this topic, you will be able to:

  1. Run a sample Selenium with PHP web automation on LambdaTest.
  2. Set up an environment for testing your locally hosted web pages using PHP automated testing.
  3. Understand & configure PHP desired capabilities for executing a PHP web automation test.
  4. Explore advanced features of LambdaTest.

Prerequisites For Running PHP Automated Testing#

All the code samples in this documentation can be found in the PHP LambdaTest Repository on Image GitHub. You can either download or clone the repository to quickly run your tests.

Before you begin automation testing with Selenium and PHP, be ready with the below essentials:

  • Install the latest PHP web automation build for your OS. Mac OS X 5.3 or higher version comes with PHP installed. However, for windows users and linux users, you can download PHP from here.

  • If you are using Windows, to get better performance LambdaTest recommends to enable the PHP curl library and OpenSSL support from PHP automated testing setup.

  • Next step is to install Composer. Open up terminal and navigate to the folder that have PHP installed. Run the following command.

php -r "copy('', 'composer-setup.php');"php -r "if (hash_file('sha384', 'composer-setup.php') === '93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"php composer-setup.phpphp -r "unlink('composer-setup.php');"

Once you have composer installed, you can leverage Composer to download and install Selenium dependencies. For that first create a composer.json file in your directory and add the following code to the json.

{  "require": {    "phpunit/phpunit-selenium": "*",    "facebook/webdriver": "dev-master"  }}

Installing Selenium Dependencies For PHP Automated Testing#

Now all you would have to do is to run composer to install Selenium. You can do that by running following command in your terminal:

composer install

If you are using Xampp or Mamp you may have to be a little more specific.

php composer.phar install

Getting Started With PHP Automated Testing on LambdaTest#

After you have everything installed and set up, you can run the LambdaTest.php example test that’s included with LambdaTest to make sure everything works.

//To run the demo test on Mac OS X/Linux
vendor/bin/phpunit LambdaTest.php
//To run the demo test on Windows
bat vendor\bin\phpunit.bat LambdaTest.php

No output may be visible initially, but after a while, you can see a series of dots inching across the screen. This starts the PHPUnit test runner and gives it the name of an example test suite that LambdaTest downloaded. PHPUnit will start in a few moments.

Let us have a look at an example which will validate your LambdaTest credentials for authentication purpose. Later, the code will select the basic capabilities such as OS, browser, browser version and so on. This code is also available on our PHP GitHub repository for you to clone and play around. (smile)

<?php require 'vendor/autoload.php'; $GLOBALS['LT_USERNAME'] = getenv('LT_USERNAME');if(!$GLOBALS['LT_USERNAME']) $GLOBALS['LT_USERNAME'] = "************************************";$GLOBALS['LT_APPKEY'] = getenv('LT_APPKEY');if(!$GLOBALS['LT_APPKEY']) $GLOBALS['LT_APPKEY'] = "*****************************************";$GLOBALS['LT_BROWSER'] = getenv('LT_BROWSER');if(!$GLOBALS['LT_BROWSER']) $GLOBALS['LT_BROWSER'] = "chrome";$GLOBALS['LT_BROWSER_VERSION'] = getenv('LT_BROWSER_VERSION');if(!$GLOBALS['LT_BROWSER_VERSION']) $GLOBALS['LT_BROWSER_VERSION'] ="63.0";$GLOBALS['LT_OPERATING_SYSTEM'] = getenv('LT_OPERATING_SYSTEM');if(!$GLOBALS['LT_OPERATING_SYSTEM']) $GLOBALS['LT_OPERATING_SYSTEM'] = "win10"; class LambdaTest{    protected static $driver;   public function testAdd() {                     $url = "https://". $GLOBALS['LT_USERNAME'] .":" . $GLOBALS['LT_APPKEY'] ."";              $desired_capabilities = new DesiredCapabilities();        $desired_capabilities->setCapability('browserName',$GLOBALS['LT_BROWSER']);        $desired_capabilities->setCapability('version', $GLOBALS['LT_BROWSER_VERSION']);        $desired_capabilities->setCapability('platform', $GLOBALS['LT_OPERATING_SYSTEM']);        $desired_capabilities->setCapability('name', "PHPTestSample");        $desired_capabilities->setCapability('build', "LambdaTestSampleApp");        self::$driver = RemoteWebDriver::create($url, $desired_capabilities);      
        $itemName = 'Yey, Lets add it to list';        self::$driver->get("");        $element1 = self::$driver->findElement(WebDriverBy::name("li1"));        $element1->click();        $element2 = self::$driver->findElement(WebDriverBy::name("li2"));        $element2->click();                 $element3 = self::$driver->findElement(WebDriverBy::id("sampletodotext"));        $element3->sendKeys($itemName);                 $element4 = self::$driver->findElement(WebDriverBy::id("addbutton"));                   $element4->click();                 self::$driver->wait(10, 500)->until(function($driver) {           $elements = $driver->findElements(WebDriverBy::cssSelector("[class='list-unstyled'] li:nth-child(6) span"));           return count($elements) > 0;        });        self::$driver->quit();    }        }  $lambdaTest = new LambdaTest();  $lambdaTest->testAdd();?>

Execute The PHP Automated Testing Scripts#

You would need to execute the below command in your terminal/cmd.

php tests\LambdaTest.php

Understanding & Configuring PHP Desired Capabilities#

To executes test on a remote browser, you will have to configure a couple of capabilities to run your PHP web automation based test suite on the LambdaTest Selenium grid.

For performing the tests on LambdaTest’s Firefox browser, the code has to be modified a bit. To run the code on Firefox browser hosted by LambdaTest, you’d need to add the following command to your existing PHP web automation code:

FirefoxDriver driver = new FirefoxDriver();

To run on LambdaTest Selenium grid, you would have to change its remote webdriver and at the same time pass capabilities related to browser, browser versions etc. In simple terms, it would look something like this:

self::$driver = RemoteWebDriver::create("https://Username:[email protected]/wd/hub", $desired_capabilities);

Our Capabilities Generator will automatically generate the program, based on your provided input. For Instance, if you select the below configurations:

FieldsSelected Value
BrowserMozilla FireFox
Operating SystemMacOS High Sierra
Browser Version64.0
Selenium Version3.13.0

Then Capabilities Generator at LambdaTest will provide you with the below program:

//Basic Test Configurations For PHP
$capabilities = array(    "build" => "your build name",    "name" => "your test name",    "platform" => "macOS High Sierra",    "browserName" => "Firefox",    "version" => "64.0",    "resolution" => "1280x1024",    "selenium_version" => "3.13.0",    "screenshot" => true,    "firefox.driver" => v0.23.0    )

The most important capabilities to understand here are ‘browserName’, ‘versions’, and ‘platform’. They define which browser environment you wish to run the test on. Rest of the capabilities are important in test management and debugging. We have a inbuilt capabilities generator tool as well that you use to generate capabilities code for your test suite.

Advanced LambdaTest Capabilities#

In addition to default Selenium Grid capabilities, LambdaTest also has platform specific capabilities like video recording of test runs, console logs of each test run, network logs of each test run, custom profiles for specific browsers, etc. Do checkout our documentation on LambdaTest Advanced Capabilities as well.

Testing Locally Hosted Projects Using PHP Automated Testing#

To help you perform cross browser testing of your locally stored web pages, LambdaTest provides an SSH(Secure Shell) tunnel connection with the name LambdaTest Tunnel. With LambdaTest Tunnel, you can test your locally hosted files before you make them live over the internet. You could even perform cross browser testing from different IP addresses belonging to various geographic locations. LambdaTest Tunnel would help you to test web-apps and websites that are only accessible internally through a corporate firewall. The SSH tunnel provided by LambdaTest acts as a proxy server for hosting your web pages from your local machine to Virtual machines running on LambdaTest cloud servers. Curious to know more about LambdaTest Tunnel?

Follow our documentation on LambdaTest Tunnel to know it all.

To perform cross browser testing for your locally stored web pages or web apps. You would need to download a binary zip file of LambdaTest Tunnel with respect to your device’s operating system.

You can start tunnel by executing the below command in your cmd(Command Prompt) / terminal. Make sure that your pointer is routed in the same directory where you extract the downloaded LambdaTest Tunnel zip file.

//Syntax To Start LambdaTest Tunnel
LT -user [user's login email] -key [user's access key]

So for example, if your user login email is [email protected] and your user key is 123asd123, then the command would be:

//Example Command To Start LambdaTest Tunnel
LT -user [email protected].com -key 123asd123

Once, the tunnel is successfully set up. You can add the below code to your capabilities for testing internal servers on your network.

$capabilities = array(        "tunnel" => true,)

You can also add the capability using LambdaTest Capabilities Generator.

Tunnel Reference: For a full reference of all tunnel features we support, visit our [tunnel page](

Mark Tests As Pass Or Fail#

While performing automation testing using Selenium with Python through LambdaTest Selenium grid, it is imperative to flag an automation test as either pass or fail. This is completely dependent on your testing requirement with respect to the validation of expected behavior. You can mark whether an automation test passed or failed by adding the below code fragment in your automation script:

//Mark Pass/ Fail Status


To prevent over-exploitation of the platform we have added a capacity constraint on the number of tests that can be queued at our platform. Your maximum queue capacity will be dependent upon the number of concurrent sessions your LambdaTest account is eligible for. Below formula will help you calculate the maximum capacity for your queue.

Maximum Queue Capacity

Maximum number of test cases that can be queued = n + 150

Here, n = number of concurrent sessions.

For instance, if you are opting for pricing where you can avail up to 10 concurrent sessions. Then the maximum number of test cases that can be queued will be equal to 10 + 150 i.e. 160 queued test cases. LambdaTest would automatically schedule and execute test cases for you.

Here you can get more information about LambdaTest Queuing Policy.

Queuing Timeout

There is also a limit on how long a test case can stay in the queue. If your test case stays in the queue for more than 15 minutes, the test case would be timed out and would not be executed.

Last updated on