是否可以制定一个场景大纲,其中每个示例都在不同的 URL 中运行?例如,如果示例表中的第一列是某种两位数/字符代码,是否根据该值打开不同的起始 URL?
最佳答案
是的,当然。为什么不直接设置 URL,将要使用的 URL 分配给某个变量(在类中、在 ScenarioContext.Current
中或在自定义上下文对象中),然后使用它您所有通话中的 URL。在我的手机上,所以格式化很痛苦,但像这样:
Given I'm using the site '<site>'
When I login
Then something should happen
Examples:
|site |
| aaa.com|
| bbb.com|
然后在给定的步骤中,只需记录 URL 并使用该基本 URL 在“when”步骤中构建完整的 URL。
你的步骤类可能看起来像这样。
[Binding]
Public class Steps
{
Private string baseUrl;
[Given ("I'm using the site '(.*)'")]
Public void GivenImUsingTheSite(string baseUrl)
{
This.baseUrl=baseUrl;
}
[When ("I log in")
Public void WhenILogIn()
{
String URL=baseUrl + "\login";
....login
}
}
关于selenium - 具有不同 URL 的 Specflow 场景大纲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32273285/