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

Need example on how to pass null values for Example table #463

Closed
f00dog-x300 opened this issue Nov 24, 2021 · 7 comments
Closed

Need example on how to pass null values for Example table #463

f00dog-x300 opened this issue Nov 24, 2021 · 7 comments

Comments

@f00dog-x300
Copy link

Hi,

I'm trying to perform a test by adding different parameters, and one of those parameters are for null values. Unfortunately, I'm not able to do it.

Currently the Example table that I'm using looks like this

 Scenario Outline: Invalid Login
        Given I am an invalid user
        And I enter a bad <username> in the username field
        And I enter a bad <password> in the password field

        When I click on the Log in button

        Then I should get a proper <error> message

        Examples:
            | username      | password     | error                              |
            | standard_user |              | Epic sadface: Password is required |
            |               | secret_sauce | Epic sadface: Username is required |

I receive an error stating the step definition is not found. The methods associated with these steps look like this:

@given(cfparse("I enter my {username} in the username field"), converters=CONVERTERS)
@given(string("I enter a bad {username} in the username field"))
def enter_username(login: Login, username: str) -> None:
    logging.info(f"Logging on as - {username}")
    login.enter_username(username)


@given(cfparse("I enter my {password} in the password field"), converters=CONVERTERS)
@given(string("I enter a bad {password} in the password field"))
def enter_password(login: Login, password: str) -> None:
    logging.info(f"Entering password - {password}")
    login.enter_password(password)


@then(cfparse("I should get a proper {error} message"), converters=CONVERTERS)
def check_error_messages(login: Login, error):
    assert error == login.bad_login_error_message()

I was wondering if I could get some guidance

@elchupanebrej
Copy link

Hi, original module "parse" has no possibility to this just now because of r1chardj0n3s/parse#136
But in your case, you could fallback to use regex parser or write your own parser using https://github.com/jenisys/parse_type as was shown in an example: r1chardj0n3s/parse#13 (comment)

@jenisys
Copy link

jenisys commented Jan 2, 2022

Mmh, isn't the problem already solved by using quoting?

Like:

Scenario Outline: Invalid Login
  Given I am an invalid user
  And I enter a bad "<username>" in the username field
  And I enter a bad "<password>" in the password field
  ...
@given(cfparse('I enter my "{password}" in the password field'), converters=CONVERTERS)
@given(string('I enter a bad "{password}" in the password field'))
def enter_password(login: Login, password: str) -> None:
    logging.info(f"Entering password - '{password}'")
    login.enter_password(password). # HINT: Internal implementation handles EMPTY_STRING password (and raises error)

HINT: I have not actually tried the example above.

@jenisys
Copy link

jenisys commented Jan 2, 2022

HINT:
The motivating Gherkin example above is not exactly "good gherkin".
It is better to describe what you need to do (your intentions) instead of how to do it (exact procedure).
The "How" is implemented in your step implementations.
The exact procedure may change over time, if you change the UI.
This works with one page login (username and password) and two page login (username page, then password page).
With your example you would always need to change the Gherkin description ... (which is brittle).

BETTER:

Scenario Outline: Invalid Login
  Given I am not logged in
  When I login as user "<username>" with password "<password>"
  Then the login fails with "<error>" message
  ...

@elchupanebrej
Copy link

elchupanebrej commented Jan 3, 2022

Let try

@given(cfparse("I enter my {username:word?} in the username field", dict(word=with_pattern(r'\w+')(lambda _:_))), converters=CONVERTERS)
def enter_username(login: Login, username: str) -> None:
    logging.info(f"Logging on as - {username}")
    login.enter_username(username)

@elchupanebrej
Copy link

@f00dog-x300 Pay attention that cfparse doesn't support cardinality field for parse module now jenisys/parse_type#10

@jenisys
Copy link

jenisys commented Jan 3, 2022

Actually, the parse_type.cfparse.Parser supports the cardinality fields (for user-defined types). Only the build-types of the parse module are not supported (because the knowledge of the regular expression pattern, etc. is not easily available. This knowledge is spread over the internal implementation details).

@olegpidsadnyi
Copy link
Contributor

Parsers and converters is the right way to go.

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

4 participants