简体   繁体   中英

Coded UI Test - Inconsistently finds HtmlDocument

I am having issues getting Visual Studio 2013 's Coded UI Test framework to consistently find an HtmlDocument .

I have only just recently experienced this issue where it was working great prior. Unfortunately many things have changed (including my version of Visual Studio AND Internet Explorer, among others) since I created these tests, so it is very difficult to pinpoint what change is causing this. Also, the fact that it works roughly 2/3 of the time makes it more difficult to troubleshoot.

In my tests I have a set of different users log into the site under test and perform various actions. In order to do this, I captured via the UI Test Builder the actions of right clicking on the Internet Explorer button while holding shift, then clicking the " Run as different user " menu option. The test proceeds to input the users credentials and their homepages are loaded. (Each user has a profile on my machine, and they all have Google as their homepage.) A call to NavigateTo() on the BrowserWindow allows me to load the site and the test officially starts from there.

The hang-up is occurring when I attempt to call NavigateTo() and gives me the following error:

NOTE: If the homepage CAN be found, there are no issues dealing with any preceding HtmlDocuments or BrowserWindows.

... threw exception.
Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException:
Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException:
The playback failed to find the control with the given search properties.
Additional Details: 
TechnologyName:  'MSAA'
ControlType:  'Button'
Name:  'Internet Explorer'
---> System.Runtime.InteropServices.COMException:
     Error HRESULT E_FAIL has been returned from a call to a COM component..

EDIT: Sometimes I get this error instead:

...threw exception. Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException: Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException: Unable to find Windows Internet Explorer window with 'Google - Internet Explorer' in the title. ---> Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException: The playback failed to find the control with the given search properties. Additional Details: 
TechnologyName:  'MSAA'
ControlType:  'Window'
Name:  'Google - Internet Explorer'

ClassName: 'IEFrame' ---> System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component..

I've attempted various WaitFor calls on the BrowserWindow , the HtmlDocument , etc.

I've tried including a try / catch block where it will forget about the HtmlDocument if it fails and try again (so it researches for the HtmlDocument ) as a just in case, but that doesn't work either.

Searching the vast web of knowledge has not helped me figure out how to fix this (it is such a trivial thing to use the BrowserWindows and HtmlDocuments that I seem to only be able to find issues dealing with finding specific controls).

Does anyone have any ideas or recommendations for me about what else I can try?

Ok, I lied. I found out what really fixed it. I gave my test accounts Administrative rights on the machine running the tests. Simple. It may not be ideal, but the test accounts can't really do anything anywhere else if they are compromised.

It appears running an application without Administrative rights, then trying to capture it in a Coded UI Test fails because the application is running with less rights than the instance of Visual Studio.

So my role-based tests are working, and they are FAST.

I fixed this issue by reducing the computational load on the PC running the tests. It appears that a system not "burdened" with running applications executes just fine. I don't know what conditions setup a "burdened" environment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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