cucumber / cucumber-js

Cucumber for JavaScript
https://cucumber.io
MIT License
5.02k stars 1.09k forks source link

New custom type is not registered #2332

Closed jkalandarov closed 10 months ago

jkalandarov commented 10 months ago

πŸ‘“ What did you see?

? And I click on "Create campaign button" on "Dashboard page"  
       Undefined. Implement with the following snippet:

         Given('I click on {string} on {string}', async function (string, string2) {
           // Write code here that turns the phrase above into concrete actions
           return 'pending';
         });

βœ… What did you expect to see?

I expected the step to be executed

πŸ“¦ Which tool/library version are you using?

"@cucumber/cucumber": "^9.5.1",
"@playwright/test": "^1.38.0",
"@types/node": "^20.8.0",
"multiple-cucumber-html-reporter": "^3.5.0",
"ts-node": "^10.9.1"

πŸ”¬ How could we reproduce it?

campaignCreate.feature:

Feature: Campaign creation

  Scenario: [TC] Advertiser should be able to create campaign
    Given I am authenticated as "Advertiser"
    Then I am on "Dashboard page"
    And I click on "Create campaign button" on "Dashboard page"

commonActions.ts:

When('I click on {toCamelCase} on {string}', function (element: string, page: string) {
  //some code
});

defineParameterTypes.ts:

import { defineParameterType } from "@cucumber/cucumber";

defineParameterType({
  name: 'toCamelCase',
  regexp: /^[^"]*\sbutton|checkbox|radiobutton$/,
  transformer: function(match) {
    return match.toLowerCase()
      .replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
        return index === 0 ? word.toLowerCase() : word.toUpperCase();
      })
      .replace(/\s+/g, '');
  },
  preferForRegexpMatch: true,
  useForSnippets: false
});

Screenshots: image

πŸ“š Any additional context?


This text was originally generated from a template, then edited by hand. You can modify the template here.

davidjgoss commented 10 months ago

Closing as you got the right pointers on the Slack thread https://cucumberbdd.slack.com/archives/C60TKS3SL/p1696091351991659