CAPABILITY GENERATOR

LambdaTest DocumentationAutomation Testing ● Quick Guide To Run PHP Tests on LambdaTest Selenium Grid

Quick Guide To Run PHP Tests on LambdaTest Selenium Grid


LambdaTest Selenium Automation Grid is an on cloud Selenium grid that you can leverage to run your automation test scripts on 2000+ different browser and operating system environments. It’s a scalable, reliable, and secure online Selenium grid infrastructure that not only helps you in increasing test coverage, but also cut down execution of your test automation builds by significant margin. This post will help you get started with running your PHP based Selenium automation scripts on LambdaTest Selenium grid.

Prerequisites


Running PHP scripts require your local system to have both PHP and Composer. Here’s how you can setup your PHP environment for running Selenium scripts.

  • First step is to install the latest PHP build. Latest MacOS systems come with PHP pre-installed, however for windows users and linux users, you can download PHP from here.
  • Next step is to install Composer. Open up terminal and navigate to the folder that have PHP installed. Run the following command.

  • If you are using xampp or mamp you may have to open up PHP shell by pressing the button shown in picture below.

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.

Sample PHP and Selenium Test To Get You started


Once you have installed and setup PHP and Selenium, you are now ready to run PHP automation scripts on LambdaTest Selenium Grid. Checkout the simple sample code below. This is a simple PHP and Selenium automation script that opens up google.com, search LambdaTest in google search and outputs the title of the resultant google search page. You can also fork it from our PHP GitHub repository.

PHP Sample Test

You can execute the test from your terminal through this command.

Do note the use of remote webdriver here. We have passed browser environment configurations through capabilities class. You can set your environment details as you wish.

To setup your own environment for the test you can leverage our Capability Generator tool.

Tear Down: The tear down method helps LambdaTest platform understand when the execution of a test is finished. It’s important to tear down each test or else it will give timeout errors