Skip to main content

Codeception Framework Integration to Run Codeception Selenium Tests on Online Grid

Powered by PHPUnit testing framework, and being BDD compatible, Codeception framework is a widely preferred test automation framework for performing unit testing, functional testing, and acceptance testing of a web application. Codeception framework provides versatile commands for validating structure and data of JSON & XML, so you could easily perform API testing throughout your extensive REST & SOAP API calls.

You can perform Selenium automation testing with Codeception across 2000+ browsers through our on-cloud Selenium Grid.

Prerequisites For Running PHP and Selenium#

All the code samples in this documentation can be found in the Codeception 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 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 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');"
  • If you are using Xampp or Mamp you may have to open up PHP shell by pressing the button shown in picture below.
XAMPP Control Panel

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#

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
  • Follow this documentation about Installing Extensions for Windows on the website.
  • You can even download PHP with this link for your respective Windows or Linux OS.

LambdaTest Authentication Credentials#

Be aware of your LambdaTest authentication credentials i.e. your LambdaTest username, access key and HubURL. You need to set them up as your environment variables. You can retrieve them from your LambdaTest automation dashboard by clicking on the key icon near the help button.

  • For Windows user:
  • For macOS/Linux user:

Integrating Codeception Framework With LambdaTest#

Now, that we are done with basic set up. We go ahead to run our first automation script through Codeception framework and LambdaTest Integration. Check out our GitHub repository for finding all the code references that will be discussed in this topic.

Below is a sample acceptance test through PHP.

<?phpclass FirstCest    {        public function frontpageWorks(AcceptanceTester $I)        {            sleep(5);            $I->amOnPage('/sample-todo-app');            sleep(2);            $I->checkOption('/html/body/div/div/div/ul/li[4]/input');            sleep(2);            $I->checkOption('/html/body/div/div/div/ul/li[5]/input');        }    }

Notice the declaration of class name “AcceptanceTester”. We used this class to specify test configuration, port number, browser name, browser version and other desired capabilities.

# Codeception Test Suite Configuration## Suite for acceptance tests.# Perform tests in browser using the WebDriver or PhpBrowser.# If you need both WebDriver and PHPBrowser tests - create a separate suite.  class_name: AcceptanceTestermodules:    enabled:        - WebDriver:            url: ''            host: '{username}:{token}' #provide your LambdaTest credentials            port: 80            browser: chrome                         capabilities:            name: 'Codeception Example'            build: '1.0'               browserName: 'Chrome' # request the latest version of chrome            platform: 'ANY'            version: '71.0'            tunnel: false # sets tunnel value to true for routing traffic through your local machine


In the above code, remember to replace the token and username with respect to your LambdaTest account. You can find these values from LambdaTest dashboard. Your token would be the Access key.

Configure LambdaTest Tunnel For Executing Your Codeception Selenium Tests With LambdaTest#

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 execute a test of your locally hosted Codeception Selenium instance on cloud to perform automated cross browser testing on 2000+ browsers offered by Selenium Grid on LambdaTest. So you make sure how well your changes look, even before your customers. Curious to know more about LambdaTest Tunnel?

Follow our documentation on LambdaTest Tunnel to know it all. OS specific instructions to download and setup tunnel binary can be found at the following links.

Download the binary file of:

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

Tunnel Capabilities

tunnel: true

Running Tests With Codeception Selenium and LambdaTest#

Execute the below command and you are all good to go!

./vendor/bin/codecept run --steps
Last updated on