Testing / Cucumber Interview Questions
What is the World object in Cucumber?
In Cucumber's Ruby and JavaScript implementations, the "World" is a fresh object created for each scenario that step definitions execute within, serving the same role Java's dependency-injected shared context objects serve: a place to store and share state across steps within one scenario, without leaking between scenarios.
// Cucumber.js example const { setWorldConstructor } = require('@cucumber/cucumber'); class CustomWorld { constructor() { this.loginResult = null; } } setWorldConstructor(CustomWorld);
Given('a registered user {string}', async function (username) { this.loginResult = await loginService.register(username); });
Because a brand-new World instance backs every scenario, state naturally resets between scenarios without any manual cleanup code, which is exactly the isolation guarantee Java's per-scenario step definition instantiation (combined with dependency injection) is achieving through a different mechanism in that ecosystem.
More Related questions...