0

When we run a CodedUI test case with the following code to close a dialog popup (JavaScript alert):

CurrentBrowser.PerformDialogAction(BrowserDialogAction.Ok);

Or, with the following code:

var popupWindow = new WinWindow(null);
popupWindow.SearchProperties.Add("Name", "Message from webpage", "ClassName", "#32770");
popupWindow.TechnologyName = "MSAA";

var okButton = new WinButton(popupWindow) { TechnologyName = "MSAA" };
okButton.SearchProperties.Add("Name", "OK");

okButton.SetFocus();
Keyboard.SendKeys(okButton, "{ENTER}");

It works locally, but when we run the via Microsoft Test Manager on a VDI with the same version of Windows and Internet Explorer the popup is not closed. No error is thrown, the VDI just waits.

We are using the following versions:

TFS 2012 update 4 test agent
Internet Explorer 10
Windows 7 Enterprise

Does anyone know why this could be and how it can be solved?

user2609980
  • 10,264
  • 15
  • 74
  • 143
  • 1
    Can you try it without the ("Name", "Message from webpage") ? It might be a culture setting thing (other language or some added text for your service account) that it can't find the popupWindow. – Rolf Huisman Oct 01 '15 at 04:56
  • Thanks Rolf. Unfortunately this does not make a difference. – user2609980 Oct 06 '15 at 14:27

2 Answers2

1

Generally, you want to use SetFocus on the window not the button. What is DrawHighlight doing? Have you removed ClassName search property from Window?

  • Hi Alex, I did not remove the ClassName search property. I will try to remove that. Another suggestion (by Rolf) was to execute JavaScript from C# to close the alert box. I will try that if removing the class name does not help. `DrawHighlight` was there to check if the box was highlighted. I'll post the results here. – user2609980 Oct 07 '15 at 16:55
  • Update 1: [seems](http://stackoverflow.com/questions/19020830/autoclose-alert) you cannot close an alert with JavaScript. This makes the JavaScript solution not going to work. I will follow your hints. – user2609980 Oct 07 '15 at 16:59
  • We did remove all the information. Resulting code was: `var popupWindow = new WinWindow(null) { TechnologyName = "MSAA" }; var okButton = new WinButton(popupWindow) { TechnologyName = "MSAA" }; okButton.SearchProperties.Add("Name", "OK"); Keyboard.SendKeys(okButton, "{ENTER}");`. That did not work. I try to remove the "Name" property! If that does not work: another thing that might be the cause is the version of CodedUI. We are using TFS 2012 on the VDI and locally we run with 2013/2015 CodedUI dlls. – user2609980 Oct 07 '15 at 17:13
  • `code` var popupwindow = new WinWindow(); popupwindow.SearchProperties.Add("Name", "Message from webpage"); var okButton = new WinButton(popupwindow); okButton.SearchProperties.Add("Name", "OK"); Mouse.Click(okButton); – AlexCharizamhard Oct 09 '15 at 15:50
0

Turned out that locally I used Visual Studio 2015 to run. The build and MTM used TFS 2012. There was a mismatch in CodedUI dlls. Apparently something was fixed in CodedUi that made clicking on an alert box possible.

Removing conditional choosing of (old) dll's:

<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
  <ItemGroup>
    <Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <Private>False</Private>
    </Reference>
    <Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <Private>False</Private>
    </Reference>
    <Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <Private>False</Private>
    </Reference>
    <Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <Private>False</Private>
    </Reference>
  </ItemGroup>
</When>

from the csproj file and referencing newer versions solved the issue.

user2609980
  • 10,264
  • 15
  • 74
  • 143