Class ITestContextYamlFactoryListener

  • All Implemented Interfaces:
    ITestListener, ITestNGListener

    public class ITestContextYamlFactoryListener
    extends YamlFactoryListenerBase
    implements ITestListener
    This listener uses file name(classpath:<test_name>.yaml) for resource(ClassLoader of current thread) of conducting data.

    By default, the DataSource would be retrieved from ITestContext object(which type of IAttributes).

    It is recommended that client implements needConductData(org.testng.ITestContext) to trigger data conduction.

    Example by defulat conventions:

    
     package guru.mikelue.jdut.testng.example;
    
     // File: classpath:MakoSharkTest.yaml
     @Test(testName="MakoSharkTest")
     @Listeners(MakoSharkTest.MakoSharkSuiteListener.class)
     public class MakoSharkTest {
         public static MakoSharkSuiteListener extends ITestContextYamlFactoryListener {
             @Override
             public void onStart(ITestContext context)
             {
                 YamlFactoryListenerBase.setDataSource(context, getDataSource(context));
                 super.onStart(context);
             }
             @Override
             public void onFinish(ITestContext context)
             {
                 super.onFinish(context);
                 YamlFactoryListenerBase.removeDataSource(context);
             }
         }
    
         @Test
         public void bite()
         {
         }
     }