Running Coded UI test on VM using MSTEST
Prerequisites :
Microsoft Visual Studio Agent is installed on all VMs. This is required to have all necessary libraries to run coded UI through command prompt. We are not installing full Visual studio set up and neither are we using controller and agent set up to run automated coded UI test.
What we want to achieve :
We have two applications, 1 windows based & other is web based. These applications interact with each other. Create a coded UI test for this interaction & run this on a VM.
How do we achieve :
1) Create a coded UI test for functionality you want to achieve. ( Described very well here : https://msdn.microsoft.com/en-us/library/dd286681(v=vs.100).aspx)
2) Copy and Paste the binary ( DLL) from your system to VMs on which you want to run coded UI.
3) Open command prompt in admin mode and go to below location
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE OR C:\Program Files \Microsoft Visual Studio 11.0\Common7\IDE
4) Type MSTEST.EXE /testcontainer : "LOCATION OF YOUR BINARY (DLL)"
5) Click enter.
6) Verify that test is running fine once and you are ready to go!
Things to know :
Systems supported by Coded UI : https://msdn.microsoft.com/en-us/library/dd380742.aspx
Command line options for MSTEST : https://msdn.microsoft.com/en-us/library/ms182489(v=vs.80).aspx
VMs cant be put off sleep while tests are running. More information available here : https://msdn.microsoft.com/en-us/library/ee291332.aspx
If your tests involves audio, they cant be run on VM.
To run VM remotely without keep desktop active one must configure controller & agent set up.
Coded UI now supports multi language with Visual studio 2012 CTP update. (https://blogs.msdn.com/b/visualstudioalm/archive/2012/10/30/introducing-cross-browser-testing-with-coded-ui-tests.aspx)
Common Errors:
Now while all this is happening there are few precautions that you should take care of before :
1) Use same version of windows based application in all VMs which was used while creating Coded UI test other you might get below error ( if one is creating logs of error)
INNER EXCEPTION ISSystem.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component. at Microsoft.VisualStudio.TestTools.UITest.Playback.Engine.IScreenElement.FindAllDescendants(String bstrQueryId, Object& pvarResKeys, Int32 cResKeys, Int32 nMaxDepth) at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindAllScreenElement(String queryId, Int32 depth, Boolean singleQueryId, Boolean throwException, Boolean resetSkipStep) at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindScreenElement(String queryId, Int32 depth, Boolean resetSkipStep) at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindFirstDescendant(String
queryId, Int32 maxDepth, Int32& timeLeft)
2) If coded UI test is created in Visual studio 2010, then install agent 2010 and in case test case is created in 2012, then install agent 2012
3) Make sure you have enough space in C Drive
4) In case your tests run for more than half hour then decorate your test with this attribute : [Timeout(TestTimeout.Infinite)] / alternatively you can create scheduled task.
Comments
Anonymous
May 26, 2013
Shouldn't we rather not use cmd.exe in admin mode? In my local setup, I just set current working directory to a writable location like %temp% and it seems to work in my little use case (form processing in IE 10).Anonymous
October 13, 2013
It works, but I found that it creates the UITestPlaybackResults_QTAgent32.html and screenshots under c:Program Files (x86)Microsoft Visual Studio 11.0Common7IDE. Is there a way to tell it where to put the content?Anonymous
April 03, 2014
Regarding the point "If coded UI test is created in Visual studio 2010, then install agent 2010 and in case test case is created in 2012, then install agent 2012". I have a question " We have created Coded UI test in Visual Studio 2010 But we have made test case using Microsoft Test Manager 2012. So should i install Visual Studio 2010 agents or Visual Studio 2012 agents?Anonymous
June 16, 2014
Ali Hussain : You should install Visual Studio 2010 agentsAnonymous
June 16, 2014
Alex : yes, that should also be fine. Both approaches will workAnonymous
April 22, 2015
Hi I follow the same which given above.but in my case coded ui test not getting run...Please provide the solution