Generating report in leanft in Java

Reports can be generated in 2 ways in LeanFT. Screenshots using Reporter and TestObject.GetSnapshot Video recordings of test execution using Microsoft expression encoder. By default, LeanFT creates the reports in RunResults folder in the root directory of Java project. But you can change that using ModifiableReportConfiguration class as shown in below example. You can also use below method to send your log messages to the report. Reporter.reportEvent
 
package leanft;

import com.hp.lft.report.*;
import com.hp.lft.sdk.Desktop;
import com.hp.lft.sdk.stdwin.Window;
import com.hp.lft.sdk.stdwin.WindowDescription;
import com.hp.lft.sdk.web.*;
import com.hp.lft.verifications.Verify;
import org.junit.Test;

import java.awt.image.RenderedImage;

public class ChromeReportTest extends BaseTest {

    @Test
    public void test() throws Exception{

        ModifiableReportConfiguration reportConfig = ReportConfigurationFactory.createDefaultReportConfiguration();
        reportConfig.setOverrideExisting(true);
        reportConfig.setTargetDirectory("RunResults"); // The folder must exist under C:        reportConfig.setReportFolder("myreportdirectory");
        reportConfig.setTitle("My Report Title");
        reportConfig.setDescription("Report Description");
        reportConfig.setSnapshotsLevel(CaptureLevel.OnError);

        Reporter.init(reportConfig);
        Browser browser = BrowserFactory.launch(BrowserType.CHROME);
        try{
            //Navigate to https://www.softpost.org/selenium-test-page/
            browser.navigate("https://www.softpost.org/selenium-test-page/");
            browser.sync();

            //set value in edit box
           EditField firstName = browser.describe(EditField.class,new EditFieldDescription.Builder()
            .id("fn").build());
            firstName.setValue("Sagar");

            //take screenshot
           RenderedImage img = browser.getPage().getSnapshot();

            if (firstName.getValue().equalsIgnoreCase("sagar"))
                Reporter.reportEvent("Verify Editbox","Value is sagar", Status.Passed,img);
            else
                Reporter.reportEvent("Verify Editbox","Value is not sagar", Status.Failed,img);

        }
        catch(AssertionError ex){
           //Report the Exception
           Reporter.reportEvent("Exception","Test failed", Status.Failed, ex);
           throw ex;
        }
        finally{
            //Close the browser
            browser.close();
        }
    }
}

Web development and Automation testing

solutions delivered!!