Package guru.mikelue.jdut.testng
Class ITestContextYamlFactoryListener
- java.lang.Object
-
- guru.mikelue.jdut.testng.YamlFactoryListenerBase
-
- guru.mikelue.jdut.testng.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 fromITestContext
object(which type ofIAttributes
).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() { } }
-
-
Constructor Summary
Constructors Constructor Description ITestContextYamlFactoryListener()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Optional<DuetConductor>
buildDuetConductor(IAttributes attributes)
Builds the conductor from data source inITestContext
.
This method usesITestContext.getName()
.yaml as file name of data conduction.protected boolean
needConductData(ITestContext context)
Checks whether or not the context should make.
By default, this method always returns true.void
onFinish(ITestContext context)
ExecutesduetConductorClean
if the result ofneedConductData(org.testng.ITestContext)
is true.void
onStart(ITestContext context)
ExecutesduetConductorBuild
if the result ofneedConductData(org.testng.ITestContext)
is true.void
onTestFailedButWithinSuccessPercentage(ITestResult result)
void
onTestFailure(ITestResult result)
void
onTestSkipped(ITestResult result)
void
onTestStart(ITestResult result)
void
onTestSuccess(ITestResult result)
-
Methods inherited from class guru.mikelue.jdut.testng.YamlFactoryListenerBase
buildYamlConductorFactory, duetConductorBuild, duetConductorClean, getDataSource, getLogger, removeDataSource, setDataSource
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.testng.ITestListener
onTestFailedWithTimeout
-
-
-
-
Method Detail
-
onFinish
public void onFinish(ITestContext context)
ExecutesduetConductorClean
if the result ofneedConductData(org.testng.ITestContext)
is true.- Specified by:
onFinish
in interfaceITestListener
- Parameters:
context
- The context provided by TestNG framework
-
onStart
public void onStart(ITestContext context)
ExecutesduetConductorBuild
if the result ofneedConductData(org.testng.ITestContext)
is true.- Specified by:
onStart
in interfaceITestListener
- Parameters:
context
- The context provided by TestNG framework
-
onTestFailedButWithinSuccessPercentage
public void onTestFailedButWithinSuccessPercentage(ITestResult result)
- Specified by:
onTestFailedButWithinSuccessPercentage
in interfaceITestListener
-
onTestFailure
public void onTestFailure(ITestResult result)
- Specified by:
onTestFailure
in interfaceITestListener
-
onTestSkipped
public void onTestSkipped(ITestResult result)
- Specified by:
onTestSkipped
in interfaceITestListener
-
onTestStart
public void onTestStart(ITestResult result)
- Specified by:
onTestStart
in interfaceITestListener
-
onTestSuccess
public void onTestSuccess(ITestResult result)
- Specified by:
onTestSuccess
in interfaceITestListener
-
buildDuetConductor
protected Optional<DuetConductor> buildDuetConductor(IAttributes attributes)
Builds the conductor from data source inITestContext
.
This method usesITestContext.getName()
.yaml as file name of data conduction.- Specified by:
buildDuetConductor
in classYamlFactoryListenerBase
- Parameters:
attributes
- The object ofITestContext
- Returns:
- The initialized conductor or nothing
-
needConductData
protected boolean needConductData(ITestContext context)
Checks whether or not the context should make.
By default, this method always returns true.- Parameters:
context
- The context data- Returns:
- true if this context should apply data conduction
-
-