Assert and continue

7 posts, 0 answers
  1. CVue
    CVue avatar
    36 posts
    Member since:
    Mar 2015

    Posted 07 May 2015 Link to this post

     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);
                    }

  2. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 12 May 2015 Link to this post

    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
     
  3. CVue
    CVue avatar
    36 posts
    Member since:
    Mar 2015

    Posted 13 May 2015 in reply to Boyan Boev Link to this post

    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.
  4. CVue
    CVue avatar
    36 posts
    Member since:
    Mar 2015

    Posted 13 May 2015 in reply to Boyan Boev Link to this post

    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.
  5. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 18 May 2015 Link to this post

    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
     
  6. CVue
    CVue avatar
    36 posts
    Member since:
    Mar 2015

    Posted 18 May 2015 in reply to Boyan Boev Link to this post

    Yes, that will tell me where in the code it failed, but not what step/line it failed on.
  7. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 19 May 2015 Link to this post

    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
     
Back to Top
  Cast Your Vote at DevPro Connections! Cast Your Vote at  Win IT Pro Connections!