我有一个描述登录帐户的方案文件;
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."
在我的步骤定义(使用Lettuce的Python)中,除非我在我的场景中传入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)
此操作因错误而失败,无论我如何尝试设置,我似乎都无法设置网址变量。
提前感谢您提供任何帮助
答案 0 :(得分:0)
为什么不按名称使用页面网址的字典映射?
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])