【问题标题】:Python BDD logic in step definition issue步骤定义问题中的 Python BDD 逻辑
【发布时间】:2015-12-07 14:08:42
【问题描述】:

我有一个描述登录帐户的方案文件;

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 使用 Lettuce),除非我在我的场景中传入 URL,否则会失败(坏 BDD);

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

相反,我想构建一些逻辑,将路径替换为真实的 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 变量。

提前感谢您的帮助

【问题讨论】:

  • “失败并出现错误” - 什么错误?
  • pycharm中的错误是Message: f.QueryInterface is not a function
  • 步骤定义中的缩进是否只是在将其复制到 Stack Overflow 时出现的拼写错误? if 语句应该缩进。

标签: python bdd scenarios


【解决方案1】:

为什么不按名称为您的页面 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])

【讨论】:

  • 字典可以工作,但是如何获取场景中指定的传入 URL 的值?它的 if 语句不起作用。
猜你喜欢
  • 1970-01-01
  • 2018-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-17
  • 1970-01-01
  • 2023-04-10
  • 1970-01-01
相关资源
最近更新 更多