gpt4 book ai didi

watin - 使用 WatiN 和 SpecFlow 对 UI 组件进行 BDD

转载 作者:行者123 更新时间:2023-12-01 02:51:21 25 4
gpt4 key购买 nike

我的问题集中在我的设置目前是否遵循有关 BDD 和 UI 验收测试的最佳实践方法。我正在使用 WatiN 和 SpecFlow 来构建我的 UI 验收测试,我正在将我的应用程序部署到 AppHarbor(一个云平台作为 .Net 应用程序的服务)。 AppHarbor 在部署时运行您的单元/集成测试,并且只有在您的测试通过后才会实时推送您的站点。所以我首先编写了一个基本的失败测试,​​如下所示:

Scenario: Navigation to homepage
When I navigate to /
Then I should be on the application homepage

与此测试相关的步骤使用 WatiN 打开浏览器并验证 View 的标题属性设置为“欢迎”。我正在检查环境以决定使用 WatiN 浏览器测试哪个 URL。例如,如果在开发中导航到“http://localhost:49641/”作为主页。否则,导航到“http://myappharborapp.com/”。

我的问题是,如果您是第一次部署此应用程序,页面或 View 实际上并不存在,因此测试失败(因为该站点尚未上线)。例如,如果我稍后添加“关于”页面 View 并首先编写失败的测试,这也会失败。当我推送更新时,测试将失败,因为“关于”页面尚不存在。

我的问题是:我是否没有遵循关于如何设置 UI 测试的最佳实践?应该如何设置这些测试,以便它们在任何环境中都能通过?

任何见解都非常感谢!

最佳答案

在“传统”watin 测试中,我使用自定义属性来指定应用程序的哪个版本以及它在什么环境中运行,然后如果缺少标准则跳过测试。

(该代码开源在 http://testingstax.codeplex.com 中的 parkcalc 示例 > 观察者 > 环境监视器)

    internal static void CheckSetEnvironment()
{
Object[] attributes = Utility.GetCallerAttributes(typeof(ExecutionEnvironment), 3);

CheckEnvironment(attributes);
}

private static void CheckEnvironment(Object[] attributes)
{
TestEnvironment = GetCurrentEnvironment();

if (attributes.Length > 0 && !attributes.Contains(new ExecutionEnvironment(TestEnvironment)))
{
Assert.Inconclusive("This test is not designed to be executed in the '" + TestEnvironment.ToString() + "' environment.");
}
}

private static EnvironmentType GetCurrentEnvironment()
{
string currentEnvironment = ConfigurationManager.AppSettings["Environment"].ToLower(CultureInfo.CurrentCulture);
EnvironmentType Environment = new EnvironmentType();

try
{
Environment = (EnvironmentType)Enum.Parse(typeof(EnvironmentType), currentEnvironment, true);
}
catch (System.ArgumentException)
{
Assert.Fail(" The current environment setting in 'Environment' in the app.config is invalid.");
}
return Environment;
}

诀窍是映射一个specflow Action 来忽略测试

“鉴于测试未在生产中运行”或类似的东西

关于watin - 使用 WatiN 和 SpecFlow 对 UI 组件进行 BDD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4876730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com