编码的UI在失败断言时继续 [英] Coded UI Continue on failure Assertions

查看:107
本文介绍了编码的UI在失败断言时继续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我要问的问题已经被其他人问过了,但是我仍然不清楚那些在网上发布的内容,因此我发布此问题是为了澄清我的疑问.希望你们能帮助我.

Hi I know that what I am about to ask has been asked before by others however I am still unclear about those that has been posted online hence I am posting this Question to clarify my doubts. Hope that you guys can help me out with it.

当前,我正在使用Microsoft Visual Studio 2013 Premium.我正在使用录音和播放功能.我记录了一些动作和一些验证点.现在,当验证点失败时,脚本将立即停止.但是,即使某些点失败了,我也希望脚本继续运行.我在网上阅读了一些选项,但是我不知道该在脚本中放置什么位置. 我看到了这篇文章编码的UI-失败时继续";断言,但是我不使用SpecFlow仍然适用吗?另外,我应该将这些代码放在哪一部分?在我的方法里面?创建新方法?还是?

Currently I am using Microsoft Visual Studio 2013 Premium. I am using the record and play functions. I record some actions and a few verification points. Now the script will immediately stop when an verification point fails. However I want the script to continue running even though some point has failed. And I read of a few option online however I have no idea on where should I place those at my script. I saw this post Coded UI - "Continue on failure" for Assertions However I am not using SpecFlow is that still applicable for me? Also which part should I place those code in? Inside my method? Create a new method? Or?

bool thisTestFailed = false;
if ( ... the first assertion ... ) { thisTestFailed = true; }
if ( ... another assertion ... ) { thisTestFailed = true; }
if ( ... and another assertion ... ) { thisTestFailed = true; }
if ( thisTestFailed ) {
Assert.Fail("A suitable test failed message");
}"

推荐答案

链接的问题确实提到了Specflow,但是问题的详细信息和可接受的答案并不取决于Specflow.

The linked question does mention Specflow, but the details of the question and the accepted answer do not depend on Specflow.

通常,由编码的UI记录创建并生成的断言方法有点像:

Typically an assertion method created by Coded UI record and generate is a bit like:

void AssertionMethod1()
{
    ... get the values of fieldOne, fieldTwo, etc
    Assert.Equals(fieldOne, fieldOneExpectedValue);
    Assert.Equals(fieldTwo, fieldTwoExpectedValue);
    Assert.Equals(fieldThree, fieldThreeExpectedValue);
    ... more calls of assert methods.
}

使用的断言方法和访问字段值的机制可能会更复杂.

The assertion method used and the mechanism of accessing the field values will probably be more complex.

每个Assert.Equals(...)的实现方式均类似于以下目的的代码:

Each of the Assert.Equals(...) is implemented with code similar in purpose to:

void Assert.Equals(string actual, string expected)
{
    if ( actual == expected )
    {
        // Pass. Nothing more to do.
    }
    else
    {
        // Fail the test now.
        throw AnAssertionFailureException(...);
    }
}

因此,链接的问题建议将对记录的断言方法的调用(即,从CodedUItestMethod1调用AssertionMethod1的调用)更改为类似以下内容:

The linked question is thus suggesting changing the call to the recorded assertion method (ie the call of AssertionMethod1 from CodedUItestMethod1) to be something like:

... get the values of fieldOne, fieldTwo, etc
if(fieldOne != fieldOneExpectedValue) { thisTestFailed = true; }
if(fieldTwo != fieldTwoExpectedValue) { thisTestFailed = true; }
if(fieldThree != fieldThreeExpectedValue) { thisTestFailed = true; }
... etc.

尽管更简单的方法可能是将AssertionMethod1复制到另一个文件,然后将其修改为与上面相同的格式.编码UI中的UIMap编辑器具有将代码移至UIMap.cs"命令(可通过上下文菜单或命令图标访问)命令,该命令将方法移动到uimap.cs文件中,从而使您可以根据需要进行编辑.自动生成的代码进入uimap.designer.cs文件,并且不应编辑此文件.它和uimap.cs文件的顶部附近都有partial class UIMap,因此它们的组合内容构成了该类. uimap.cs文件用于您添加到UI Map.

Although an easier way may be to copy the AssertionMethod1 into another file and then modify it to be like the above. The UIMap editor in Coded UI has a "Move code to UIMap.cs" command (accessed by context menu or by command icon) that moves a method into the uimap.cs file, thus allowing you to edit it as needed. The auto-generated code goes into the uimap.designer.cs file and this file should not be edited. Both it and the uimap.cs file have partial class UIMap near their tops so their combined contents makes the class. The uimap.cs file is for your additions to the UI Map.

这篇关于编码的UI在失败断言时继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆