Action after failed coded ui test
I am using several C # tests ordered on daily runs. Every test requires going back to a snapshot, so all data and changes are lost (which is fine for me)
But ... sometimes the test fails and all information is lost. Visual studio provides a good explanation and screenshot (very helpful)
My question is, is there a way or function to implement if, when executing a test, some files (log / crash) are copied to a network location (hardcoded function or link to bat / script file or something in play function) I tried with try options catch in your tests, but you've lost the good information you are getting from visual studio. If this is not achieved, I will fall back to try catch
Hello
as some code requested:
This is the TestMethod I am using:
//playback options + delay
Logging.playback();
Try{
Mouse.Click(uITaskListItems);
foreach (WinControl TaskList in uITaskListItems.GetChildren())
{
if (TaskList.Name.Contains(Variables.TaskItem1))
{
Mouse.Click(TaskList, MouseButtons.Right);
Mouse.Click(uIListMonitor);
break;
}
}
}catch(Exception ex){
Logging.Log(ex.Message);
Assert.Fail();
And playback options
private static void Playback_PlaybackError(object sender, PlaybackErrorEventArgs e)
{
// Wait a second
System.Threading.Thread.Sleep(1000);
// Retry the failed test operation
e.Result = PlaybackErrorOptions.Retry;
}
//playback options
public static void playback()
{
Playback.PlaybackSettings.MatchExactHierarchy = true;
Playback.PlaybackSettings.SmartMatchOptions = SmartMatchOptions.Control;
Playback.PlaybackSettings.SmartMatchOptions = SmartMatchOptions.TopLevelWindow;
Playback.PlaybackSettings.SmartMatchOptions = SmartMatchOptions.None;
Playback.PlaybackSettings.SearchTimeout = 2000;
Playback.PlaybackSettings.ShouldSearchFailFast = true;
Playback.PlaybackSettings.ThinkTimeMultiplier = 2;
Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.AllThreads;
Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.UIThreadOnly;
Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.Disabled;
Playback.PlaybackSettings.WaitForReadyTimeout = 2000;
Playback.PlaybackError -= Playback_PlaybackError;
Playback.PlaybackError += Playback_PlaybackError;
Playback.PlaybackSettings.DelayBetweenActions = 300;
}
source to share
You can use a method [TestCleanup]
that will run after each test. The code can be based on the following.
[TestCleanup()]
public void MyTestCleanup()
{
switch (TestContext.CurrentTestOutcome)
{
case UnitTestOutcome.Passed:
// Success.
break;
case UnitTestOutcome.Aborted:
case UnitTestOutcome.Error:
case UnitTestOutcome.Failed:
case UnitTestOutcome.Inconclusive:
case UnitTestOutcome.InProgress:
case UnitTestOutcome.Timeout:
case UnitTestOutcome.Unknown:
// Oh dear.
break;
default:
// Should never be called.
break;
}
}
The simplest procedure can only use one operator if
:
if (TestContext.CurrentTestOutcome != UnitTestOutcome.Passed )
{
// Oh dear.
}
source to share
You can try the Exception class.
By using the Exception class, you can get all the information about the error. - "Like a visual studio"
try
{
//make some noise...
}
catch(Exception ex)
{
Console.WriteLine(ex.InnerException);
//ex.Data, ex.HelpLink, ex.HResult, ex.Messages etc..
}
source to share