forked from qa/richrates
/
ConsoleStatusTestListener.java
79 lines (70 loc) · 2.75 KB
/
ConsoleStatusTestListener.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*******************************************************************************
* JBoss, Home of Professional Open Source
* Copyright 2009-2010, Red Hat, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*******************************************************************************/
package org.jboss.test.selenium.listener;
import org.jboss.test.selenium.utils.testng.TestLoggingUtils;
import org.testng.ITestResult;
import org.testng.TestListenerAdapter;
/**
* This class is used as ITestListener in testNG tests to put test's status to the console output
*
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>, <a href="mailto:pjha@redhat.com">Prabhat Jha</a>, <a
* href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
* @version $Revision$
*/
public class ConsoleStatusTestListener extends TestListenerAdapter {
@Override
public void onTestStart(ITestResult result) {
logStatus(result);
}
@Override
public void onTestFailure(ITestResult result) {
logStatus(result);
}
@Override
public void onTestSkipped(ITestResult result) {
logStatus(result);
}
@Override
public void onTestSuccess(ITestResult result) {
logStatus(result);
}
@Override
public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
logStatus(result);
}
/**
* This method will output method name and status on the standard output
*
* @param result
* from the fine-grained listener's method such as onTestFailure(ITestResult)
*/
private void logStatus(ITestResult result) {
String message = getMessage(result);
System.out.println(message);
if (result.getStatus() != ITestResult.STARTED) {
System.out.println();
}
}
protected String getMessage(ITestResult result) {
return TestLoggingUtils.getTestDescription(result);
}
}