top of page
hand-businesswoman-touching-hand-artificial-intelligence-meaning-technology-connection-go-

Selenium Integration with Cucumber BDD

July 23, 2023, by Neetu Khatri


Selenium Integration with Cucumber BDD Tool1)


1)What is Cucumber? 2) What is Selenium?3) Why Integrating Selenium and Cucumber? (Use of Selenium with Cumber Integration, and Users of this Test Environment.) 4) Selenium Integration with Cucumber- Environment Setup (Download & Install Java, Add Selenium WebDriver, TestNG, and Cucumber software dependencies using Maven.) 5) Selenium Integration with Cucumber- Write First Test Case & Execute (Create a ‘Selenium with Cucumber” Project, Create a Cucumber Feature file, Create Selenium Test Script for the Cucumber feature file, Create Test Runner using TestNG, and execute Cucumber Test & View test Results.) 6) Data Driven Testing using “Selenium with Cucumber Integration (Create Cucumber Feature File and Test Data, Create Selenium Test script for the Cucumber Feature File Data Driven test Scenario, and Execute the Cucumber Data Driven Test.) Selenium with Java and TestNG Tutorials


Introduction to Cucumber


  • Cucumber is an open-source tool to support Behavior Driven Development with plain text specifications, It is not an Automated Test Tool and It can Test the Functional behavior of web applications by integrating Selenium etc, Tools.

  • Behavior Driven Development (BDD) framework is an extended version of TDD (Test Driven Development) that supports the behavioral part of software code.

  • Cucumber was written in Ruby. Cucumber supports other languages like Java, Net, Javascript, and other platforms.

  • Cucumber reads executable specifications written in plain text and validates that the software does what those specifications say.

  • In order for Cucumbers to understand the scenarios, they must follow some basic syntax rules, called Gherkin. Gherkin is a simple set of grammar rules that makes plain text structured enough for Cucumber to understand.

  • Cucumber is used to write acceptance tests for web applications, It allows automation of functional validation in an easily readable and understandable format (like plain English) to Business Analysts, Developers, Testers, etc.

  • In BDD, users (business analysts, product owners) first write scenarios or acceptance tests that describe the behavior of the system from the customer’s perspective, for review and sign-off by the product owners before developers write their codes.

Advantages of Cucumber


  • It is helpful to involve business stakeholders who can’t easily read code

  • Cucumber Testing focuses on end-user experience

Why Integrating Selenium and Cucumber? Cucumber and Selenium are two popular technologies. Most organizations use Selenium for the functional testing of web applications. these organizations want to integrate Cucumber with Selenium to easy to read and understand the application flow. The cucumber tool acts as the bridge among Business analysts, Software Testers and Software Developers. Cucumber also benefits the client to understand the application code as it uses Gherkin language which is in Plain Text. Prerequisites for Behavior Driven Test Development,BDD Test Tool — to define application behavior in plain meaningful English text using a simple grammar defined by a domain-specific language (DSL)– e.g. Cucumber (DSL: Gherkin), JBehave (DSL: Gherkin), Behat (DSL: Gherkin), Mocha (DSL: user-defined) Test Runner — to automate and run the behavior tests– e.g. TestNG (Java), JUnit (Java) ETC, Optional IDE plugins — Ex: Cucumber plugin for Eclipse IDEs to enable BDD coding support. Test Tool – Ex Selenium to write Test Steps for BDD tools like Cucumber Test Specification Required jar files for Selenium, Java, JUnit/TestNG with Cucumber cucumber-core cucumber-java cucumber-junit cucumber-jvm-dep cucumber-HTML gherkin testing cucumber-testng cucumber-pico container extent reports cucumber-extent report selenium-server web driver manager, Note: If we use Selenium, or Java with Cucumber then you can use either JUnit ot TestNG as Test Runner. Selenium Integration with Cucumber- Test Environment Setup Eclipse IDE, Maven, Selenium WebDriver, Java, JUnit or TestNG, Cucumber and ExtentsReport etc, software. Steps:


  • Download & Install Java (JDK) Software

  • Set Java Environment Variable path

  • Download & Extract Eclipse IDE for Java Developers,

  • Install the “TestNG” plugin for Eclipse IDE

  • If you want to use JUnit as Test Runner you can use, Junit is a built-in plugin in Eclipse IDE,

  • Create Maven Project

  • Add the below Maven Software dependencies in Maven POM XML file cucumber-core, cucumber-java, cucumber-junit, cucumber-jvm-deps, cucumber-html, gherkin, testng, cucumber-testng, cucumber-pico container, extent reports, cucumber-extent report, selenium-server, web driver manager,

  • Restart Eclipse IDE Note: Now Selenium with Cucumber Test Environment is ready.

Selenium Integration with Cucumber- Write First Test Case & Execute Data Driven Testing using “Selenium with Cucumber Integration






Why do I need Selenium Automation Testing?

Imagine that a manual tester has this scenario: Checking whether the web app’s signup page (www.example.com/signup) validates input strings and registers a user successfully in latest versions of Chrome and Firefox, on Windows 7. Assume that the signup page has these input fields—username, email address, and password. The tester will get a Windows 7 desktop and follow these steps, consecutively, on latest versions of Chrome and Firefox:

  1. Enter the URL in the address bar (www.example.com/signup)

  2. Enter an invalid string in each input field (email, username, and password)

  3. Check whether the input strings were validated against corresponding regexes and any pre-existing values in the database

  4. Enter ‘valid’ strings in each input field; click Sign Up

  5. Check whether “Welcome, ‘{‘username’}’“ page showed up

  6. Check whether the system database created a new userID for ‘{‘username’}’

  7. Mark the test ‘passed’ if it did, ‘failed’ if the signup feature broke anywhere during the test.

That’s a very basic system test. In the real world, testers are more likely to be checking all user workflows on www.example.com for breakage, on as many OS-browser combinations as needed to meet the benchmarked compatibility standards. Depending on the number of manual testers (and thoroughness of test cases), it may take anywhere between hours to weeks to be sure that the web app is fully functional. Modern developers and product teams don’t have that kind of time to allot for testing, but they can’t set aside exhaustive testing in a hurry to release either. This is why they super-charge their testing with automation, powered by Selenium. Run a Selenium Test How Selenium Testing Boosts Agile Development What is Agile? Agile is a development methodology. It starts with the simplest working version of the product design—one that can be continuously improved. Here’s what a typical Agile workflow looks like:

  • Stakeholders agree upon the ‘simplest working’ design of the product.

  • The design gets divided into smaller modules.

  • Each module is assigned to a cross-functional team of developers, designers, and Quality Assurance personnel.

  • Teams work in sprints to create their modules within a time-frame (‘iteration’)—a window of one to four weeks.

  • At the end of each iteration, finished modules are put together. Tests are run and a functional product (with minimum bugs) is demonstrated to the stakeholders.

  • The stakeholders evaluate project priorities, add customer feedback, and adapt as needed.

The whole cycle begins again with the next iteration and a new set of modules. A ‘market-ready’ product or a new feature will always need multiple iterations. Where does testing automation come in:

  • QAs are involved from early stages to run a series of unit and acceptance tests on modules.

  • Integration tests on every iteration ensure that separately coded modules don’t break when put together.

  • Each new iteration requires regression tests (so it doesn’t break the previous working iteration).

It’s essential to keep track of code as well as test cases, so all iterations are well documented. While we’re on the subject, you should note that this recurrent testing is a theme in any sub-category of rapid, iterative development based on Agile, like CI/CD.How Selenium Testing is Integral to Continuous Integration/Delivery (CI/CD) What is CI/CD? Continuous Integration/Delivery prioritizes delivery of new releases of a build, frequently and quickly. A project that’s launched remains open to continuous iterations (like Agile). The only difference is this: the project also remains ready to be shipped at all times (instead of waiting for iterations to run their course). A CI/CD pipeline looks like this:

  • A developer has code they wants to integrate into the project

  • An external CI server does an ‘integration’ test—it grabs the source files and attempts to do a build with the new code.

  • If the build completes successfully, the server packages the changes with source files. If not, the server notifies members of the team.

CI engines (like Jenkins or Bamboo) have dashboards that display current and previous builds, logs of previous check-ins and their status (successful/failed), what broke (and when), etc. Everyone remains informed about any change in code, infrastructure, or configuration. This ensures that deployment failures are caught (and fixed) early. Note: There’s a difference between a ‘successful build’ and ‘quality build’. Even if a new integration is successful, it’s not considered ready to ship until it has passed a series of tests by QA engineers. That’s where automation testing with Selenium comes in handy. Selenium automates frequent and recurrent functional, performance, and compatibility testing. This gives developers near-instant feedback for faster debugging, leaving them with more time to code business logic for newer versions/features. Modern web development needs Selenium testing because:

  • It automates repeated testing of smaller components of a large(r) code-base

  • It’s integral to agile development and CI/CD

  • It frees resources from manual testing

  • It’s consistently reliable; catches bugs that human testers might miss

  • It can provide extensive test coverage

  • It’s precise; the customizable error reporting is an added plus

  • It’s reusable; you can refactor and reuse an end-to-end test script every time a new feature gets deployed.

  • It’s scalable; over time, you can develop an extensive library of repeatable test cases for a product


What Types of Testing can be Automated with Selenium?

Types of testing that are commonly automated with Selenium are: Compatibility Testing: Done by QA professionals/Testers to ensure that the web app meets performance benchmarks on different browser-OS combinations. For example, testing on different devices (mobile and desktop) to ensure that the front-end fits to scale (responsive); testing on different browsers to see if video ads render on the pages as they should. Performance Testing: Series of tests done by QA professionals/Testers to ensure that the project meets performance benchmarks set by the stakeholders. Tester writes a script that checks whether all elements on homepage load within 2 seconds on different browsers/browser versions. Integration Testing: Done by developers to verify that units/modules coded separately (that work on their own), also work when put together. Parallel Test Calculator, for instance, has separate layers. UI takes input and business logic calculates the output—then sends it back to UI to display. The tester could verify whether they are able to relay data/output when integrated. System Testing: aka Black Box testing. Done by Testers/QA professionals with no context of the code or any previously executed tests. Typically centered on a single user workflow. The check-out process on a product website, for instance, comprises of: validating user credentials, fetching products from the cart, checking their availability, and validating payment details—before redirecting to the bank website. The tester could write a script to verify that the entire system is functional. End-to-end Testing: Also done by Testers/QA professionals, typically from the user’s point of view. The aim is to verify that all touchpoints on the web app are functional. From the previous example, the tester could write a series of test cases to check that sign-up, product search, checkout, review, bookmark, and all other features function as intended (and fail when invalid values are entered in input fields). Regression Testing: A series of tests done to ensure that newly built features work with the existing system. From the same example, say the product website launches a new feature (promotional codes) that automatically apply to eligible items before checkout. The tester could write cases to verify that it doesn’t break the rest of the checkout feature. Well-written test suites can also automate Smoke and Sanity testing with Selenium.





Conclusion Selenium is a cost-effective and flexible tool developers can use in the automation testing of their web applications.

133 views0 comments

Recent Posts

See All
bottom of page