【发布时间】:2018-05-17 11:44:46
【问题描述】:
我正在编写 UI 测试。这是为了检查我在 Web.Config 中启用的错误 404 页面;
<customErrors mode="On" redirect="~/Errors/"/>
这一切都很好,但是我只有在“UAT”开发环境中将自定义错误设置为“开”。如果我在“Dev”或“IST”中,那么我仍然希望看到默认的 ASP.Net 错误。
现在回到使用 Selenium 的 UI 测试
public string GetAlertBoxDetails()
{
IWebElement alertBox = _driver.FindElement(By.CssSelector(".alert.alert-danger"));
return alertBox.Text;
}
如您所见,我正在检测 Bootstrap “.alert.alert-danger” 框并返回其中的文本。然后我检查此文本是否包含“抱歉,该页面不存在。”。我正在为文本故事使用 Specflow。
[Then(@"The user should be told that no such page exists")]
public void ThenTheUserShouldBeToldThatNoSuchPageExists()
{
string alertboxDetail = GetAlertBoxDetails();
Assert.IsTrue(alertboxDetail.Contains("Sorry, that page doesn't exist."), "Couldn't find the message \"Sorry, that page doesn't exist.\"");
}
这一切都很好,但是我只希望这个测试在 UAT 环境中运行。这是因为只有在 customErrors 设置为“Off”时才能找到元素“.alert.alert-danger”。为此,我在测试中包含了这一步。
[Given(@"I am in the UAT environment")]
public void GivenIAmInTheUATEnvironment()
{
var env = EnvironmentType;
if (env != EnvironmentType.Uat)
{
Assert.Inconclusive($"Cannot run this test on environment: {env}. " +
$"This test is only for the UAT environment.");
}
else
{
Assert.IsTrue(true);
}
}
再次,这工作正常。我唯一的问题是我不想使用“Assert.Inconclusive”,我宁愿使用“Assert.Pass”并说如果在非 UAT 环境中进行测试通过。
我看到 XUnit 有一个 Assert.Pass 函数,但是这可以在 MsTest 中完成吗?强制测试通过而不继续下一个断言。在 specflow 中,我正在运行“给定”步骤,我想阻止它继续执行“然后”步骤。
【问题讨论】:
-
情况很有趣,但不清楚您的问题究竟是什么。请告诉我们您的实际要求。
-
嗨@Charlie 抱歉不清楚。我已经重写了问题以包含更多代码示例。
标签: c# unit-testing nunit mstest xunit