Report code samples

Customize the Report settings

This example shows how to customize the LeanFT 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("LeanFtJUnitExample");
 reportConfig.setTitle("LeanFT 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();
        			
 // Use try-catch to add a warning to the run report if the assert validation fails. 
 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";       
				
  // Enclosing the Assert method in a try-catch statement ensures the application does not throw a runtime error if the Assert returns false.          
		
  assertEquals("Text verification failed: ", expected, visibleText);		
 } catch (Throwable e) {			
  // Adds a step to the results report on failure.
  Reporter.reportEvent("LeanFtJUnitExample", "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: