基本上,我编写了一个名为@When("I go to {url}")的步骤
然后,我使用When I go to http://youtube.com从要素文件中调用它,它起作用了
但我想使用When I go to YouTube调用它
css选择器也是如此(因为Then logo is visible看起来比Then div#id.class is visible更漂亮)
如何将包含此css选择器和URL的映射文件链接为我的步骤使用的变量?如下所示:
YouTube = "http://youtube.com"
logo = "div#id.class"我试过了
def before_all(context):
global YouTube
YouTube = "http://youtube.com"然后我会在步骤中定义,但它一直说YouTube没有定义
发布于 2017-06-18 03:43:43
您应该使用预定义URL的字典,而不是变量。将以下代码添加到steps实现文件中:
websites = {'youtube': 'http://youtube.com', 'somesite': 'http://somesite.com'}
@When("I go to {website}")
def when_i_go_to_website(context, website):
context.url = websites[website]context.url将在以下所有步骤中可用。
您可能希望使用try / except将代码行括起来以捕获KeyErrors。
https://stackoverflow.com/questions/44608564
复制相似问题