将参数从黄瓜特征传递到Python脚本? [英] Pass parameters from a cucumber feature to Python script?

查看:73
本文介绍了将参数从黄瓜特征传递到Python脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Cucumber(Behave),python和selenium编写一个简单的BDD脚本。

我的功能和脚本的前两步工作但我从我的Behave功能获取参数到我的Python脚本。



当我不遵守行为特征时,我一直收到这个错误:

你可以实现步骤定义对于这些片段的未定义步骤:

@when(你输入搜索词速率')
def step_impl(context):
raise NotImplementedError(u'STEP:当他输入搜索条件费率')





黄瓜/表现特征:



场景:有效收款人
鉴于用户在页面
当他点击搜索字段
并且他输入搜索字词'rate'





Python脚本:



从行为导入给出,何时,然后
xurl =''

@given('用户在页面')
def step_user_is_on_ fund_transfer_page(context):
context.driver.get(#)

@when('他点击搜索字段')
def step_he_clicks_search_field(context):
context.driver.find_element_by_id(cludoquery)。click()


@when('他输入搜索词{text}')
def step_he_enters_searchterm(上下文,文本):
context.driver.find_element_by_id(cludoquery)。send_keys(text)





Selenium env:



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

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





我尝试了什么:



我尝试过使用'rate'和< rate>在我的参数的功能文件中,我尝试在python脚本中使用{text},{text}但没有成功。



有什么想法吗?

解决方案

我做的是





他是输入搜索字词< rate>





并且在.py



  @ when ' 他输入一个搜索词(。*)'
def step_he_enters_searchterm(context,text):
context.driver.find_element_by_id( cludoquery)。send_keys(text)







这使用正则表达式来查找变量,并将该变量赋值给文本。





确保将它放在.py的顶部,这样就可以使用正则表达式了。



 use_step_matcher('  re'


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?

解决方案

What I do is


And he enters a search term "<rate>"



And in the .py

@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.

use_step_matcher('re')


这篇关于将参数从黄瓜特征传递到Python脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆