Report code samples (Java SDK)

Customize the Report settings

This example shows how to customize the UFT Developer run report settings.

@Override
protected ModifiableReportConfiguration getReportConfiguration() throws IOException {
 ModifiableReportConfiguration reportConfig = ReportConfigurationFactory.createDefaultReportConfiguration();	
 reportConfig.setTargetDirectory("c:\\Reports"); // The folder must exist under C:\
 reportConfig.setReportFolder("UFTDeveloperJUnitExample");
 reportConfig.setTitle("UFT Developer JUnit Example Run Results");
 reportConfig.setDescription("Configuration settings example");
 return reportConfig;
}		

Back to top

Report a failure to the Run Results

This example reports a test failure to the run results.

@Test
	public void test() throws Exception {
	CalculatorApp calc = new CalculatorApp();
	try {
		WindowDescription calculatorDescription = new WindowDescription.Builder().nativeClass("CalcFrame").build();

		Window calculator = Desktop.describe(Window.class, calculatorDescription);

		Button button4 = calculator.describe(Button.class, new ButtonDescription.Builder().windowId(134).nativeClass("Button").build());

		Button buttonSqrt = calculator.describe(Button.class, new ButtonDescription.Builder().windowId(110).nativeClass("Button").build());

		button4.click();
		buttonSqrt.click();

		Static textBox = calculator.describe(Static.class, new ScrollBarDescription.Builder().windowId(150).nativeClass("Static").build());
		String visibleText = textBox.getVisibleText();

		String expected = "2";
		Verify.areEqual(expected, visibleText, "Expected Result Verification", "Verify the text box contains the expected text.");
	} catch (Throwable e) {
		Reporter.reportEvent("UFTDeveloperJUnitExample", "Test Failed", Status.Failed, e);
		throw e;
	} finally {
		calc.dispose();
	}
}

Back to top

Access current report status during runtime

This example shows how to access the current report status during runtime, and write different scenarios of the test execution according to the obtained value.

Status reportStatus = Reporter.getStatus();
if (reportStatus == Status.Passed) {
	//continue test execution
} else {
	//make custom action
}

Back to top

See also: