TestNG Assertion class Overrides

Source: Internet
Author: User
Tags testng

Assertion fails without exiting the use case, providing settlement method settlement assertion

 Public classSoftassertextendsAssertion {PrivateWebdriver Driver; Private FinalString Screenshot_path =system.getproperty ("User.dir") + "/target/testreport/screenshot/";  PublicSoftassert (webdriver driver) { This. driver=driver; }    PrivateMap<assertionerror, iassert> m_errors =Maps.newlinkedhashmap (); PrivateList<string> screenshotlist =NewArraylist<>(); /*** Override method, assertion failure does not exit use case, join failed *@parama*/@Override Public voidExecuteassert (Iassert a) {Try{A.doassert (); } Catch(Assertionerror ex) {onassertfailure (A, ex);            M_errors.put (ex, a); Basisutil util=NewBasisutil ();        Screenshotlist.add (Util.getscreenshot (Driver, Screenshot_path)); }    }    /*** Settlement*/     Public voidAssertall () {if(!M_errors.isempty ()) {StringBuilder SB=NewStringBuilder ("The following asserts failed:\n"); BooleanFirst =true;  for(Map.entry<assertionerror, iassert>Ae:m_errors.entrySet ()) {                if(first) { first=false; } Else{sb.append (", ");            } sb.append (Ae.getkey (). GetMessage ()); }            Throw NewAssertionerror (sb.tostring ()); }    }}

TestNG Assertion class Overrides

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.