1
votes

In my test automation runs tests on two mobile devices in Parallel with testNG feamework. The @BeforeClass and the @AfterClass methods are in the base (super) class that all other test classes inherit. The BeforeClass method initialized the driver session and the AfterClass terminates the session.

The problem is that the @AfterClass is not executed. Because of that, the driver session is not terminated and the subsequent call to BeforeClass fails becasue of that.This results in execution of only the first test in each class - the rest of them are not.

I am wondering if anyone has come across this...and what the cause/remedy is!

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Parallel Mobile Tests" parallel="tests" thread-count="2"
    preserve-order="true" configfailurepolicy="continue">
    <parameter name="browserTypes" value="Mobile OS" />

    <listeners>
        <listener class-name="my.listeners.TestListener" />
        <listener class-name="my.listeners.CustomReportListener" />
    </listeners>

    <test verbose="2" name="IPHONE_6SPLUS : Parallel Tests">
        <parameter name="device" value="IPHONE_6SPLUS" />
        <parameter name="deviceOS" value="iOS" />
        <classes>
            <!-- ALL INSTALL TESTS -->
            <class name="my.tests.Install" />
            <class name="my.tests.Class1_tests" />
            <class name="my.tests.Class2_tests" />
            <class name="my.tests.Class3_tests" />
            <class name="my.tests.Class4_tests" />
            <class name="my.tests.Class5_tests" />
        </classes>
    </test>

    <test verbose="2" name="IPHONE_SE : Parallel Tests">
        <parameter name="device" value="IPHONE_SE" />
        <parameter name="deviceOS" value="iOS" />
        <classes>
            <!-- ALL INSTALL TESTS -->
            <class name="my.tests.Install" />
            <class name="my.tests.Class1_tests" />
            <class name="my.tests.Class2_tests" />
            <class name="my.tests.Class3_tests" />
            <class name="my.tests.Class4_tests" />
            <class name="my.tests.Class5_tests" />
        </classes>
    </test>

</suite> <!-- Suite -->
1

1 Answers

1
votes

Is your base class public? Following sample works for me.

public abstract class A {

 @AfterClass
 tearDown() {...}

}

class B extends A {  

 @Test
 doTests() {...}

}

You can try @AfterClass (alwaysRun = true) as well