简体   繁体   English

完全相同的手动测试通过时,C#MSTEST编码的UI自动化测试失败

[英]C# MSTEST Coded UI Automated Test Fails While Identical Manual Test Passes

I've Googled and Binged and Yahoo'd and even Dogpiled. 我搜索过Google,Binged,Yahoo,甚至Dogpiled。 I found mostly Python, PHP, and Ruby that don't apply. 我发现大部分不适用的Python,PHP和Ruby。 Only one item shows up (from 2012) but it has no answer: unit test fails in r# but passes in mstest 仅显示一项(自2012年起),但没有答案: 单元测试在r#中失败,但在mstest中通过

I have two tests that work exactly as recorded. 我有两个测试完全按照记录进行。 For one, when the test gets to the Submit button, the app says the page isn't ready to be submitted and the Submit button remains disabled. 首先,当测试到达“提交”按钮时,应用程序说该页面尚未准备好提交,并且“提交”按钮保持禁用状态。 For the other, the Submit button is enabled, but the page does nothing. 另外,启用了“提交”按钮,但是页面不执行任何操作。 When I run the exact same actions manually (using keyboard and mouse) with identical data (or with different data), the Submit buttons on both pages work and both pages process. 当我手动(使用键盘和鼠标)使用完全相同的数据(或使用不同的数据)执行完全相同的操作时,两个页面上的“提交”按钮都可以工作,两个页面都可以处理。

I've run the tests to the point where the Submit buttons are clicked, but nothing happens when I manually click them, either. 我已经将测试运行到单击“提交”按钮的位置,但是当我手动单击它们时也没有任何反应。 I've tabbed from one field to the next thinking it might be an event not firing, but no. 我从一个字段移到另一个字段,以为这可能是一个没有触发但没有的事件。

Here's what I've found: If the automation opens the page, the Submit buttons will not work. 这是我发现的内容:如果自动打开页面,则“提交”按钮将不起作用。 If even one item on the page is entered or selected by the automation, the Submit buttons will not work. 如果自动化系统甚至输入或选择了页面上的一项,则“提交”按钮将不起作用。 BUT: If I run the automation to the point BEFORE the page opens, then if I click to open the page and manually keyboard and mouse the entries, and then manually mouse-click the Submit button, it will work. 但是:如果我在页面打开之前先运行自动化,然后单击打开页面并手动键盘和鼠标单击条目,然后手动单击Submit按钮,它将起作用。

The tests were recorded in MTM and imported into Visual Studio 2012. I've tried re-importing them, and I've manually recorded the steps using Visual Studio. 测试记录在MTM中,并导入到Visual Studio 2012中。我尝试重新导入它们,并使用Visual Studio手动记录了步骤。

We're now thinking there's some unexpected interaction between the testing software (MSTest) and the JavaScript in the pages. 现在,我们正在考虑测试软件(MSTest)与页面中的JavaScript之间是否存在意外交互。 We've coded (Coded UI) 11 other pages in the application. 我们已经在应用程序中的其他11页进行了编码(UI编码)。 All 11 application pages use the same basic architecture and the same controls. 所有11个应用程序页面都使用相同的基本体系结构和相同的控件。 We testers are thinking the JavaScript might be broken (missing closing brace, missing pair of parentheses, missing a semi-colon, a line-break in the wrong place, something). 我们的测试人员认为JavaScript可能已损坏(缺少右花括号,缺少一对括号,缺少分号,在错误的位置出现了换行符等)。

There is absolutely nothing unique about these tests. 这些测试绝对没有独特之处。 They are among the simplest tests I've ever coded. 它们是我编写过的最简单的测试之一。 One of them only has four input fields. 其中之一只有四个输入字段。 I've coded nothing manually; 我没有手动编码。 The UIMap.cs file is empty. UIMap.cs文件为空。 It's all in the UIMap.Designer.cs based on the UIMap.UITest file. 全部都在基于UIMap.UITest文件的UIMap.Designer.cs中。

Here is the significant portion of my Coded UI Test Class (variable setup and try-catch logic omitted): 这是我的编码UI测试类的重要部分(省略了变量设置和try-catch逻辑):

try
{
  User.OpenBrowser(TestContext);
  this.UIMap.ClickFeesButtonInSecondaryMenu();
  this.UIMap.ClickAddPaymentButton();
  this.UIMap.OpenYearDropdownAndSelect2016();
  this.UIMap.Type1234InCheckNumber();
  this.UIMap.Type275InTotalAmount();
  this.UIMap.SelectBusinessFees();
  this.UIMap.SelectInstructorFees();
  this.UIMap.ClickSubmitButton();
  User.CloseBrowser(TestContext);
}
catch . . . . 

Here is part of my UIMap.Designer.cs: 这是我的UIMap.Designer.cs的一部分:

public void ClickFeesButtonInSecondaryMenu()
{
    #region Variable Declarations
    HtmlHyperlink uIFeesHyperlink = this.UIInternetExplorerWindow.UIDocument.UIFeesHyperlink;
    #endregion

    // Click 'Fees' link
    Mouse.Click(uIFeesHyperlink, new Point(22, 21));
}

public void ClickAddPaymentButton()
{
    #region Variable Declarations
    HtmlHyperlink uIAddPaymentHyperlink = this.UIInternetExplorerWindow.UIDocument1.UIAddPaperPaymentHyperlink;
    #endregion

    // Click 'Add Payment' link
    Mouse.Click(uIAddPaymentHyperlink, new Point(84, 15));
}

    public void OpenYearDropdownAndSelect2016()
    {
        #region Variable Declarations
        HtmlHyperlink uIItem2017Hyperlink = this.UIFeeInternetExplorerWindow.UIFeeDocument.UIItem2017YearYearPane.UIItem2017Hyperlink;
        HtmlDiv uIItem2016Pane = this.UIFeeInternetExplorerWindow.UIFeeDocument.UIItem2016Pane;
        #endregion

        // Click '2017' link
        Mouse.Click(uIItem2017Hyperlink, new Point(149, 20));

        // Click '2016' pane
        Mouse.Click(uIItem2016Pane, new Point(124, 3));
    }

    public void Type1234InCheckNumber()
    {
        #region Variable Declarations
        HtmlEdit uICheckNumberEdit = this.UIFeeInternetExplorerWindow.UIFeeDocument1.UICheckNumberEdit;
        #endregion

        // Type '1234' in 'Check Number' text box
        uICheckNumberEdit.Text = this.Type1234InCheckNumberParams.UICheckNumberEditText;
    }

. . . and so on until you get to . 依此类推,直到到达。 . .

public void ClickSubmitButton()
{
    #region Variable Declarations
    HtmlInputButton uISubmitButton = this.UIFeeInternetExplorerWindow.UIFeeDocument1.UISubmitButton;
    #endregion

    // Click 'Submit' button
    Mouse.Click(uISubmitButton, new Point(27, 17));
}

I've only been doing C# MSTEST Coded UI just over a year, but I have three other automators here with tons more experience than I have, and this problem is new to us all. 我只使用C#MSTEST编码的UI才一年多,但是我在这里还有另外三个自动化器,比我拥有更多的经验,这个问题对我们所有人来说都是新问题。 We've looked at everything we can think of, but no joy. 我们已经查看了所有可以想到的内容,但没有喜悦。 Has anyone seen this? 有人看过吗? What causes this behavior? 是什么原因导致这种现象? Most importantly, is there a fix? 最重要的是,有修复程序吗?

Because you mentioned that you think the JS may be broken, that leads me to believe that perhaps some sort of AJAX is going on in the background after clicking the button. 因为您提到您认为JS可能已损坏,所以让我相信单击按钮后,后台可能正在进行某种AJAX。 If that is the case, please see this question to see if it applies to your case. 如果是这种情况,请查看此问题以查看它是否适用于您的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM