CAPABILITY GENERATOR

LambdaTest DocumentationAutomation Testing ● PHP With Selenium – Running PHP Automation Scripts On LambdaTest Selenium Grid

PHP With Selenium – Running PHP Automation Scripts On LambdaTest 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 on LambdaTest.

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

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

Prerequisites For Running PHP and Selenium


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

  • Set up PHP 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 setup.
  • Next step is to install Composer. Open up terminal and navigate to the folder that have PHP installed. Run the following command.

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.

Installing Selenium Dependencies For PHP


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:

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

Getting Started With PHP and 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.

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)

Execute The Test


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

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 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 code:

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:

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

Fields
Selected Values
Browser
Mozilla Firefox
Operating System
MacOS High Sierra
Resolution
1280×1024
Browser Version
64.0
Selenium Version
3.13.0

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

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 or Privately Hosted Projects


To help you perform cross browser testing of your locally stored web pages, LambdaTest provides an SSH(Secure Shell) tunnel connection with the name Lambda Tunnel. With Lambda 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. Lambda 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 Lambda Tunnel?

Follow our documentation on Lambda 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 Lambda 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 Lambda Tunnel zip file.

So for example, if your user login email is example@lambdatest.com and your user key is 123asd123, then the command would be:

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

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:

Queuing


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.