Question

I am trying to run the following scenario using Freshen:

  Scenario Outline: Retrieve a user using some identifier
    Given I have the account number <account_number>
    And I get the user from their <identifier> which is <identifier_value>
    Then the users <field_name> should be <field_value>

  Examples:
   | account_number | identifier | identifier_value        | field_name | field_value     | 
   | 57             | id         | 622                     | Username   | testuser01      |
   | 57             | username   | testuser01              | Email      | argy@bargy.com  |

With the following steps:

@Given("I have the account number (\d+)")
def set_account_num(account_number):
    scc.account_number = int(account_number)

@Given("I get the user from their (\w+) which is (\w+)")
def get_user_from_id(identifier, identifier_value):

    scc.user = user_operations.get_user(scc.account_number, str(identifier_value), str(identifier), scc.headers)

@Then("the users (\w+) should be (\w+)")
def check_result(field_name, field_value):
    assert_equal(str(field_value), str(scc.user[str(field_name)]))

I get the following failure:

======================================================================
FAIL: user: Retrieve a user using some identifier
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\Front_End\features\
teps.py", line 83, in check_result
    assert_equal(str(field_value), str(scc.user[str(field_name)]))
AssertionError: 'argy' != 'argy@bargy.com'

----------------------------------------------------------------------

The problem appears to be that the string in field_value is being read in as "argy" instead of "argy@bargy.com". Does anybody know how to include or escape the @ symbol?

Thanks!

Was it helpful?

Solution

The strings which are used to annotate your steps (e.g. "the users (\w+) should be (\w+)") are regular expressions. They're used to match up step definitions against the text found in the Gherkin file and parse arguments out of the text.

In this case the (\w+) is looking for one or more "word" characters, which doesn't include @. Actually the @ isn't your only problem, \w won't match the dot in .com either.

You've got two options, either change the (\w+) to a regex which will match email or just put quotes around the parameters and use (.*) to match anything inside those quotes.

Matching an email address with regex is harder than you'd think (see http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html), so just use the quotes:

Then the users "<field_name>" should be "<field_value>"

@Then('the users "(.*)" should be "(.*)"')

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top