Created
November 24, 2017 10:04
-
-
Save mefarazath/28f273d1c1679036f84c1a1b0ca3eede to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.wso2.identity.integration.test.listeners; | |
import org.testng.ITestContext; | |
import org.testng.ITestListener; | |
import org.testng.ITestResult; | |
import java.io.IOException; | |
import java.nio.file.Files; | |
import java.nio.file.Paths; | |
import java.nio.file.StandardOpenOption; | |
public class LogListener implements ITestListener { | |
public LogListener() { | |
try { | |
Files.deleteIfExists(Paths.get("test-order.log")); | |
Files.createFile(Paths.get("test-order.log")); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
@Override | |
public void onTestStart(ITestResult iTestResult) { | |
String className = iTestResult.getInstance().getClass().getName(); | |
String msg = "Started executing --> " + className + "\tMethod: " + iTestResult.getMethod().getMethodName() + "\n"; | |
try { | |
Files.write(Paths.get("test-order.log"), msg.getBytes(), StandardOpenOption.APPEND); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
@Override | |
public void onTestSuccess(ITestResult iTestResult) { | |
String className = iTestResult.getInstance().getClass().getName(); | |
String msg = "Success --> " + className + "\tMethod: " + iTestResult.getMethod().getMethodName() + "\n"; | |
try { | |
Files.write(Paths.get("test-order.log"), msg.getBytes(), StandardOpenOption.APPEND); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
@Override | |
public void onTestFailure(ITestResult iTestResult) { | |
String className = iTestResult.getInstance().getClass().getName(); | |
String msg = "Failed --> " + className + "\tMethod: " + iTestResult.getMethod().getMethodName() + "\n"; | |
try { | |
Files.write(Paths.get("test-order.log"), msg.getBytes(), StandardOpenOption.APPEND); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
@Override | |
public void onTestSkipped(ITestResult iTestResult) { | |
String className = iTestResult.getInstance().getClass().getName(); | |
String msg = "Skipped --> " + className + "\tMethod: " + iTestResult.getMethod().getMethodName() + "\n"; | |
try { | |
Files.write(Paths.get("test-order.log"), msg.getBytes(), StandardOpenOption.APPEND); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
@Override | |
public void onTestFailedButWithinSuccessPercentage(ITestResult iTestResult) { | |
} | |
@Override | |
public void onStart(ITestContext iTestContext) { | |
} | |
@Override | |
public void onFinish(ITestContext iTestContext) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment