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

wildcards in step definitions? #72

Closed
mikelietz opened this issue Dec 26, 2018 · 2 comments
Closed

wildcards in step definitions? #72

mikelietz opened this issue Dec 26, 2018 · 2 comments

Comments

@mikelietz
Copy link

I don't think this is a bug as much as lack of coding experience. I'm porting over some very rudimentary lettuce_webdriver features and steps, and I'm struggling for a clean replacement for "I should see..."

One such feature line for this is:

Scenario: Testing Webdriver
  When I open the url "http://my.login.page"
  Then I should see "Forgot Your Password?"

Of the three definitions below, only the first one works. The latter two are not recognized and behave suggests a snippet like the first one.

@then(u'I should see "Forgot Your Password?"')
def step_impl(context):
  assert context.behave_driver.element_contains('body', 'Forgot Your Password?')

@then(u'I should see "([^"]*)?"')
def step_impl(context, value):
  assert context.behave_driver.element_contains('body', value)

@then(u'I should see "([^"]*)?"')
def step_impl(context, value):
  context.execute_steps( u"""
    then I expect that element "body" contains the text "{text}')
  """).format(text = value)
@spyoungtech
Copy link
Owner

By default, the 'parse' matcher is in use.
Defining a generic step for this use should be as simple as the following:

@then(u'I should see "{text}"')
def expect_some_text(context, text):
    assert context.behave_driver.element_contains('body', text)

The problem you're encountering with the latter two steps is that, in order to use regex matching, you'd need to change the step matcher first.

So you could define the same kind of step using the regex matcher this way

from behave import use_step_matcher
use_step_matcher('re')

@then(u'I should see "([^"]*)?"')
def step_impl(context, value):
  assert context.behave_driver.element_contains('body', value)

If you change the matcher, don't forget to change it back as needed, so your other steps don't unexpectedly stop working.

For more info, you can read about this more in the behave documentation

@mikelietz
Copy link
Author

Thank you! I wasn't sure if this was better asked there or here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants