This is a migrated thread and some comments may be shown as answers.

Assert and continue

6 Answers 61 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
CVue
Top achievements
Rank 1
CVue asked on 07 May 2015, 02:57 PM

 I know that this catches the assert and continue and log it, but I want to log the line it failed on in the code like how it does without the try catch?

 

                 try
                {
                    //Verify grid view is empty
                    Assert.IsFalse(whatever is true);
                }
                catch (Exception e)
                {
                    Log.WriteLine(e.Message);
                }

6 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 12 May 2015, 11:33 AM
Hello Cher,

Without using try..catch block the test will fail.

Why you don't want to use that block?

Please elaborate a bit more on your scenario so we can try to find you a workaround.

Looking forward to hearing from you.

Regards,
Boyan Boev
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
CVue
Top achievements
Rank 1
answered on 13 May 2015, 02:00 PM
reason why is, sure the code above works but doesn't tell you in the log is what line it failed on. I would like to go back to the log and verify where it failed.
0
CVue
Top achievements
Rank 1
answered on 13 May 2015, 02:01 PM
I want to know where in the code did it failed like what line. Since it fails but continue to go through the test, it would be nice if it failed but show you the line where it failed as well in the log.
0
Boyan Boev
Telerik team
answered on 18 May 2015, 07:32 AM
Hello Cher,

You can modify the code like this:

try
{
    Assert.AreEqual(Assert.IsFalse(whatever is true););
}
catch (Exception e)
{
    Log.WriteLine(e.StackTrace.ToString());
}


This will write into the log the entire StackTrace.

Let me know if this helps.

Regards,
Boyan Boev
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
CVue
Top achievements
Rank 1
answered on 18 May 2015, 01:52 PM
Yes, that will tell me where in the code it failed, but not what step/line it failed on.
0
Boyan Boev
Telerik team
answered on 19 May 2015, 08:30 AM
Hi Cher,

You can also add the description of the step to be outputted:

try
 
{
 
    Assert.AreEqual(true, Pages.PageTitle.input.IsVisible());
 
}
 
catch (Exception e)
 
{
 
    Log.WriteLine("The failed step is: " + ExecutionContext.CurrentStep.Description.ToString()+ Environment.NewLine + e.StackTrace.ToString());
 
}

You should add assembly reference to System.Runtime.Serialization.

Hope this helps.

Regards,
Boyan Boev
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
CVue
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
CVue
Top achievements
Rank 1
Share this question
or