Anton Anton
Anton Anton

Reputation: 123

TestNG does not continue execute tests after failure

I have test automation framework with a page object model. All my test are located in separate classes in same package.

In testng.xml i have

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Smoke Test">
    <test name="SmokeTest">
        <classes>
            <class name="name.test1"/>
            <class name="name.test2"/>
            <class name="name.test3"/>
        </classes>
    </test>
</suite>

Problem is that after running TestNG.xml if the 1st test will fail, it will stop test execution. But i want to continue executing of all test cases.

I use Jenkins on my project and if one of the tests are failed it stops execution immediately.

Example of test

public class LoginTestTest {
    public AndroidDriver<AndroidElement> driver;
    public AOWebClient aoWebClient;

    AOWebClient aoWeb;
    public LoginTestTest(AndroidDriver<AndroidElement> driver, AOWebClient aoWeb){
        this.driver = driver;
        this.aoWeb = aoWeb;
        PageFactory.initElements(new AppiumFieldDecorator(driver), this);
    }

    public LoginTestTest() {
    }

    SoftAssert softAssert = new SoftAssert();

    @BeforeClass
    public void setUp() throws Exception {

        driver = DesiredCapabilitiesSetup.startAppiumServer();
        aoWebClient = DesiredCapabilitiesSetup.getAOWeb();

        LogIn logIn = new LogIn(driver,aoWebClient);
        logIn.logIn();
    }

    @org.testng.annotations.Test
    public void goToSettings() throws InterruptedException {
        HeaderMenu header = new HeaderMenu(driver,aoWeb);
        HamburgerMenuList ham = new HamburgerMenuList(driver);

        header.clickHamburgerButton();
        header.clickHamburgerButton();

        header.editButtonClick();


        softAssert.assertAll();
    }   

    @AfterClass
    public void tearDown(ITestResult result) throws Exception {
            if (result.getStatus() == ITestResult.FAILURE) {
                TakeScreenshot screenshot = new TakeScreenshot();
                screenshot.TakeScreenshot("screenshots/");
            }
        LogOut logOut = new LogOut(driver,aoWeb);
        logOut.logOut();
    }
}

If my test will fail in @Test it will never continue to @AfterClass method. And I want that if @Test fail it will continue to @AfterClass method and After This Class continue executes test from other classes from testng.xml.

Upvotes: 1

Views: 18885

Answers (3)

Rahul
Rahul

Reputation: 1

Add below attribute in testng.xml file under Suite syntax

<suite thread-count="25" name="Smoke" parallel="classes" skipfailedinvocationcounts="true">

Work for me, hope it will work for you as well :)

Upvotes: 0

Jerrod Anderson
Jerrod Anderson

Reputation: 61

Your suite tag in your xml should include configfailurepolicy="continue". This tells testng that even though a config failed in one class, you still want to run other classes in that suite. See "configfailurepolicy" in the documentation.

So your xml would become:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Smoke Test" configfailurepolicy="continue">
    <test name="SmokeTest">
        <classes>
            <class name="name.test1"/>
            <class name="name.test2"/>
            <class name="name.test3"/>
        </classes>
    </test>
</suite>

Upvotes: 6

juherr
juherr

Reputation: 5740

From the documentation:

alwaysRun: For after methods (afterSuite, afterClass, ...): If set to true, this configuration method will be run even if one or more methods invoked previously failed or was skipped.

Then, just replace your @AfterClass by @AfterClass(alwaysRun = true).

Upvotes: 2

Related Questions