Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I writing a simple BDD script using Cucumber(Behave), python and selenium.
The first two steps of my feature and script work but I having trouble getting a parameter from my Behave feature to my Python script.

I keep getting this error when I runt the behave feature:
You can implement step definitions for undefined steps with these snippets:

@when(u'he enters search term rate')
def step_impl(context):
    raise NotImplementedError(u'STEP: When he enters search term rate')


Cucumber/Behave feature:

Scenario: Valid Payee
       Given the user is on a Page
       When he clicks the search field
       And he enters search term 'rate'


Python script:

from behave import given, when, then
xurl =''

@given('the user is on a Page')
def step_user_is_on_fund_transfer_page(context):
    context.driver.get("#")

@when('he clicks the search field')
def step_he_clicks_search_field(context):
    context.driver.find_element_by_id("cludoquery").click()


@when('he enters search term "{text}"')
def step_he_enters_searchterm(context,text):
    context.driver.find_element_by_id("cludoquery").send_keys(text)


Selenium env:

from selenium import webdriver
def before_all(context):
    context.driver = webdriver.Chrome()

def after_all(context):
    context.driver.quit()


What I have tried:

I've tried using 'rate' and <rate> in my feature file for the parameter and ive tried using {text}, "{text}" in the python script but no success.

Any ideas?
Posted
Updated 12-Oct-22 21:37pm
v2

What I do is


And he enters a search term "<rate>"


And in the .py

Python
@when('he enters a search term "(.*)"')
def step_he_enters_searchterm(context,text):
    context.driver.find_element_by_id("cludoquery").send_keys(text)



This uses regex to find the variable, and it assigns that variable to text.


Make sure that you place this at the top of your .py so that you can use the regex.

Python
use_step_matcher('re')
 
Share this answer
 
For this:
@when('he enters search term "{text}"')
def step_he_enters_searchterm(context,text):
context.driver.find_element_by_id("cludoquery").send_keys(text)

You need to write this:
And he enters search term "rate"

And if you get undefined step implementations maybe your files are not in correct order.
You need order something like this:
<features>
-- <steps>
-- -- pageSteps(When then etc.)
-- environment.py
-- something.feature
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900