com.github.bogdanlivadariu.reporting.testng.helpers.Helpers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of testng-reporting-handlebars Show documentation
Show all versions of testng-reporting-handlebars Show documentation
Module used to generate TestNG reports using handlebars
package com.github.bogdanlivadariu.reporting.testng.helpers;
import static com.github.bogdanlivadariu.reporting.testng.helpers.Constants.FAILED;
import static com.github.bogdanlivadariu.reporting.testng.helpers.Constants.PASSED;
import static com.github.bogdanlivadariu.reporting.testng.helpers.Constants.SKIPPED;
import static com.github.bogdanlivadariu.reporting.testng.helpers.Constants.UNDEFINED;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Helper;
import com.github.jknack.handlebars.Options;
public class Helpers {
public static final String PROBLEM_SETTING_STATUS =
"there was a problem setting the tooltip of the test, status might differ, investigate";
private Handlebars handlebar;
public Helpers(Handlebars handlebar) {
this.handlebar = handlebar;
}
public Handlebars registerHelpers() {
handlebar.registerHelper("date", new Helper() {
public CharSequence apply(Long arg0, Options arg1) throws IOException {
int totalSecs = (int) arg0.doubleValue() / 1000;
int hours = totalSecs / 3600;
int minutes = (totalSecs % 3600) / 60;
int seconds = totalSecs % 60;
int miliSec = (int) arg0.doubleValue() % 1000;
return String.format("%02d h : %02d m : %02d s : %02d ms", hours, minutes, seconds, miliSec);
}
});
handlebar.registerHelper("result-color", new Helper() {
@Override
public CharSequence apply(String arg0, Options arg1) throws IOException {
return checkStatus(arg0.toLowerCase(), "info", "success", "danger", null);
}
});
handlebar.registerHelper("is-config", new Helper() {
@Override
public CharSequence apply(Boolean arg0, Options arg1) throws IOException {
return getIsConfigApplyResult(arg0);
}
});
handlebar.registerHelper("resolve-tooltip", new Helper() {
@Override
public CharSequence apply(String arg0, Options arg1) throws IOException {
return checkStatus(arg0.toLowerCase(), "This test has been skipped", "This test has passed",
"This test has failed", PROBLEM_SETTING_STATUS);
}
});
handlebar.registerHelper("resolve-title", new Helper() {
@Override
public CharSequence apply(String arg0, Options arg1) throws IOException {
return checkStatus(arg0.toLowerCase(), "This step has been skipped", "This step has passed",
"This step has failed", null);
}
});
handlebar.registerHelper("is-collapsed", new Helper() {
@Override
public CharSequence apply(String arg0, Options arg1) throws IOException {
return checkStatus(arg0.toLowerCase(), null, "collapse", "collapse in", null);
}
});
handlebar.registerHelper("now", new Helper
© 2015 - 2024 Weber Informatics LLC | Privacy Policy