Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Parameter Type in DataTables #669

Closed
NielsFeldtmannKALO opened this issue Feb 2, 2022 · 10 comments
Closed

Custom Parameter Type in DataTables #669

NielsFeldtmannKALO opened this issue Feb 2, 2022 · 10 comments

Comments

@NielsFeldtmannKALO
Copy link

NielsFeldtmannKALO commented Feb 2, 2022

Current behavior

Given a feature A with a DataTable including a custom parameter
When I run the szenario 
then the parameter is not replaced

Desired behavior

When i use custom parameter types like in https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/blob/master/cypress/support/step_definitions/customParameterTypes.js
I want them to be replaced in Data Tables

Test code to reproduce


Szenario A: DataTable
    When I enter date {today}     
    Then I verify the datatable result contains
      | column | value      |
      | 1           | {today}   |

custom parameter in cucumber runner

defineParameterType({
  name: "today",
  regexp: /today/,
  transformer(s) {
    return 10; // more realistic would be today
  },
});

When("  When I enter date {today}", (number) => {
  // Here the {today} => 10
  cy.get('input').type(number);
});

Then("I verify the datatable result contains", (dataTable) => {
  // Here the dataTable should also contain 
 // | column | value      |
 // | 1           | 10   |
  assert(dataTable.hashes()[0]["1"]).is.eq('10')
});

Versions

  • Cypress version: 9.1.1
  • Preprocessor version:4.3.1
  • Node version:14.15.5
@GaxZE
Copy link

GaxZE commented Mar 4, 2022

This would be a really good feature.

@amitguptagwl
Copy link

@NielsFeldtmannKALO are you looking for a feature or reporting a bug? You can parameterize steps using Examples. Custom parameters are used to give some meaningful name to the regex. See this documentation for an example.

@NielsFeldtmannKALO
Copy link
Author

@amitguptagwl this would be a new feature.

I am aware that we can parametrize "simple" steps.

This feature would allow to use the parameters in datatables also.

@amitguptagwl
Copy link

Hmm.. ok. But the purpose of data tables is to provide the data. how would you define the type there. I believe, I'm missing something here.

@NielsFeldtmannKALO
Copy link
Author

Hmm.. ok. But the purpose of data tables is to provide the data. how would you define the type there. I believe, I'm missing something here.

The dataTable would provide the data to check in the test.

Assume you want to check the content of a html table after editing one of the entries in on row, by putting a variable content.
So we put a variable value inside one of the cells, like {currentDate}.

After that we want to check all the displayed rows in the table. Therefore we provide the data in the test as "dataTable".
One of the rows contains now the variable cell value, so the dataTable would also need a parameter.
The "type" would be one of the customParameters you defined for normal steps. (like {mob} in your examples)

@badeball
Copy link
Owner

Due to personal reasons, the previous maintainers of this package are stepping down and handing the reigns over to me, a long-time contributor to the project and a user of it myself. This is a responsibility I'm very excited about. Furthermore, I'd like to thank @lgandecki ++ for all the work that they've done so far.

Read more about the transfer of ownership here.

The repository has however moved and all outstanding issues are being closed. This is not a reflection of the perceived importance of your reported issue. However, if after upgrading to the new version, you still find there to be an issue, feel free to open up another ticket or comment below. Please make sure to read CONTRIBUTING.md before doing so.

@novicovs
Copy link

Any chance we can "revive" this issue?
It looks like a nice feature.

@badeball
Copy link
Owner

No, this is completely nonsensical and not at all what parameters are.

@badeball
Copy link
Owner

Stop thinking that steps themselves have to vary. Instead, the interpretation of them can vary. Here's some pseudo code to get you going.

Feature:
  Scenario:
    When I enter date "today" in "Birthday"
defineParameterType({
  name: "date",
  regexp: /"([^\"])"/,
  transformer(s: string) {
    if (DATE_EXPR.test(s)) {
      return Temporal.PlainDate.from(s);
    } else if (s === "today") {
      return Temporal.Now.plainDateISO();
    } else {
      throw new Error("Unable to parse expression: " + s);
    }
  },
});

When("I enter date {date} in {string}", (date: Temporal.PlainDate, label: string) => {
  // ...
});

@NielsFeldtmannKALO
Copy link
Author

Still the ckeck of variable content with data tables is not possible.

Feature:
  Scenario:
    When I enter date "today" in "Birthday"
Then the list of birtday is
| date      |
| today     |
| yesterday |

With current implementation you qould have to check like

When I enter date "today" in "Birthday"
Then the list of birtday has value "today"
And the list of birtday has value "yesterday"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants