步骤定义问题中的Python BDD逻辑

步骤定义问题中的Python BDD逻辑,python,bdd,scenarios,Python,Bdd,Scenarios,我有一个描述登录帐户的场景文件 Scenario: Failed login with blank login details Given I go to "BBC Login Page" When I fill in the username textfield with "" And I fill in the password textfield with "" And I press "Log in" Then I should see "In o

我有一个描述登录帐户的场景文件

Scenario: Failed login with blank login details
    Given I go to "BBC Login Page"
    When I fill in the username textfield with ""
    And I fill in the password textfield with ""
    And I press "Log in"
    Then I should see "In order to login, you must enter a valid user name."
在我的步骤定义(Python使用莴苣)中,除非在我的场景中传入URL,否则将失败(坏BDD)

取而代之的是,我想建立一点逻辑,用路径代替真正的URL

msr_login_page = "https://www.bbc.co.uk/login"

@step('I go to "(.*?)"$')
def go_to(step, url):
if url == "BBC Login page":
    urladjusted = msr_login_page
    with AssertContextManager(step):
            world.browser.get(urladjusted)
这失败了,出现了一个错误,无论我如何设置URL变量,我似乎都无法设置它


提前感谢您的帮助

为什么不按名称为页面URL使用字典映射

urls = {"BBC Login page": "https://www.bbc.co.uk/login"}

@step('I go to "(.*?)"$')
def go_to(step, page):
    with AssertContextManager(step):
        world.browser.get(urls[page])

“此操作因错误而失败”-什么错误?pycharm中的错误是消息:f.QueryInterface不是函数步骤定义中的缩进是否只是将其复制到堆栈溢出时的打字错误?if语句应该缩进。字典可以工作,但是如何获得场景中指定的传入URL的值?它的if语句不起作用。
urls = {"BBC Login page": "https://www.bbc.co.uk/login"}

@step('I go to "(.*?)"$')
def go_to(step, page):
    with AssertContextManager(step):
        world.browser.get(urls[page])