CAPABILITY GENERATOR

LambdaTestAutomation Testing ● Laravel Dusk Selenium: Running Laravel Dusk Testing Scripts on Online Selenium Grid

Laravel Dusk Selenium: Running Laravel Dusk Testing 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 Laravel Dusk Selenium on LambdaTest.

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

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

Prerequisites to Run Laravel Dusk Testing with Selenium


Before you begin automation testing with Laravel Dusk Selenium, be ready with the below essentials:

  • Make sure that you have the latest PHP build installed on your system. If you are using a Mac then PHP would be installed by default. For Linux you would need to enter the below command in terminal:

    For Windows, you can download PHP from here. Also, refer to this documentation for ensuring the accessibility of PHP through Command Prompt(cmd).
  • Install Laravel Dusk Framework using the below command with composer:

    If you don’t have composer installed in your system then click here.
  • 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.
  • Setting up project dependencies.
  • Check out our GitHub repository for finding all the code references that will be discussed in this topic.

Getting Started With Laravel Dusk Testing on LambdaTest


First, let us create .env from the example file:

Now we need to replace, LT_USERNAME with your LambdaTest username & LT_ACCESS_KEY with your access key. You can acquire both using LambdaTest Dashboard.

After that, you need to update platform configuration in driver method of tests/DuskTestCase.php, to specify the target where tests should run. (List of supported OS platfrom, Browser, resolutions can be found at LambdaTest Capability Generator)Sample configuration.

Running Tests On Locally Hosted Web Pages or Web Apps using Laravel Dusk Selenium


You can run Selenium test for your locally hosted webpages or web apps using the Lambda Tunnel or Underpass(GUI Tunnel Application). You will need to do the following for running Selenium test automation for locally or privately hosted projects.

  1. Download and install Lambda Tunnel or Underpass in your system.
  2. Define tunnel capability to true in DesiredCapabilities class.
  3. Specify your local testing URL or DNS.

Let us look at each of these steps in detail.

Download and Install Lambda Tunnel or Underpass


Download the binary file of:

To install and run Lambda Tunnel, you can follow our step-by-step documentation.

Or if you wish to avoid Command Line Interface then you can use the Underpass application.
LambdaTest username & accesskey
Download:

For more details, refer to the support documentation of Underpass.

Define tunnel capability to true


After installing and running the Lambda Tunnel, you now need to specify the tunnel value to true in your desired capabilities.

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. You will find the capabilities in the driver method of tests/DuskTestCase.php on our Laravel Dusk Testing GitHub Repository.

You can easily generate the DesiredCapabilities with our Selenium Capabilities Generator.

Specify your local testing URL or DNS


Important Note: 127.0.0.1 IP address won’t work when using tunnel as different browsers exhibit different behaviours. You can use localhost, localhost.lambdatest.com, any custom domain if that’s entered into your etc/hosts file, or you can specify a custom domain that is managed by a custom DNS server, provided that you explicitly pass DNS server details while initiating the tunnel.

To explicitly pass DNS server details through Lambda Tunnel you will need to use the --dns argument and pass the local host string i.e. 127.0.0.1:port number as the value while triggering the tunnel.

Note: For PHP Laravel, 127.0.0.1:53 is the default value so you will need to specify that.

The command-syntax would look like:

Here is an example of this command:

To explicitly pass DNS server details through the Underpass application, you will need to go to Advanced settings and provide 127.0.0.1:53 for PHP Laravel as the value for the DNS Server field.

LambdaTest Underpass

Test Scenario: Sample To Do App

You can find all the code files in our Laravel Dusk Testing GitHub Repository.

Let us quickly analyze our test scenario: Visit the Sample To Do App, check the first and second item from the list and add a new item i.e. ‘sampletodotext’. Here is the code file for it.

Execute The Laravel Dusk Testing Script


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