When('I enter valid credentials', async function() {
await enterCredentials('
[email protected]', 'password123');
});
Then('I should see the dashboard page', async function() {
const dashboardVisible = await seeDashboard();
expect(dashboardVisible).to.be.true;
});
In this example:
Gherkin defqnes the behavior in a human-readable format.
JavaScript provides the actual test steps in loginSteps.js,
where the step defqnitions map to functions that interact with
the application.
Chai assertions are used to verify that the test behaves as
expected.
Why Use Cucumber with JavaScript?
Seamless Integration with Web and Mobile Testing
Frameworks: JavaScript is the language of choice for web
applications testing with Selenium, WebDriverIO, or Cypress. For
mobile applications testing, Appium supports the language as
well. So, the combination of Cucumber with JavaScript lets
teams leverage the strength of BDD and the flexibility of the
chosen testing frameworks to easily write, maintain, and execute
acceptance tests.
By writing tests in Gherkin: you are actually creating readable
and maintainable specifqcations for your system’s behavior. This
will make sure that anyone can understand the business
requirements irrespective of their technical expertise and then
verify that the application really meets them.
Unifqed Testing Approach: Cucumber-JS helps in unifying your
testing approach by allowing frontend JavaScript-based tests