我有一个描述登录帐户的场景文件;
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变量,我似乎都无法设置它
提前感谢的任何帮助
为什么不按名称为页面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])