Open viktor-silakov opened 1 month ago
Could you provide an example?
@vitalets Yes sure, for example, I have step:
When I fill out the form:
"""
name: [random username]
email: [random email]
"""
And make some callback 'fillPlaceholders' which should render this template and give me the output:
name: John
email: john@example.com
Under the hood...
For usual string parameters, I can use defineParameterType
transformation but for docstrings - can't
At what moment fillPlaceholders
should be called? During spec files generation or in runtime?
If in runtime - looks like it's custom content type for doc strings, I see it in cucumber-jvm (and don't see in cucumber-js).
I think API can be the following:
defineDocStringType({
name: 'placeholders', // if empty -> applied to all docStrings
transformer: (s) => fillPlaceholders(s, { name: 'John', email: 'john@example.com' });
});
And in feature file:
When I fill out the form:
"""placeholders
name: [random username]
email: [random email]
"""
Yes, it would be good to have this API on runtime.
Ok. Lets track in this issue. For now the only workaround I see is to make transformation inside step:
When("I fill out the form:", async ({ page }, docStringTpl: string) => {
const docString = fillPlaceholders(docStringTpl, { name: 'John', email: 'john@example.com' });
// ...
});
Is it possible to use a similar to the
defineParameterType
transformation for all docstrings?Or maybe you can suggest some workaround? I want to add some templating system across all docstrings.