Search code examples
testingbdde2e-testinggherkintestcafe

Is the TestCafe team planning to support Gherkin (BDD) officially? If not what is the best way of integrating TestCafe with Gherkins at the moment?


My team kinda like TestCafe, but there are some reservations against adopting it. The main one being support for Gherkin integration. The gherkin-testcafe npm package and the sample https://github.com/helen-dikareva/testcafe-cucumber-demo seem not ready for primetime yet.

Is it a more reliable way of supporting BDD at the moment?


Solution

  • After a conversation with colleagues here at the office, we concluded that the best way to

    • keep our BDD process,
    • use TestCafe and
    • write tests in Typescript without adding dependencies on javascript packages that are not the most realiable

    was to just use some conventions while writing the TestCafe tests. For example, let's say you are given the following Gherkin file:

    Feature: Application
    As an administrator
    I want to be able to view and manage Applications in my account
    
    Scenario: Verify creating and deleting an application
        Given I am in the login page
        When I login to console with allowed user
        And I go to Applications page
        And I add an application
        Then the application is added in the application page
    

    Then the feature.ts file would look something like the following:

    import {Selector} from 'testcafe';
    import {LoginPageModel} from '../pagemodels/login.pagemodel';
    import {ApplicationPageModel} from '../pagemodels/application.pagemodel';
    
    let applicationPageModel: ApplicationPageModel = new ApplicationPageModel();
    let loginPageModel: LoginPageModel = new LoginPageModel();
    
    fixture(`Feature: Application
       As a administrator
       I want to be able to view and manage Applications in my account
     `);
    
    let scenarioImplementation = async t => {
      let stepSuccess: boolean;
    
      stepSuccess = await loginPageModel.goToPage(t);
      await t.expect(stepSuccess).eql(true, 'Given I am in the login page');
    
      stepSuccess = await loginPageModel.login(t);
      await t.expect(stepSuccess).eql(true, 'When I login to console with 
      allowed user');
    
      stepSuccess = await applicationPageModel.selectPage(t);
      await t.expect(stepSuccess).eql(true, 'And I go to Applications page');
    
      stepSuccess = await applicationPageModel.addApplication(t);
      await t.expect(stepSuccess).eql(true, 'And I add an application');
    
      stepSuccess = await applicationPageModel.verifyAddedApplication(t);
      await t.expect(stepSuccess).eql(true, 'Then the application is added in 
      the application page');
    
     };
    
    test(`Scenario: Verify creating and deleting an application
       Given I am in the login page
       When I login to console with allowed user
       And I go to Applications page
       And I add an application
       Then the application is added in the application page`, 
                                                scenarioImplementation);