Convert Figma logo to code with AI

cucumber logocommon

A home for issues that are common to multiple cucumber repositories

3,363
696
3,363
37

Top Related Projects

Cucumber for Ruby. It's amazing!

Cucumber for JavaScript

3,138

BDD, Python style.

BDD library for the py.test runner

8,079

Test Automation Made Simple

Quick Overview

Cucumber Common is a repository containing shared code and resources used across various Cucumber projects. It provides common utilities, data structures, and functionalities that are essential for Cucumber's behavior-driven development (BDD) tools and implementations in different programming languages.

Pros

  • Centralizes shared code, reducing duplication across Cucumber projects
  • Improves consistency and maintainability of Cucumber implementations
  • Facilitates easier updates and bug fixes across multiple Cucumber tools

Cons

  • May introduce dependencies between different Cucumber projects
  • Changes to common code could potentially affect multiple projects simultaneously
  • Requires careful coordination when making updates to ensure compatibility

Code Examples

  1. Using the Messages module to create a Pickle:
require 'cucumber/messages'

pickle = Cucumber::Messages::Pickle.new(
  id: "123",
  uri: "features/example.feature",
  name: "Example Scenario",
  language: "en",
  steps: [
    Cucumber::Messages::PickleStep.new(
      text: "Given I have a cucumber",
      id: "step-1"
    )
  ]
)
  1. Creating a TestCase using the TestCase module:
require 'cucumber/messages'

test_case = Cucumber::Messages::TestCase.new(
  id: "test-1",
  pickle_id: "pickle-1",
  test_steps: [
    Cucumber::Messages::TestStep.new(
      id: "step-1",
      pickle_step_id: "pickle-step-1"
    )
  ]
)
  1. Generating a unique ID using the IdGenerator:
require 'cucumber/messages'

id_generator = Cucumber::Messages::IdGenerator.new
unique_id = id_generator.new_id

Getting Started

To use Cucumber Common in your project, add it as a dependency in your Gemfile:

gem 'cucumber-messages'

Then, install the gem:

bundle install

Now you can require and use the common modules in your Ruby code:

require 'cucumber/messages'

# Use Cucumber Common modules and classes here

Competitor Comparisons

Cucumber for Ruby. It's amazing!

Pros of cucumber-ruby

  • Specifically tailored for Ruby development, offering seamless integration with Ruby projects
  • Provides Ruby-specific step definitions and hooks, making it easier for Ruby developers to write and maintain tests
  • Includes built-in support for popular Ruby testing frameworks like RSpec and Test::Unit

Cons of cucumber-ruby

  • Limited to Ruby ecosystem, lacking the cross-language support offered by common
  • May have a steeper learning curve for developers not familiar with Ruby-specific syntax and conventions
  • Potentially slower development and update cycle compared to the more generalized common repository

Code Comparison

cucumber-ruby:

Given(/^I have (\d+) cucumbers in my belly$/) do |count|
  @cucumbers = count.to_i
end

When(/^I wait (\d+) hour$/) do |time|
  @time = time.to_i
end

common:

Feature: Eating cucumbers

  Scenario: Eat cucumbers
    Given I have 42 cucumbers in my belly
    When I wait 1 hour
    Then I should have 40 cucumbers in my belly

Note: The code comparison shows a Ruby-specific step definition in cucumber-ruby versus a language-agnostic Gherkin feature file in common.

Cucumber for JavaScript

Pros of cucumber-js

  • Specifically designed for JavaScript environments, offering seamless integration with Node.js and browser-based projects
  • Provides a more extensive set of features tailored to JavaScript developers, including async/await support and TypeScript definitions
  • Actively maintained with frequent updates and a large community of contributors

Cons of cucumber-js

  • Limited to JavaScript ecosystems, lacking the cross-language support offered by common
  • May have a steeper learning curve for developers not familiar with JavaScript-specific testing paradigms
  • Potentially more complex setup and configuration compared to the language-agnostic common repository

Code Comparison

cucumber-js:

const { Given, When, Then } = require('@cucumber/cucumber');

Given('I have {int} cucumbers', function (count) {
  this.cucumberCount = count;
});

common:

Given(/^I have (\d+) cucumbers$/) do |count|
  @cucumber_count = count.to_i
end

The code comparison shows how step definitions are written in cucumber-js (JavaScript) versus common (Ruby). While the syntax differs, both achieve similar functionality in their respective languages.

3,138

BDD, Python style.

Pros of behave

  • Python-native implementation, allowing for seamless integration with Python projects
  • Simpler setup and configuration process
  • Built-in support for various output formats (e.g., JUnit XML, JSON)

Cons of behave

  • Limited cross-language support compared to Cucumber's ecosystem
  • Smaller community and fewer available resources
  • Less frequent updates and maintenance

Code Comparison

behave:

from behave import given, when, then

@given('we have behave installed')
def step_impl(context):
    pass

@when('we implement a test')
def step_impl(context):
    assert True is not False

common:

Given("we have cucumber installed") do
  # Implementation
end

When("we implement a test") do
  expect(true).to_not eq(false)
end

Both frameworks use a similar syntax for defining step definitions, but behave uses Python decorators while common (Cucumber) typically uses Ruby-style method definitions. behave's implementation is more Pythonic, while common's approach is more flexible across different programming languages.

The choice between behave and common often depends on the primary programming language of the project and the need for cross-language support. behave is ideal for Python-centric projects, while common (Cucumber) offers broader language compatibility and a larger ecosystem.

BDD library for the py.test runner

Pros of pytest-bdd

  • Integrates seamlessly with pytest, leveraging its powerful features and ecosystem
  • Supports both imperative and declarative styles of BDD
  • Allows for more flexibility in test structure and organization

Cons of pytest-bdd

  • Less widespread adoption compared to Cucumber
  • May have a steeper learning curve for those unfamiliar with pytest
  • Limited support for non-Python languages

Code Comparison

pytest-bdd:

@scenario('features/login.feature', 'Successful login')
def test_successful_login():
    pass

@given('I am on the login page')
def login_page(browser):
    browser.get('/login')

@when('I enter valid credentials')
def enter_credentials(browser):
    browser.find_element_by_id('username').send_keys('user')
    browser.find_element_by_id('password').send_keys('pass')

common (Cucumber):

Given('I am on the login page') do
  visit '/login'
end

When('I enter valid credentials') do
  fill_in 'Username', with: 'user'
  fill_in 'Password', with: 'pass'
end

Both frameworks support BDD-style testing, but pytest-bdd integrates more closely with Python's ecosystem, while common (Cucumber) offers broader language support and a more standardized approach across different programming languages.

8,079

Test Automation Made Simple

Pros of Karate

  • All-in-one testing framework with built-in API, UI, and performance testing capabilities
  • Simpler syntax and less boilerplate code compared to Cucumber
  • Powerful assertion and validation features for API responses

Cons of Karate

  • Steeper learning curve for those familiar with Cucumber-style Gherkin syntax
  • Less extensive ecosystem and community support compared to Cucumber
  • Limited support for behavior-driven development (BDD) practices

Code Comparison

Karate:

Feature: Sample API Test

Scenario: Get user details
  Given url 'https://api.example.com/users'
  And path '1'
  When method get
  Then status 200
  And match response.name == 'John Doe'

Cucumber:

Feature: Sample API Test

Scenario: Get user details
  Given I send a GET request to "/users/1"
  Then the response status should be 200
  And the response should contain "John Doe"

Summary

Karate offers a more integrated and streamlined approach to API testing with powerful built-in features, while Cucumber provides a more flexible and extensible framework for BDD-style testing across various domains. The choice between the two depends on specific project requirements and team preferences.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

#StandWithUkraine

Cucumber Common Components

Cucumber is made up of several libraries, many of which are kept in polyglot repositories, meaning we keep multiple language implementations of the same library together in the same repo.

LibraryDescriptionLatest release
cucumber-expressionsPattern-matching for Gherkin stepsLatest release
tag-expressionsFor parsing tag selection queriesLatest release
gherkinParser for Gherkin feature filesLatest release
messagesJSON message protocolLatest release
queryQuery API for messagesLatest release
gherkin-utilsAPI for querying parsed Gherkin documentsLatest release

If you're not sure which repository your issue belongs under, or it cuts across multiple repos, raise it in this repo.