Using soft assertion does not attach correct snapshot for failed test

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Using soft assertion does not attach correct snapshot for failed test

garvitagirotraev
Hi,

I am using soft assertion for validating charts. At end of test i write assertAll() because i am using multiple assertions in one test. Assertion failures are reported correctly. Screenshot is attached for every failed test case.

Issue is :
As assertAll() is last line in test(supposed to be), when it reports that test is failed- screenshot is taken for current open page. Can we add screenshot when assertion fails?

Example :
Class util
{
  // contains create_chart(String parameter) method

  // 3 assertions are done everytime create_chart() method is called.
}

Class PieChart()
{
    util.create_chart("companies");    // if one assertion fails here, test continues and as test is reported fail after executing last line in test, screenshot is                                                                take for that screen.
    util.create_chart("year");
    assertAll();
}


Can i attach screenshot at time when assertion fails?

Thanks !!

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Using soft assertion does not attach correct snapshot for failed test

⇜Krishnan Mahadevan⇝
Here's how you do it.

  1. subclass org.testng.asserts.SoftAssert
  2. Override org.testng.asserts.Assertion#onAssertFailure(org.testng.asserts.IAssert<?>, java.lang.AssertionError) and include your screenshot recording logic
  3. Have all of your tests use the subclassed variant of SoftAssert [ That you created in (1) ]

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Thu, Dec 7, 2017 at 2:37 PM, <[hidden email]> wrote:
Hi,

I am using soft assertion for validating charts. At end of test i write assertAll() because i am using multiple assertions in one test. Assertion failures are reported correctly. Screenshot is attached for every failed test case.

Issue is :
As assertAll() is last line in test(supposed to be), when it reports that test is failed- screenshot is taken for current open page. Can we add screenshot when assertion fails?

Example :
Class util
{
  // contains create_chart(String parameter) method

  // 3 assertions are done everytime create_chart() method is called.
}

Class PieChart()
{
    util.create_chart("companies");    // if one assertion fails here, test continues and as test is reported fail after executing last line in test, screenshot is                                                                take for that screen.
    util.create_chart("year");
    assertAll();
}


Can i attach screenshot at time when assertion fails?

Thanks !!

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.