I am facing a problem where python behave is parsing a step definition weird when one of my parameter I am passing is a part of the step sentence itself.
Here is the step definition
@when(u'I set the value of {setting} to {value} in configuration')
def **step_imp**(context, setting, value):
print ("Setting:", setting , " Value:", value)
pass
My feature sample look like
Scenario: Configuration Update
Given I can access the configuration file
When I set the value of **CDROM Drive** to **G:** in configuration
When I set the value of **USB TO IGNORE** to **USB2.0** in configuration
It works for the first when statement. But for 2nd When statement, the behave parser parses and gives the parameter {setting} as USB and {value} as USB2.0. Since "to" is a word which is part of the step itself, when parsing USB TO IGNORE the behave parser ignores words from "TO".
Any possible solutions without omitting the spaces in the parameters? Thanks
Yeah just use double-quotes instead of asterisks around the parameters in your feature file and also (And this is what makes the difference in getting 'to' to appear) put double quotes around the curly brackets in the step file, e.g. @when(u'I set the value of "{setting}" to "{value}" in configuration')
. I also don't think you need the asterisks around **step_imp**
. But I'm being specific for python behave.
If anyone ends up here for the same reason I did, how do you escape double quotes in a parameter. It seems you just use a forward slash, \
, before the double quote. It was the first thing I tried but there was something else causing my test to get a parse error and I couldn't find anyone explicitly saying it was a forward slash to escape anywhere so want to document it somewhere just in case others end up on a goose chase.
Scenario: If we enter an xss attack it should not work on another page
Given I am on "/example-page"
When I set current element to search field
and I send the attack "\">alert(1)"
Then I am on "/?s=%5C\"><%2Flabel><h1+id%3DXSS>Hello<%2Fh1><label><input+#search-form"
and there should not be an element with this locator "h1#XSS"