Non-capturing text in action words definitions


#1

Is it possible to use non-capturing text in steps/action word definitions?

For example I would like to be able to say:
Given I have an “something” and Given I have a “something” to be able to use either “an” or “a” and not to become a variable.

Something like: Given I have (?:a|an) “something”

Thanks


#2

Hi @daniel.crisan,

Can you give me more details about your use case please?

Thanks in advance.

Regards,
Houda


#3

Hi,

For example now if I have a step:
Given I have “1” cat
But I also want to say:
Given I have “2” cats
It will create two action words because of the trailing “s” from cats. But I would like to have only one action word.

It’s also discussed here: https://stackoverflow.com/questions/18378229/how-to-use-non-capturing-parenthesis-to-capture-a-word-or-nothing-at-all

Thank you


#4

Hi!

Thank you fir this explanation.

For now that’s not possible to have such possibilities because we can export in many languages and for some of them there is no support of regular expressions.

The closest you can get to this functionality with HipTest is by defining two actionwords, and make the first one call the second one. When exporting to Gherkin-based languages, the actionword will call the other one as you expect, and you just have to implement one method.

Would that fit your needs?

Regards,
Houda


#5

Thank you for the answer. For now I use parameters and it works ok so far.

Regards


#6

Great :grinning:

you’re welcome!