But it works on my PC!

The random thoughts of Richard Fennell on technology and software development

Debugging CodedUi Tests when launching test as a different user

If you are working with CodedUI tests in Visual Studio you sometimes get unexpected results, such as the wrong field be selected in replays. When trying to work out what has happened the logging features are really useful. These are probably already switched on, but you can check by following the details in this post.

Assuming you make no logging level changes from the default, if you look in the

      %Temp%\UITestLogs\LastRun

you should see a log file containing warning level messages in the form

Playback - {1} [SUCCESS] SendKeys "^{HOME}" - "[MSAA, VisibleOnly]ControlType='Edit'"

E, 11576, 113, 2011/12/20, 09:55:00.344, 717559875878, QTAgent32.exe, Msaa.GetFocusedElement: could not find accessible object of foreground window

W, 11576, 113, 2011/12/20, 09:55:00.439, 717560081047, QTAgent32.exe, Playback - {2} [SUCCESS] SendKeys "^+{END}" - "[MSAA, VisibleOnly]ControlType='Edit'"

E, 11576, 113, 2011/12/20, 09:55:00.440, 717560081487, QTAgent32.exe, Msaa.GetFocusedElement: could not find accessible object of foreground window

W, 11576, 113, 2011/12/20, 09:55:00.485, 717560179336, QTAgent32.exe, Playback - {3} [SUCCESS] SendKeys "{DELETE}" - "[MSAA, VisibleOnly]ControlType='Edit'"

A common problem with coded UI tests can be who you are running the test as. It is possible to launch the application user test using the following command at the start of a test

     ApplicationUnderTest.Launch(“c:\my.exe”, 
                              “c:\my.exe”, 
                             ””, 
                             ”username”, 
                            securepassword, 
                           ”domain”)

 

I have found that this launch mechanism it can cause problems with fields not being found in the CodeUI test unless you run Visual Studio as administrator (using the right click run as Administrator in Windows). This is down to who is allowed to access who's UI thread in Windows if a user is not an administrator.

So if you want to use ApplicationUnderTest.Launch and change the user for an CodedUI test, best the process running the test is an administrator.

Comments are closed