问题
We have a Coded UI test suite which depends on running our tests as different users. We accomplish this by using the following ApplicationUnderTest.Launch overload:
ApplicationUnderTest.Launch(browserLocation, null, url, username, GetSecurePassword(password), domain);
We use Visual Studio 2013 premium (update 3) and had no problem when running on Windows 7 and Windows 2012 R2. Now we have migrated to Windows 8.1 and we are no longer able to run as a different user. We get the following infamous error:
The application cannot be started. This could be due to one of the following reasons: 1) Another instance of the application is already running and only one instance can be running at a time. 2) The application started another process and has now stopped. You may need to launch the process directly. 3) You do not have sufficient privileges for this application." File: C:\Program Files\Internet Explorer\iexplore.exe.
We are able to run Coded UI tests successfully when we run as the current user like so:
ApplicationUnderTest.Launch(browserLocation, null, url);
Unfortunately doing this does not allow us to exercise our tests. We are running Visual Studio as Administrators and all the test users we run as are set up as Administrators themselves. Do you have any idea of what the problem might be?
This is the stack trace we experience:
at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.ThrowIfProcessNotValid(Process process)
at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.SetCurrentProcessPrivate(Process value)
at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.<>c__DisplayClassb.<set_Process>b__a()
at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)
at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.set_Process(Process value)
at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.Start(ProcessStartInfo startInfo)
at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.<>c__DisplayClass10.<.ctor>b__e()
at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)
at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest..ctor(String fileName, String alternateFileName, String arguments, String userName, SecureString password, String domain)
at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.<>c__DisplayClass4.<Launch>b__3()
at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)
at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.Launch(String fileName, String alternateFileName, String arguments, String userName, SecureString password, String domain)
at Pantheon.Web.AppsPortal.UITests.Utilities.TestBase.LaunchBrowserWindow(String browserLocation, String url, String username, String password, String domain) in c:\dev_jr\AppsPortal\Development\Pantheon.Web.AppsPortal.UITests\Utilities\TestBase.cs:line 122
TestBase.cs:line 122 looks like this:
var app = ApplicationUnderTest.Launch(browserLocation, null, url, username, GetSecurePassword(password), domain);
回答1:
Since I posted this question I did some more digging and investigation. It seems that Visual Studio 2013 Update 3 broke Coded UI testing when tests run as another user on Windows 8.1. Details of the interaction can be found on MSDN here:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/f48665e4-569a-4b67-9bdb-5522b2adffb2/cannot-run-coded-ui-tests-as-different-user-on-windows-81?forum=vsmantest#28c9decb-b579-4848-a7a9-f41c57584d59
Thanks to Crystal Zhu for helping out. Unfortunately rolling back to Update 2 does not seem to be possible as Microsoft have (as far as Crystal and I can tell) made it impossible to obtain anything but the latest Update pack. Which is very frustrating. Both of us logged the issue with Microsoft:
https://connect.microsoft.com/VisualStudio/feedbackdetail/view/949052/vs2013-update-3-coded-ui-test-cant-launch-ie-under-a-different-user-on-windows-8-1-machine-with-ie11
https://connect.microsoft.com/VisualStudio/feedbackdetail/view/949049/coded-ui-cannot-run-as-a-different-user-with-visual-studio-2013-update-3
Unfortunately there has been no response as yet. I've tried (and failed) to log this through the official channels but I can only report that I have failed and been beaten down by a million call centre conversations.
Hopefully this isn't the end of the story but I wanted to log the (insignificant) progress that there has been. I won't mark this as an accepted answer because the problem still remains for now.
Edit: 07 Jan 2015:
Since there was no progress on this we ended up working around this by changing the impersonation mechanism. It's not a small switch and I consider it rather hacky. In case it's helpful I blogged about it here: (I'm afraid it's rather a long post and so moving it across to SO didn't really make sense)
http://blog.icanmakethiswork.io/2014/11/Coded-UI-IE-11-and-the-runas-problem.html
来源:https://stackoverflow.com/questions/25288508/cannot-run-coded-ui-tests-as-different-user-on-windows-8-1