Wednesday, April 23, 2014

VSTS Challenges

VSTS:-




Sometime we face issue like whenever we recorded any control and when we play back it fails by saying:- "uitestcontrolnotfoundexception" but control was there. Some time it occurs due to accessibily of application class.
In that case we can use keyboard.sendkeys("samplestring") to send our sample string on particular control. To get the access of that control we cab use "tab, shift +tab , mouse.click etc."
e.g.:-
Keyboard.sendkeys("+{TAB}");
keyboard.sendkeys("SampleKeys");


cheers!!!


Logging:-

In this article, we will find out how to enable tracing logs when executing with Coded UI Test in Visual Studio 2012. We can use these logs for debugging which will make it easier to find out issues when a Coded UI Test fails.
The tracing can be seen in a html log file. The unfortunate part is that this logging in not available in Coded UI Test by default. We need to change the configuration file in order to enable tracing log. This file depends upon the .NET framework we are working with.
- If the application is targeting .NET Framework 4.0 and there is no App.config file present in the test project, we need to change QTAgent32_40.exe.config.
OR
- If the application is targeting .NET Framework 4.5 and there is no App.config file present in the test project, we need to change QTAgent32.exe.config
In both of the above cases, we need to provide the value of EqtTraceLevel to the level we want
If there is an App.config file present in the test project, we can directly add the configuration entry as
<system.diagnostics>
<switches>
<add name="EqtTraceLevel" value="4" />
</switches>
</system.diagnostics>

This entry needs to be added under configuration node.
Let us discuss where the config file is present and how the tracing log will look like. For this demonstration, I am using framework 4.5 with no App.Config present. The QTAgent32.exe.cofig will be available at drive letter\<Visual Studio Installation folder>\Common7\IDE OR at C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE
Open the file from the specified folder and change the following
trace-level
There are total 4 levels available as can be seen from the snapshot.
The blog Analyzing Coded UI Tests using Logs discusses about adding the entries for EnableHTMLLogger and EnableSnapshotInfo by setting them to true.
enable-html-logger
But these 2 entries have been deprecated as described by the post Enable Tracing in CUIT. Now that we have done the necessary configuration setting, what remains is to run the Coded UI Test and find out how the html log gets created.
I have executed one Coded UI Test which is successfully executed and we get the result as follows
execute-cuit
Clicking on Output provides the attachment link to the log
attachment
The log is shown as below
cuit-test-log
If we change the EqtTraceLevel to 4 (verbose) we get the complete debug trace
debug-trace
Now let us run a Coded UI Test which fails while execution. I have used a Windows Application action recording for this.
The test fails
failed-test
The output shows the attachment for log file
log-attachment
The html log looks as the following in 2 parts
coded-ui-test-log
Expanding the last action shows
action-failed
Observe that the png file is also embedded as a part of log file. The log can also be found at %temp%\UITestLogs in the folder of LastRun
Important points: If the log file is not shown with the test execution, ensure that the QTAgent32 process is re-started. We can ensure this by clearing the check box for Keep test execution running between test runs as shown below
test-execution-actions
That’s it. This is how we enable tracing logs when executing with Coded UI Test in Visual Studio 2012.