Turn your manual testers into automation experts Request a DemoStart testRigor Free

Drupal Testing

ASP.Net Testing

Drupal is a widely used open-source content management system (CMS) written in PHP that is used to build websites. Its feature-rich platform makes it flexible and a popular choice for CMS web development. Like any other website, a website built with Drupal requires thorough testing.

Let's dive deeper into the Drupal ecosystem and understand how to test these websites using the tools that are provided within the Drupal ecosystem and also look into other efficient tools to achieve a seamless user experience.

What is Drupal?

Drupal is a powerful CMS that is largely used to create websites. Many government agencies, educational institutions, and businesses build their websites using Drupal.

Advantages of Using Drupal

Some advantages of adopting Drupal to build your website are:
  • Drupal is an open-source framework.
  • It is a flexible platform that works well with different content types. It is adopted as a CMS as well as a development platform. With provisions for custom content types and views, to name a few of the available features, Drupal is truly a flexible platform.
  • Drupal is great for complex projects and websites due to its feature-rich platform.
  • It is SEO friendly, allowing the website author to add tags and keywords.
  • It provides a secure platform for building a website.
  • Has a lot of add-on options for custom themes and modules, providing full control over the visual display of content on the website.
  • The Drupal community is active and responsive. Hence it is easy to find answers to the most common challenges and get help from the community.

How Can You Test These Websites?

Testing websites built using Drupal primarily rely on PHP, JavaScript, and Drupal extensions, with the PHPUnit framework at the heart of it. Following are the ways to test these websites:
  • Unit testing
  • Kernel testing
  • End-to-end testing

Drupal Unit Testing

Use the PHPUnit testing framework for Drupal unit testing as a foundation for your testing strategy. PHPUnit installation is straightforward: just run composer require --dev phpunit/phpunit in the root directory of your Drupal project.

Once you start creating unit tests, just keep these basic rules in mind:
  • The base class \Drupal\Tests\UnitTestCase is implemented to create unit test cases. This class provides helpers and a base class for writing unit tests.
  • All unit test file names should follow *Test.php pattern
  • All method names should follow test* pattern (e.g.: testGetLocation())
Here's an example of a unit test case:
<?php

namespace Drupal\phpunit_my_example;

class Unit {

  private $length = 0;

  public function setLength(int $length) {
    $this->length = $length;
  }

  public function getLength() {
    return $this->length;
  }

}

Drupal Kernel Testing

This type of testing is an intermediate between unit testing and functional testing, helping to verify the integrations of various modules. With kernel testing, you can test limited Drupal interactions. However, it does not apply to those test scenarios that require browser or UI interactions.

Kernel tests operate in a partial Drupal environment, meaning only the core of Drupal is enabled. The base class \Drupal\KernelTests\KernelTestBase is implemented to write kernel test cases. This base class partially boots Drupal for these tests and allows the loading of services and hooks of other modules.

When it comes to any modules, they will need to be enabled manually. To install, use:
  • ::installSchema () for database tables
  • ::installConfig () for default configuration
  • ::installEntitySchema () for, you guessed it - entities
Here's what a simple test case written as a method looks like:
public function testLabel() {
  $label = $this->myService->getLabel('my_service_test');
  $this->assertTrue($label == 'My Test Label', $label);
}

public function testMessage() {
  $message = $this->myService->getMessage('my_service_test');
  $this->assertTrue($message == 'My Test Message', $message);
}

To run your tests, you can either use PHPUnit (although you won't get a very detailed output), or a run-tests.sh script - which is already included with each Drupal installation. We recommend using this script since it provides a much nicer and more detailed output.

Drupal End-to-end Testing

Functional tests are meant to consider entire features, not just bits and pieces of code. They can be done using the following:
  • Browser testing
  • Javascript based testing
  • Using Selenium-based tools
  • testRigor

Drupal Browser Testing

These tests have the full Drupal functionality and an internally simulated web browser at their disposal. These tests are meant to test top-level tests of integrations between different Drupal systems. They are usually written for scenarios where JavaScript testing is not involved. The base class \Drupal\Tests\BrowserTestBase is involved in writing browser test cases.

In case you've previously had a chance to use WebTestBase, then BrowserTestBase is what replaces it, and you should be able to convert your old tests to BrowserTestBase rather easily.

Here's all the detailed information you would need to get familiar with these tests.

Drupal JavaScript Testing

In comparison to other tests, the JavaScript function tests in Drupal are executed in an actual browser to test JavaScript and AJAX functionalities.The base class \Drupal\FunctionalJavascriptTests\WebDriverTestBase is implemented to write JavaScript test cases. This base class runs a driver that is able to support JavaScript.

To get familiar with how to write JavaScript test cases for drupal, take a look at this detailed tutorial.

Functional UI End-to-end Testing With testRigor

Tests created with testRigor are the closest to representing the actual behavior of your users. Tests are on the UI layer, meaning that no details of implementation are involved. And while end-to-end tests typically represent the entire flows, they are known to be the most fragile and slow. Not with testRigor! Tests are extremely robust and stable, and test maintenance issues are completely solved, with users now spending 95% less time on test maintenance.

The best part is that testRigor is a cloud-hosted codeless solution, meaning that anyone on the team will be able to create, edit, and maintain such tests. You can create tests going through an entire user flow in plain English, and get test results with detailed screenshots for each step - making it extremely easy to debug.

There are a lot of handy built-in features; for example, testRigor is great for testing tables. You can also easily test emails and SMS alerts.

Here's a sample test for testing a table:
open url "https://testrigor.com/samples/table1/"
enter "This is a trap!" into table "table table-responsive table-striped table-hover table-bordered" at row "101" and column "Additional Data"
And another one for testing an email:
send email to "[email protected]" with subject "Test message" and  body "Hi, new content is available."
check that email from "[email protected]" is delivered

You can find more benefits of using testRigor here.

How to do End-to-end Testing with testRigor

Let us take the example of an e-commerce website that sells plants and other gardening needs. We will create end-to-end test cases in testRigor using plain English test steps.

Step 1: Log in to your testRigor app with your credentials.

Step 2: Set up the test suite for the website testing by providing the information below:

  • Test Suite Name: Provide a relevant and self-explanatory name.
  • Type of testing: Select from the following options: Desktop Web Testing, Mobile Web Testing, Native and Hybrid Mobile, based on your test requirements.
  • URL to run test on: Provide the application URL that you want to test.
  • Testing credentials for your web/mobile app to test functionality which requires user to login: You can provide the app’s user login credentials here and need not write them separately in the test steps then. The login functionality will be taken care of automatically using the keyword login.
  • OS and Browser: Choose the OS Browser combination on which you want to run the test cases.
  • Number of test cases to generate using AI: If you wish, you can choose to generate test cases based on the App Description text, which works on generative AI.

Step 3: Click Create Test Suite.

On the next screen, you can let AI generate the test case based on the App Description you provided during the Test Suite creation. However, for now, select do not generate any test, since we will write the test steps ourselves.

Step 4: To create a new custom test case yourself, click Add Custom Test Case.

Step 5: Provide the test case Description and start adding the test steps.

For the application under test, i.e., e-commerce website, we will perform below test steps:

  • Search for a product
  • Add it to the cart
  • Verify that the product is present in the cart

Test Case: Search and Add to Cart

Step 1: We will add test steps on the test case editor screen one by one.

testRigor automatically navigates to the website URL you provided during the Test Suite creation. There is no need to use any separate function for it. Here is the website homepage, which we intend to test.

First, we want to search for a product in the search box. Unlike traditional testing tools, you can identify the UI element using the text you see on the screen. You need not use any CSS/XPath identifiers.

For this search box, we see the text “What are you looking for?” So, to activate the search box, we will use the exact text in the first test step using plain English:
click "What are you looking for?"

Step 2: Once the cursor is in the search box, we will type the product name (lily), and press enter to start the search.

type "lily"
enter enter

Search lists all products with the “lily” keyword on the webpage.

Step 3: The lily plant we are searching for needs the screen to be scrolled; for that testRigor provides a command. Scroll down until the product is present on the screen:

scroll down until page contains "Zephyranthes Lily, Rain Lily (Red)"

When the product is found on the screen, testRigor stops scrolling.

Step 4: Click on the product name to view the details:

click "Zephyranthes Lily, Rain Lily (Red)"

After the click, the product details are displayed on the screen as below, with the default Quantity as 1.

Step 5: Lets say, we want to change the Quantity to 3, so here we use the testRigor command to select from a list.

select "3" from "Quantity"
After choosing the correct Quantity, add the product to the cart.
click "Add to cart"

The product is successfully added to the cart, and the “Added to your cart:” message is displayed on webpage.

Step 6: To assert that the message is successfully displayed, use a simple assertion command as below:

check that page contains "Added to your cart:"

Step 7: After this check, we will view the contents of the cart by clicking View cart as below:

click "View cart"

Step 8: Now we will again check that the product is present in the cart, under heading “Your cart” using the below assertion. With testRigor, it is really easy to specify the location of an element on the screen.

check that page contains "Zephyranthes Lily, Rain Lily (Red)" under "Your cart"

Complete Test Case

Here is how the complete test case will look in the testRigor app. The test steps are simple in plain English, enabling everyone in your team to write and execute them.

Click Add and Run.

Execution Results

Once the test is executed, you can view the execution details, such as execution status, time spent in execution, screenshots, error messages, logs, video recordings of the test execution, etc. In case of any failure, there are logs and error text that are available easily in a few clicks.

You can also download the complete execution with steps and screenshots in PDF or Word format through the View Execution option.

testRigor’s Capabilities

Apart from the simplistic test case design and execution, there are some advanced features that help you test your application using simple English commands.

  • Reusable Rules (Subroutines): You can easily create functions for the test steps that you use repeatedly. You can use the Reusable Rules to create such functions and call them in test cases by simply writing their names. See the example of Reusable Rules.
  • Global Variables and Data Sets: You can import data from external files or create your own global variables and data sets in testRigor to use them in data-driven testing.
  • 2FA, QR Code, and Captcha Resolution: testRigor easily manages the 2FA, QR Code, and Captcha resolution through its simple English commands.
  • Email, Phone Call, and SMS Testing: Use simple English commands to test the email, phone calls, and SMS. These commands are useful for validating 2FA scenarios, with OTPs and authentication codes being sent to email, phone calls, or via phone text.
  • File Upload/ Download Testing: Execute the test steps involving file download or file upload without the requirement of any third-party software. You can also validate the contents of the files using testRigor’s simple English commands.
  • Database Testing: Execute database queries and validate the results fetched.

testRigor enables you to test web, mobile (hybrid, native), API, and desktop apps with minimum effort and maintenance.

Additional Resources

Conclusion

Like testing any other website, Drupal-based websites also require unit testing, kernel testing, and end-to-end testing. We hope that this article provides you with the tools needed to build a robust testing strategy - and make your customers satisfied with high-quality software.

You're 15 Minutes Away From Automated Test Maintenance and Fewer Bugs in Production
Simply fill out your information and create your first test suite in seconds, with AI to help you do it easily and quickly.
Achieve More Than 90% Test Automation
Step by Step Walkthroughs and Help
14 Day Free Trial, Cancel Anytime
“We spent so much time on maintenance when using Selenium, and we spend nearly zero time with maintenance using testRigor.”
Keith Powe VP Of Engineering - IDT