Load Test方法抛出异常System.NullReferenceException:对象引用未设置为对象的实例

时间:2013-06-25 19:33:38

标签: load-testing coded-ui-tests

我为我的网络应用程序创建了以下Web Coded UI测试。

执行时,测试用例成功。

当测试用例作为“加载测试”的一部分添加时,它会开始抛出错误消息。

Test Error TestError 4 Test method testWithSQLExp.CodedUITest2.CodedUITestMethod1 threw exception: 
System.NullReferenceException: Object reference not set to an instance of an object.

BTW相同的负载测试与相同的codedUI测试工作正常,当用户数设置为1时。

我的代码如下 的 UIMap.cs

   public void AssertMethod1()
    {
        #region Variable Declarations
        HtmlCell uIItem1363758Cell = this.UIFirstNetHomePageWindWindow.UIEConnectFirstMeritBaDocument1.UIMainContent_gvAccounTable.UIItem1363758Cell;
        #endregion
        // Verify that the 'InnerText' property of '$13,637.58' cell equals '$13,637.58'
        Assert.AreEqual(this.AssertMethod1ExpectedValues.UIItem1363758CellInnerText, uIItem1363758Cell.InnerText);
    }

public void RecordedMethod1()
    {
        #region Variable Declarations
        HtmlEdit uICompanyEdit = this.UIFirstNetHomePageWindWindow.UIBusinessDocument.UICompanyEdit;
        HtmlEdit uIUsernameEdit = this.UIFirstNetHomePageWindWindow.UIBusinessDocument.UIUsernameEdit;
        HtmlEdit uITxtPasswordEdit = this.UIFirstNetHomePageWindWindow.UIEConnectFirstMeritBaDocument.UITxtPasswordEdit;
        #endregion
        // Go to web page 'https://dev.firstmerit.com/business/index.html' using new browser instance
        this.UIFirstNetHomePageWindWindow.LaunchUrl(new System.Uri(this.RecordedMethod1Params.UIFirstNetHomePageWindWindowUrl));
        // Type 'demo' in 'Company' text box
        uICompanyEdit.Text = this.RecordedMethod1Params.UICompanyEditText;
        // Type '{Tab}' in 'Company' text box
        Keyboard.SendKeys(uICompanyEdit, this.RecordedMethod1Params.UICompanyEditSendKeys, ModifierKeys.None);
        // Type 'user' in 'Username' text box
        uIUsernameEdit.Text = this.RecordedMethod1Params.UIUsernameEditText;
        // Type '{Enter}' in 'Username' text box
        Keyboard.SendKeys(uIUsernameEdit, this.RecordedMethod1Params.UIUsernameEditSendKeys, ModifierKeys.None);
        // Type '********' in 'txtPassword' text box
        uITxtPasswordEdit.Password = this.RecordedMethod1Params.UITxtPasswordEditPassword;
        // Type '{Enter}' in 'txtPassword' text box
        Keyboard.SendKeys(uITxtPasswordEdit, this.RecordedMethod1Params.UITxtPasswordEditSendKeys, ModifierKeys.None);
    }

CodedUITest2.cs

命名空间testWithSQLExp {

[CodedUITest]
public class CodedUITest2
{
    public CodedUITest2()
    {
    }

[TestMethod]
    public void CodedUITestMethod1()
    {
        // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
        // For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463
        this.UIMap.RecordedMethod1();
        this.UIMap.AssertMethod1();
    }

public TestContext TestContext
    {
        get
        {
            return testContextInstance;
        }
        set
        {
            testContextInstance = value;
        }
    }
    private TestContext testContextInstance;

    public UIMap UIMap
    {
        get
        {
            if ((this.map == null))
            {
                this.map = new UIMap();
            }

            return this.map;
        }
    }

    private UIMap map;
}

}

1 个答案:

答案 0 :(得分:0)

找到答案..

msdn code UI limitation - http://msdn.microsoft.com/en-us/library/ff468125.aspx

负载测试中的编码UI测试限制


编码的UI测试驱动鼠标和键盘。因此,每个代理只能有1个虚拟用户运行编码的UI测试。控制此操作的最佳方法是在负载测试中设置单独的方案,并将用户负载设置为1个用户。