Using Cucumber with Selenium – a tutorial  

Automation testing is a vital part of modern software development, ensuring applications work correctly across all browsers and devices. Two of the most widely used tools for automation testing are Selenium and Cucumber. Together, they provide a robust solution for developers who want a code-driven test automation framework with impressive functionality and control, as well as the ability to write flexible test cases that can be easily adapted. 

But what if you’re looking for a more user-friendly, GUI-based solution that non-developers can also engage with? After all, not everyone on your team is a coding expert. That’s where T-Plan comes in, adding depth and usability to your automation strategy. This guide will first walk you through using Cucumber with Selenium for automated testing. Then, we’ll show how T-Plan enhances this setup by adding powerful image-based capabilities and an intuitive interface, allowing non-developers to dive into test automation as well. 

software testing

Table of Contents

What is Selenium and why pair It with Cucumber? 

Understanding Selenium 

Selenium is a popular open-source tool designed for automating web browsers, making it a cornerstone of browser testing. It’s widely used for functional testing of web applications and is especially favoured by developers for its code-centric nature. Selenium’s capabilities are extensive; it automates browsers, interacts with elements like buttons, forms and links, and integrates with several programming languages, including Java and Python. With Webdriver driver, developers can create scripts to automate almost any interaction on a webpage, giving full control over software testing in browser environments. 

Introduction to Cucumber 

The cucumber framework is an open-source testing tool that supports behavior driven development (BDD). It allows test scenarios to be defined in plain language using Gherkin syntax, making tests more accessible to non-developers. By combining Cucumber with Selenium, you can define tests in simple language that anyone on the team can understand while using Selenium to automate and execute these scenarios. Each scenario is written in a feature file, which describes the intended behaviour of the application in plain text, specifying the value expected from various inputs. Additionally, Cucumber utilizes feature files to describe the behavior of the application in a structured way, making it easy to manage and execute tests. 

Code example: Cucumber-Selenium integration 

Here is an example demonstrating how Cucumber and Selenium work together and how developers can write effective, human-readable tests. Additional API requests can also be embedded to test backend responses. 

// Step Definitions (Selenium Code) 

@Given(“the user is on the login page”) 

public void navigateToLoginPage() { 

    driver.get(“http://example.com/login”); 

} 

@When(“the user enters valid credentials”) 

public void enterCredentials() { 

    driver.findElement(By.id(“username”)).sendKeys(“testUser”); 

    driver.findElement(By.id(“password”)).sendKeys(“password123”); 

    driver.findElement(By.id(“loginButton”)).click(); 

}  

@Then(“the user should be redirected to the dashboard”) 

public void verifyDashboard() { 

    String title = driver.getTitle(); 

    assertEquals(“Dashboard”, title); 

} 

In this example, the test steps are straightforward to create and interpret. The Gherkin syntax used in the Cucumber framework allows tests to be written in a way that’s clear to all team members. Tests can also be modified to include API calls where backend validation is required, thereby enhancing the overall quality of software testing using the Cucumber Selenium integration. 

Benefits of Cucumber with Selenium 

The integration of Cucumber and Selenium provides valuable benefits, especially when adapting to new project requirements including: 

  • Readable test scenarios: The ability to create tests in plain English makes it easier for non-developers to understand, but it also opens up collaboration between technical and non-technical team members. 
  • Clear separation of concerns: With Cucumber defining the test logic and Selenium handling execution, this combination provides a well-organised, structured testing framework that simplifies maintenance. This separation is ideal for agile, fast-paced teams looking for both flexibility and power. 
  • API Testing Compatibility: Integrating API calls within Cucumber and Selenium tests allows for complete end-to-end testing of web applications, ensuring backend responses are consistent with frontend functionality. 

Limitations of Cucumber and Selenium 

Developer-centric nature 

While Cucumber simplifies test scenarios, using it with Selenium still requires significant coding knowledge for test implementation. This dependency on code makes it less accessible for non-developers, who may struggle with configuring, setting up and executing tests without technical skills. For teams aiming to involve QA professionals or business stakeholders in testing, this code-centric approach can be limiting.  

Minimal GUI support in Cucumber-Selenium 

Cucumber and Selenium lack a straightforward graphical user interface, which restricts non-technical users from creating and managing tests independently. Without a user-friendly GUI, these tools require command-line operations and manual coding – two things that non-developers often find intimidating. This absence of front-end functionality means that the overall process of test creation and management can be cumbersome for teams lacking development expertise, potentially blocking collaboration on critical test automation projects. 

How T-Plan enhances the Selenium and Cucumber setup 

Introduction to T-Plan 

T-Plan was designed to bridge gaps in traditional automation frameworks like Selenium and Cucumber, offering capabilities that make it uniquely suited for complex and dynamic testing needs. T-Plan supports not only web and mobile applications but also more intricate environments, including desktop and virtual applications. With features such as image-based automation for testing visual elements and an intuitive, GUI-driven interface, T-Plan allows both technical and non-technical users to engage seamlessly with test automation. Learn more about T-Plan’s GUI testing and image-based automation. T-Plan also enables API testing integration, supporting robust, end-to-end software testing in complex workflows. 

The intuitive GUI advantage 

Unlike the code-centric interfaces of Selenium and Cucumber, T-Plan provides a refreshing alternative with its GUI-driven approach. T-Plan’s interface offers simplicity and accessibility: 

  • Streamlined test creation: The graphical interface removes the need for coding, making test automation accessible to everyone – from developers to business analysts – allowing teams to set up tests quickly and efficiently. 
  • Fostering collaboration: By enabling easy test creation, T-Plan bridges the gap between technical and non-technical team members, reducing bottlenecks and making the process collaborative. 
  • Enhanced integration with Selenium: T-Plan integrates Selenium within its user-friendly interface, so users can still leverage Selenium’s robust automation while enjoying T-Plan’s streamlined process. Explore T-Plan’s Selenium integration to learn how it simplifies the experience for users of all skill levels. 

Commercial benefits of T-Plan over Cucumber and Selenium 

For organisations seeking a no-code or low-code solution, T-Plan provides an ideal framework for expanding automation testing to cross-functional teams. Its GUI-driven design supports a range of testing scenarios across sectors, including finance, healthcare and regulated industries where security and compliance are essential. T-Plan’s accessibility for non-developers ensures that all team members can contribute to automation, improving productivity and supporting collaborative workflows. 

Image-based testing capabilities 

Where Cucumber and Selenium rely on DOM elements, T-Plan uses image recognition to interact directly with on-screen visuals, providing more comprehensive test coverage for elements like calendars and multimedia content. This image-based testing is especially useful in applications requiring visual precision, such as in banking apps, where graphical security components must be validated, or e-commerce platforms with dynamic product displays. Discover T-Plan’s image-based testing to see how it supports sophisticated, dynamic elements. 

Code Example: Image-Based Testing in T-Plan 

// Image-Based Testing Example in T-Plan Robot 

public void testCalendar() { 

    captureWindow(“Application”); 

    clickOnImage(“calendar_icon.png”);  // Interact with a calendar widget based on its image 

    clickOnImage(“date_15.png”);        // Select a specific date using image recognition 

} 

Support and community 

While Selenium and Cucumber offer community-based support, T-Plan provides commercial-grade support directly from its development team, ensuring reliable, personalised assistance. This support is especially valuable for organisations with complex automation needs, where guidance on customisation, scaling and integration is essential for success. 

Step-by-step guide – setting up and running tests with T-Plan 

Installing T-Plan and integrating Selenium 

To begin using T-Plan, download and set up T-Plan Robot, configure Java and integrate Selenium WebDriver for seamless automation testing. 

  1. Download and install T-Plan Robot: Access the latest version from T-Plan’s downloads section. 
  2. Java installation: Ensure Java is installed and set up correctly as T-Plan requires it for test execution. 
  3. Integrate Selenium WebDriver: Link Selenium WebDriver to T-Plan, allowing you to execute Selenium-based scripts directly within T-Plan’s environment. 

For more details on setup, see T-Plan’s Selenium integration documentation. 

Creating a test using T-Plan’s GUI 

T-Plan’s graphical interface makes test creation straightforward, even for non-developers. Here’s how to build a test case: 

  1. Capture UI elements: Use T-Plan’s screen capture feature to select and save UI elements for reuse across scenarios. 
  2. Define test steps: Build test sequences by selecting actions like “click” or “input text” for each element. 
  3. Parameterise input data: Set variable inputs to support data-driven testing. 
  4. Add validation points: Establish checkpoints to verify expected outcomes, such as page titles or content changes. 

This GUI-driven approach is highly accessible, unlike Cucumber-Selenium’s code-centric setup. With T-Plan’s drag-and-drop functionality, teams of all skill levels can build tests quickly and efficiently. Learn more about creating tests with T-Plan’s GUI. 

Running Selenium scripts from T-Plan 

After configuring Selenium scripts within T-Plan, executing them is straightforward and integrates seamlessly with T-Plan’s test management tools: 

Script integration: Import Selenium scripts directly, enabling side-by-side execution with other T-Plan tests. 

  1. Execution options: Choose between individual or bulk test runs to suit your scheduling needs. 
  2. Results monitoring: T-Plan’s result logs provide detailed feedback on each step, allowing you to track outcomes and diagnose issues. 

Using T-Plan’s intuitive interface alongside Selenium’s automation capabilities provides efficient test management and execution without the need for extensive coding. This is especially valuable for cross-browser testing, where multiple browser environments must be handled with precision. 

Real-world use cases 

Testing web applications with dynamic elements 

Cucumber and Selenium can struggle with dynamic elements such as calendars, interactive graphics or elements that change frequently and don’t have stable locators. In these cases, traditional DOM-based testing may fall short, as it relies on static element identifiers. 

T-Plan’s solution: T-Plan’s image-based testing allows it to interact with on-screen visual elements directly, recognising and automating interactions with dynamic elements like date pickers, sliders and multimedia components. This capability is invaluable for applications where visual accuracy is critical, such as e-commerce platforms with complex product displays or interactive dashboards in finance and analytics applications. T-Plan’s approach ensures that these elements can be reliably tested, providing comprehensive coverage that complements Selenium’s strengths in browser automation. 

Collaborative testing with cross-functional teams 

In a modern, cross-functional testing environment, involving both developers and non-developers in the testing process can lead to more thorough and efficient quality assurance. However, Cucumber and Selenium require a code-heavy setup, limiting the ability for non-technical team members to contribute directly to the testing process. 

T-Plan’s solution: With T-Plan’s intuitive GUI, non-developers can participate actively in test creation and execution. QA leads, business analysts and other non-technical team members can easily set up, manage and execute tests through a drag-and-drop interface. This accessibility bridges the gap between technical and non-technical stakeholders, enabling true collaboration without coding barriers. T-Plan empowers organisations to build comprehensive test cases collaboratively, enhancing the testing process and overall product quality. 

Conclusion 

While Cucumber and Selenium provide a solid foundation for code-driven test automation, their usability is limited for non-developers. T-Plan fills this gap by offering an intuitive, GUI-driven interface, image-based testing and comprehensive support, making it an ideal choice for teams of varied technical abilities. 

If you’re looking for a user-friendly, powerful automation tool that integrates seamlessly with Selenium and offers more flexibility than Cucumber alone, T-Plan is the answer. Contact T-Plan to explore how it can take your testing to the next level by providing you with valuable information and insights throughout the testing lifecycle. 

Recent Posts

Expanding Horizons: T-Plan Partners with Channel Bridge to Launch in Japan 

At T-Plan, we’re thrilled to announce our latest milestone—our entry into the Japanese market through a strategic partnership with Channel Bridge, Inc. This collaboration represents a significant step in our global journey, bringing our trusted T-Plan test automation solution to one of the world’s most innovative and technology-driven regions.  Empowering Japanese Businesses with Smarter Testing

Read More »
Automotive testing

Rethinking Testing for Software-Defined Vehicles in India: A Cost-Effective Path to Innovation 

India’s automotive industry is on a rapid growth trajectory, cementing its position as the world’s fourth-largest by production and valuation and the third-largest automobile market by sales in 2024*. As the industry evolves, the rise of Software-Defined Vehicles (SDVs) is redefining the development landscape, requiring innovative approaches to both software and testing processes.  The global

Read More »
software testing

Top 10 Types of Software Testing 

Imagine launching your product with zero bugs and no customer complaints – sounds like a dream, right? The secret to making this a reality lies in a well-executed testing strategy. Software testing is a method used to ensure that the actual software product matches user expectations and meets all requirements. Simply put, it’s a quality

Read More »

Book your FREE demo

Get in touch with our award-winning team today and unlock the power of our Automated Visual UI testing tool for your business.

Book your FREE demo

You’re just one step away from saving time & money – get in touch today.

  • No code access required
  • Visual UI testing tool
  • iOS and Mac compatible
  • All platforms supported
  • Mimics real time user experience
  • Record and playback function
  • Award winning support